mirror of
https://github.com/goharbor/harbor.git
synced 2024-10-31 15:50:00 +01:00
db migration script for 0.4.0
This commit is contained in:
parent
e5c464f205
commit
2bda70f73f
@ -123,8 +123,6 @@ create table repository (
|
||||
creation_time timestamp default CURRENT_TIMESTAMP,
|
||||
update_time timestamp default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
|
||||
primary key (repository_id),
|
||||
FOREIGN KEY (owner_id) REFERENCES user(user_id),
|
||||
FOREIGN KEY (project_id) REFERENCES project(project_id),
|
||||
UNIQUE (name)
|
||||
);
|
||||
|
||||
@ -184,4 +182,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.3.0');
|
||||
insert into alembic_version values ('0.4.0');
|
||||
|
@ -26,12 +26,13 @@ Changelog for harbor database schema
|
||||
- alter column `repo_name` on table `access_log`
|
||||
- alter column `email` on table `user`
|
||||
|
||||
## TODO
|
||||
## 0.4.0
|
||||
|
||||
- add index `pid_optime (project_id, op_time)` on table `access_log`
|
||||
- add index `poid_uptime (policy_id, update_time)` on table `replication_job`
|
||||
- add column `deleted` to table `replication_policy`
|
||||
- alter column `username` on table `user`: varchar(15)->varchar(32)
|
||||
- alter column `password` on table `replication_target`: varchar(40)->varchar(128)
|
||||
- alter column `email` on table `user`: varchar(128)->varchar(255)
|
||||
- alter column `name` on table `project`: varchar(30)->varchar(41)
|
||||
- create table `repository`
|
||||
|
@ -125,3 +125,18 @@ class ReplicationJob(Base):
|
||||
update_time = sa.Column(mysql.TIMESTAMP, server_default = sa.text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"))
|
||||
|
||||
__table_args__ = (sa.Index('policy', "policy_id"),)
|
||||
|
||||
class Repository(Base):
|
||||
__tablename__ = "repository"
|
||||
|
||||
repository_id = sa.Column(sa.Integer, primary_key=True)
|
||||
name = sa.Column(sa.String(255), nullable=False, unique=True)
|
||||
project_id = sa.Column(sa.Integer, nullable=False)
|
||||
owner_id = sa.Column(sa.Integer, nullable=False)
|
||||
description = sa.Column(sa.Text)
|
||||
pull_count = sa.Column(sa.Integer,server_default=sa.text("'0'"), nullable=False)
|
||||
star_count = sa.Column(sa.Integer,server_default=sa.text("'0'"), nullable=False)
|
||||
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"))
|
||||
|
||||
|
||||
|
54
migration/migration_harbor/versions/0_4_0.py
Normal file
54
migration/migration_harbor/versions/0_4_0.py
Normal file
@ -0,0 +1,54 @@
|
||||
# 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.3.0 to 0.4.0
|
||||
|
||||
Revision ID: 0.3.0
|
||||
Revises:
|
||||
|
||||
"""
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '0.4.0'
|
||||
down_revision = '0.3.0'
|
||||
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.username, alter column user.email, project.name and add column replication_policy.deleted
|
||||
op.alter_column('user', 'username', type_=sa.String(32), existing_type=sa.String(15))
|
||||
op.alter_column('user', 'email', type_=sa.String(255), existing_type=sa.String(128))
|
||||
op.alter_column('project', 'name', type_=sa.String(41), existing_type=sa.String(30), nullable=False)
|
||||
op.alter_column('replication_target', 'password', type_=sa.String(128), existing_type=sa.String(40))
|
||||
op.add_column('replication_policy', sa.Column('deleted', mysql.TINYINT(1), nullable=False, server_default=sa.text("'0'")))
|
||||
#create index pid_optime (project_id, op_time) on table access_log, poid_uptime (policy_id, update_time) on table replication_job
|
||||
op.create_index('pid_optime', 'access_log', ['project_id', 'op_time'])
|
||||
op.create_index('poid_uptime', 'replication_job', ['policy_id', 'update_time'])
|
||||
#create tables: repository
|
||||
Repository.__table__.create(bind)
|
||||
|
||||
def downgrade():
|
||||
"""
|
||||
Downgrade has been disabled.
|
||||
"""
|
||||
pass
|
Loading…
Reference in New Issue
Block a user