Merge "apidb: Compact Liberty database migrations"
This commit is contained in:
commit
456f50787c
|
@ -1,42 +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.
|
||||
|
||||
from migrate import UniqueConstraint
|
||||
from sqlalchemy import Column
|
||||
from sqlalchemy import DateTime
|
||||
from sqlalchemy import Index
|
||||
from sqlalchemy import Integer
|
||||
from sqlalchemy import MetaData
|
||||
from sqlalchemy import String
|
||||
from sqlalchemy import Table
|
||||
from sqlalchemy import Text
|
||||
|
||||
|
||||
def upgrade(migrate_engine):
|
||||
meta = MetaData()
|
||||
meta.bind = migrate_engine
|
||||
|
||||
cell_mappings = Table('cell_mappings', meta,
|
||||
Column('created_at', DateTime),
|
||||
Column('updated_at', DateTime),
|
||||
Column('id', Integer, primary_key=True, nullable=False),
|
||||
Column('uuid', String(length=36), nullable=False),
|
||||
Column('name', String(length=255)),
|
||||
Column('transport_url', Text()),
|
||||
Column('database_connection', Text()),
|
||||
UniqueConstraint('uuid', name='uniq_cell_mappings0uuid'),
|
||||
Index('uuid_idx', 'uuid'),
|
||||
mysql_engine='InnoDB',
|
||||
mysql_charset='utf8'
|
||||
)
|
||||
|
||||
cell_mappings.create(checkfirst=True)
|
|
@ -1,44 +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.
|
||||
|
||||
from migrate.changeset.constraint import ForeignKeyConstraint
|
||||
from migrate import UniqueConstraint
|
||||
from sqlalchemy import Column
|
||||
from sqlalchemy import DateTime
|
||||
from sqlalchemy import Index
|
||||
from sqlalchemy import Integer
|
||||
from sqlalchemy import MetaData
|
||||
from sqlalchemy import String
|
||||
from sqlalchemy import Table
|
||||
|
||||
|
||||
def upgrade(migrate_engine):
|
||||
meta = MetaData()
|
||||
meta.bind = migrate_engine
|
||||
|
||||
cell_mappings = Table('cell_mappings', meta, autoload=True)
|
||||
host_mappings = Table('host_mappings', meta,
|
||||
Column('created_at', DateTime),
|
||||
Column('updated_at', DateTime),
|
||||
Column('id', Integer, primary_key=True, nullable=False),
|
||||
Column('cell_id', Integer, nullable=False),
|
||||
Column('host', String(length=255), nullable=False),
|
||||
UniqueConstraint('host',
|
||||
name='uniq_host_mappings0host'),
|
||||
Index('host_idx', 'host'),
|
||||
ForeignKeyConstraint(columns=['cell_id'],
|
||||
refcolumns=[cell_mappings.c.id]),
|
||||
mysql_engine='InnoDB',
|
||||
mysql_charset='utf8'
|
||||
)
|
||||
|
||||
host_mappings.create(checkfirst=True)
|
|
@ -19,13 +19,42 @@ from sqlalchemy import Integer
|
|||
from sqlalchemy import MetaData
|
||||
from sqlalchemy import String
|
||||
from sqlalchemy import Table
|
||||
from sqlalchemy import Text
|
||||
|
||||
|
||||
def upgrade(migrate_engine):
|
||||
meta = MetaData()
|
||||
meta.bind = migrate_engine
|
||||
|
||||
cell_mappings = Table('cell_mappings', meta, autoload=True)
|
||||
cell_mappings = Table('cell_mappings', meta,
|
||||
Column('created_at', DateTime),
|
||||
Column('updated_at', DateTime),
|
||||
Column('id', Integer, primary_key=True, nullable=False),
|
||||
Column('uuid', String(length=36), nullable=False),
|
||||
Column('name', String(length=255)),
|
||||
Column('transport_url', Text()),
|
||||
Column('database_connection', Text()),
|
||||
UniqueConstraint('uuid', name='uniq_cell_mappings0uuid'),
|
||||
Index('uuid_idx', 'uuid'),
|
||||
mysql_engine='InnoDB',
|
||||
mysql_charset='utf8'
|
||||
)
|
||||
|
||||
host_mappings = Table('host_mappings', meta,
|
||||
Column('created_at', DateTime),
|
||||
Column('updated_at', DateTime),
|
||||
Column('id', Integer, primary_key=True, nullable=False),
|
||||
Column('cell_id', Integer, nullable=False),
|
||||
Column('host', String(length=255), nullable=False),
|
||||
UniqueConstraint(
|
||||
'host', name='uniq_host_mappings0host'),
|
||||
Index('host_idx', 'host'),
|
||||
ForeignKeyConstraint(
|
||||
columns=['cell_id'], refcolumns=[cell_mappings.c.id]),
|
||||
mysql_engine='InnoDB',
|
||||
mysql_charset='utf8'
|
||||
)
|
||||
|
||||
instance_mappings = Table('instance_mappings', meta,
|
||||
Column('created_at', DateTime),
|
||||
Column('updated_at', DateTime),
|
||||
|
@ -33,14 +62,20 @@ def upgrade(migrate_engine):
|
|||
Column('instance_uuid', String(length=36), nullable=False),
|
||||
Column('cell_id', Integer, nullable=False),
|
||||
Column('project_id', String(length=255), nullable=False),
|
||||
UniqueConstraint('instance_uuid',
|
||||
name='uniq_instance_mappings0instance_uuid'),
|
||||
UniqueConstraint(
|
||||
'instance_uuid', name='uniq_instance_mappings0instance_uuid'),
|
||||
Index('instance_uuid_idx', 'instance_uuid'),
|
||||
Index('project_id_idx', 'project_id'),
|
||||
ForeignKeyConstraint(columns=['cell_id'],
|
||||
refcolumns=[cell_mappings.c.id]),
|
||||
ForeignKeyConstraint(
|
||||
columns=['cell_id'], refcolumns=[cell_mappings.c.id]),
|
||||
mysql_engine='InnoDB',
|
||||
mysql_charset='utf8'
|
||||
)
|
||||
|
||||
instance_mappings.create(checkfirst=True)
|
||||
tables = [
|
||||
cell_mappings,
|
||||
host_mappings,
|
||||
instance_mappings,
|
||||
]
|
||||
for table in tables:
|
||||
table.create(checkfirst=True)
|
|
@ -29,7 +29,7 @@ from nova.i18n import _
|
|||
|
||||
INIT_VERSION = {}
|
||||
INIT_VERSION['main'] = 401
|
||||
INIT_VERSION['api'] = 0
|
||||
INIT_VERSION['api'] = 2
|
||||
_REPOSITORY = {}
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
|
|
@ -183,6 +183,7 @@ class NovaAPIMigrationsWalk(test_migrations.WalkVersionsMixin):
|
|||
ussuri_placeholders = list(range(73, 78))
|
||||
victoria_placeholders = list(range(78, 83))
|
||||
special_cases = [
|
||||
self.INIT_VERSION + 1, # initial change
|
||||
30, # Enforcement migration, no changes to test
|
||||
]
|
||||
return (mitaka_placeholders +
|
||||
|
@ -227,49 +228,6 @@ class NovaAPIMigrationsWalk(test_migrations.WalkVersionsMixin):
|
|||
self.assertRaises(sqlalchemy.exc.NoSuchTableError,
|
||||
db_utils.get_table, engine, table_name)
|
||||
|
||||
def _check_001(self, engine, data):
|
||||
for column in ['created_at', 'updated_at', 'id', 'uuid', 'name',
|
||||
'transport_url', 'database_connection']:
|
||||
self.assertColumnExists(engine, 'cell_mappings', column)
|
||||
|
||||
self.assertIndexExists(engine, 'cell_mappings', 'uuid_idx')
|
||||
self.assertUniqueConstraintExists(engine, 'cell_mappings',
|
||||
['uuid'])
|
||||
|
||||
def _check_002(self, engine, data):
|
||||
for column in ['created_at', 'updated_at', 'id', 'instance_uuid',
|
||||
'cell_id', 'project_id']:
|
||||
self.assertColumnExists(engine, 'instance_mappings', column)
|
||||
|
||||
for index in ['instance_uuid_idx', 'project_id_idx']:
|
||||
self.assertIndexExists(engine, 'instance_mappings', index)
|
||||
|
||||
self.assertUniqueConstraintExists(engine, 'instance_mappings',
|
||||
['instance_uuid'])
|
||||
|
||||
inspector = reflection.Inspector.from_engine(engine)
|
||||
# There should only be one foreign key here
|
||||
fk = inspector.get_foreign_keys('instance_mappings')[0]
|
||||
self.assertEqual('cell_mappings', fk['referred_table'])
|
||||
self.assertEqual(['id'], fk['referred_columns'])
|
||||
self.assertEqual(['cell_id'], fk['constrained_columns'])
|
||||
|
||||
def _check_003(self, engine, data):
|
||||
for column in ['created_at', 'updated_at', 'id',
|
||||
'cell_id', 'host']:
|
||||
self.assertColumnExists(engine, 'host_mappings', column)
|
||||
|
||||
self.assertIndexExists(engine, 'host_mappings', 'host_idx')
|
||||
self.assertUniqueConstraintExists(engine, 'host_mappings',
|
||||
['host'])
|
||||
|
||||
inspector = reflection.Inspector.from_engine(engine)
|
||||
# There should only be one foreign key here
|
||||
fk = inspector.get_foreign_keys('host_mappings')[0]
|
||||
self.assertEqual('cell_mappings', fk['referred_table'])
|
||||
self.assertEqual(['id'], fk['referred_columns'])
|
||||
self.assertEqual(['cell_id'], fk['constrained_columns'])
|
||||
|
||||
def _check_004(self, engine, data):
|
||||
columns = ['created_at', 'updated_at', 'id', 'instance_uuid', 'spec']
|
||||
for column in columns:
|
||||
|
|
|
@ -83,9 +83,8 @@ class TestDbVersion(test.NoDBTestCase):
|
|||
metadata), mock.patch.object(migration,
|
||||
'db_version_control') as mock_version_control:
|
||||
migration.db_version(database)
|
||||
mock_version_control.assert_called_once_with(0,
|
||||
database,
|
||||
context=None)
|
||||
mock_version_control.assert_called_once_with(
|
||||
migration.INIT_VERSION['api'], database, context=None)
|
||||
db_version_calls = [mock.call('engine', 'repo')] * 2
|
||||
self.assertEqual(db_version_calls, mock_db_version.call_args_list)
|
||||
engine_calls = [mock.call(database, context=None)] * 3
|
||||
|
@ -109,9 +108,8 @@ class TestDbVersion(test.NoDBTestCase):
|
|||
# racing to initialise with another process.
|
||||
mock_version_control.side_effect = test.TestingException
|
||||
migration.db_version(database)
|
||||
mock_version_control.assert_called_once_with(0,
|
||||
database,
|
||||
context=None)
|
||||
mock_version_control.assert_called_once_with(
|
||||
migration.INIT_VERSION['api'], database, context=None)
|
||||
db_version_calls = [mock.call('engine', 'repo')] * 2
|
||||
self.assertEqual(db_version_calls, mock_db_version.call_args_list)
|
||||
engine_calls = [mock.call(database, context=None)] * 3
|
||||
|
|
Loading…
Reference in New Issue