From d5d480d1e68bb343dc8cd39510a10ed3aeefb8d1 Mon Sep 17 00:00:00 2001 From: Zhenguo Niu Date: Sat, 28 Oct 2017 15:34:12 +0800 Subject: [PATCH] Following up patch of bbbe964ff4e19232ce3dd326fbd3f04f0781f5b1 This merges db migrations file into one, will not add new migration scrips until we are offical. Change-Id: Ibd70c05e42a6b8ad63f3818e385bc347b9ff8afa --- .../91941bf1ebc9_initial_migration.py | 14 +++++- .../versions/cf73c09d3ff2_add_server_tags.py | 43 ------------------- .../unit/db/sqlalchemy/test_migrations.py | 15 ------- 3 files changed, 13 insertions(+), 59 deletions(-) delete mode 100644 mogan/db/sqlalchemy/alembic/versions/cf73c09d3ff2_add_server_tags.py diff --git a/mogan/db/sqlalchemy/alembic/versions/91941bf1ebc9_initial_migration.py b/mogan/db/sqlalchemy/alembic/versions/91941bf1ebc9_initial_migration.py index 62aef56a..bb0d46df 100644 --- a/mogan/db/sqlalchemy/alembic/versions/91941bf1ebc9_initial_migration.py +++ b/mogan/db/sqlalchemy/alembic/versions/91941bf1ebc9_initial_migration.py @@ -250,7 +250,6 @@ def upgrade(): mysql_engine='InnoDB', mysql_charset='utf8' ) - op.create_table( 'server_group_member', sa.Column('created_at', sa.DateTime(), nullable=True), @@ -263,3 +262,16 @@ def upgrade(): mysql_engine='InnoDB', mysql_charset='utf8' ) + op.create_table( + 'server_tags', + sa.Column('created_at', sa.DateTime(), nullable=True), + sa.Column('updated_at', sa.DateTime(), nullable=True), + sa.Column('server_id', sa.Integer(), nullable=False), + sa.Column('tag', sa.String(length=255), nullable=False), + sa.PrimaryKeyConstraint('server_id', 'tag'), + sa.ForeignKeyConstraint(['server_id'], + ['servers.id']), + sa.Index('server_tags_tag_idx', 'tag'), + mysql_ENGINE='InnoDB', + mysql_DEFAULT_CHARSET='UTF8' + ) diff --git a/mogan/db/sqlalchemy/alembic/versions/cf73c09d3ff2_add_server_tags.py b/mogan/db/sqlalchemy/alembic/versions/cf73c09d3ff2_add_server_tags.py deleted file mode 100644 index c1cdce5a..00000000 --- a/mogan/db/sqlalchemy/alembic/versions/cf73c09d3ff2_add_server_tags.py +++ /dev/null @@ -1,43 +0,0 @@ -# -# 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. - -"""add server tags - -Revision ID: cf73c09d3ff2 -Revises: 0de89f877016 -Create Date: 2017-09-21 04:11:09.636891 - -""" - -from alembic import op -import sqlalchemy as sa - -# revision identifiers, used by Alembic. -revision = 'cf73c09d3ff2' -down_revision = '91941bf1ebc9' - - -def upgrade(): - op.create_table( - 'server_tags', - sa.Column('created_at', sa.DateTime(), nullable=True), - sa.Column('updated_at', sa.DateTime(), nullable=True), - sa.Column('server_id', sa.Integer(), nullable=False), - sa.Column('tag', sa.String(length=255), nullable=False), - sa.PrimaryKeyConstraint('server_id', 'tag'), - sa.ForeignKeyConstraint(['server_id'], - ['servers.id']), - sa.Index('server_tags_tag_idx', 'tag'), - mysql_ENGINE='InnoDB', - mysql_DEFAULT_CHARSET='UTF8' - ) diff --git a/mogan/tests/unit/db/sqlalchemy/test_migrations.py b/mogan/tests/unit/db/sqlalchemy/test_migrations.py index eecf4204..80f2af33 100644 --- a/mogan/tests/unit/db/sqlalchemy/test_migrations.py +++ b/mogan/tests/unit/db/sqlalchemy/test_migrations.py @@ -245,21 +245,6 @@ class MigrationCheckersMixin(object): self.assertIsInstance(nodes.c.resource_name.type, sqlalchemy.types.String) - def _check_cf73c09d3ff2(self, engine, data): - server_tags = db_utils.get_table(engine, 'server_tags') - col_names = [column.name for column in server_tags.c] - self.assertIn('tag', col_names) - self.assertIsInstance(server_tags.c.tag.type, - sqlalchemy.types.String) - servers = db_utils.get_table(engine, 'servers') - data = {'id': '123', 'name': 'server1'} - servers.insert().execute(data) - data = {'server_id': '123', 'tag': 'tag1'} - server_tags.insert().execute(data) - tag = server_tags.select(server_tags.c.server_id == '123').execute().\ - first() - self.assertEqual('tag1', tag['tag']) - def test_upgrade_and_version(self): with patch_with_engine(self.engine): self.migration_api.upgrade('head')