From a80e0190c6025cfb3accc986a7d98fdb4a8eeb29 Mon Sep 17 00:00:00 2001 From: Tan Jiang Date: Wed, 22 Jun 2016 12:22:02 +0800 Subject: [PATCH] data migration script to 0.2.0 --- Deploy/db/registry.sql | 6 +-- migration/changelog.md | 8 +++ migration/db_meta.py | 39 +++++++++++++++ migration/migration_harbor/versions/0_2_0.py | 52 ++++++++++++++++++++ 4 files changed, 102 insertions(+), 3 deletions(-) create mode 100644 migration/migration_harbor/versions/0_2_0.py diff --git a/Deploy/db/registry.sql b/Deploy/db/registry.sql index 2d32b4cbb..66bb219e6 100644 --- a/Deploy/db/registry.sql +++ b/Deploy/db/registry.sql @@ -93,8 +93,8 @@ create table access_log ( log_id int NOT NULL AUTO_INCREMENT, user_id int NOT NULL, project_id int NOT NULL, - repo_name varchar (40), - repo_tag varchar (20), + repo_name varchar (256), + repo_tag varchar (128), GUID varchar(64), operation varchar(20) NOT NULL, op_time timestamp, @@ -159,4 +159,4 @@ CREATE TABLE IF NOT EXISTS `alembic_version` ( `version_num` varchar(32) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -insert into alembic_version values ('0.1.1'); +insert into alembic_version values ('0.2.0'); diff --git a/migration/changelog.md b/migration/changelog.md index ab14c17d5..888aeb5a6 100644 --- a/migration/changelog.md +++ b/migration/changelog.md @@ -17,3 +17,11 @@ Changelog for harbor database schema - delete data `AMDRWS` from table `role` - delete data `A` from table `access` +## 0.2.0 + + - create table `replication_policy` + - create table `replication_target` + - create table `replication_job` + - add column `repo_tag` to table `access_log` + - alter column `repo_name` on table `access_log` + - alter column `email` on table `user` diff --git a/migration/db_meta.py b/migration/db_meta.py index dcbdd4311..fecb2aed3 100644 --- a/migration/db_meta.py +++ b/migration/db_meta.py @@ -85,3 +85,42 @@ class Project(Base): deleted = sa.Column(sa.Integer, nullable=False, server_default=sa.text("'0'")) public = sa.Column(sa.Integer, nullable=False, server_default=sa.text("'0'")) owner = relationship(u'User') + +class ReplicationPolicy(Base): + __tablename__ = "replication_policy" + + id = sa.Column(sa.Integer, primary_key=True) + name = sa.Column(sa.String(256)) + project_id = sa.Column(sa.Integer, nullable=False) + target_id = sa.Column(sa.Integer, nullable=False) + enabled = sa.Column(mysql.TINYINT(1), nullable=False, server_default=sa.text("'1'")) + description = sa.Column(sa.Text) + cron_str = sa.Column(sa.String(256)) + start_time = sa.Column(mysql.TIMESTAMP) + creation_time = sa.Column(mysql.TIMESTAMP, server_default = sa.text("CURRENT_TIMESTAMP")) + update_time = sa.Column(mysql.TIMESTAMP, server_default = sa.text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP")) + +class ReplicationTarget(Base): + __tablename__ = "replication_target" + + id = sa.Column(sa.Integer, primary_key=True) + name = sa.Column(sa.String(64)) + url = sa.Column(sa.String(64)) + username = sa.Column(sa.String(40)) + password = sa.Column(sa.String(40)) + target_type = sa.Column(mysql.TINYINT(1), nullable=False, server_default=sa.text("'0'")) + creation_time = sa.Column(mysql.TIMESTAMP, server_default = sa.text("CURRENT_TIMESTAMP")) + update_time = sa.Column(mysql.TIMESTAMP, server_default = sa.text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP")) + +class ReplicationJob(Base): + __tablename__ = "replication_job" + + id = sa.Column(sa.Integer, primary_key=True) + status = sa.Column(sa.String(64), nullable=False) + policy_id = sa.Column(sa.Integer, nullable=False) + repository = sa.Column(sa.String(256), nullable=False) + operation = sa.Column(sa.String(64), nullable=False) + tags = sa.Column(sa.String(16384)) + creation_time = sa.Column(mysql.TIMESTAMP, server_default = sa.text("CURRENT_TIMESTAMP")) + update_time = sa.Column(mysql.TIMESTAMP, server_default = sa.text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP")) + diff --git a/migration/migration_harbor/versions/0_2_0.py b/migration/migration_harbor/versions/0_2_0.py new file mode 100644 index 000000000..79ff28be9 --- /dev/null +++ b/migration/migration_harbor/versions/0_2_0.py @@ -0,0 +1,52 @@ +# Copyright (c) 2008-2016 VMware, Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""0.1.1 to 0.2.0 + +Revision ID: 0.1.1 +Revises: + +""" + +# revision identifiers, used by Alembic. +revision = '0.2.0' +down_revision = '0.1.1' +branch_labels = None +depends_on = None + +from alembic import op +from db_meta import * + +from sqlalchemy.dialects import mysql + +def upgrade(): + """ + update schema&data + """ + bind = op.get_bind() + #alter column user.email, alter column access_log.repo_name, and add column access_log.repo_tag + op.alter_column('user', 'email', type_=sa.String(128), existing_type=sa.String(30)) + op.alter_column('access_log', 'repo_name', type_=sa.String(256), existing_type=sa.String(40)) + op.add_column('access_log', sa.Column('repo_tag', sa.String(128))) + + #create tables: replication_policy, replication_target, replication_job + ReplicationPolicy.__table__.create(bind) + ReplicationTarget.__table__.create(bind) + ReplicationJob.__table__.create(bind) + +def downgrade(): + """ + Downgrade has been disabled. + """ + pass