Merge "Add migration tests for PostgreSQL"
This commit is contained in:
commit
bc8d0d2fcb
|
@ -111,21 +111,29 @@ def downgrade(migrate_engine):
|
|||
meta = MetaData()
|
||||
meta.bind = migrate_engine
|
||||
|
||||
fk_name = None
|
||||
|
||||
if migrate_engine.name == 'mysql':
|
||||
# NOTE(jsbryant): MySQL Cannot drop the quota_usages table
|
||||
# until the foreign key reservations_ibfk_1 is removed. We
|
||||
# remove the foreign key first, and then we drop the table.
|
||||
fk_name = 'reservations_ibfk_1'
|
||||
elif migrate_engine.name == 'postgresql':
|
||||
fk_name = 'reservations_usage_id_fkey'
|
||||
|
||||
# NOTE: MySQL and PostgreSQL Cannot drop the quota_usages table
|
||||
# until the foreign key is removed. We remove the foreign key first,
|
||||
# and then we drop the table.
|
||||
table = Table('reservations', meta, autoload=True)
|
||||
ref_table = Table('reservations', meta, autoload=True)
|
||||
params = {'columns': [table.c['usage_id']],
|
||||
'refcolumns': [ref_table.c['id']],
|
||||
'name': 'reservations_ibfk_1'}
|
||||
'name': fk_name}
|
||||
|
||||
if fk_name:
|
||||
try:
|
||||
fkey = ForeignKeyConstraint(**params)
|
||||
fkey.drop()
|
||||
except Exception:
|
||||
LOG.error(_LE("Dropping foreign key reservations_ibfk_1 failed."))
|
||||
msg = _LE("Dropping foreign key %s failed.")
|
||||
LOG.error(msg, fk_name)
|
||||
|
||||
quota_classes = Table('quota_classes', meta, autoload=True)
|
||||
try:
|
||||
|
|
|
@ -133,6 +133,17 @@ def downgrade(migrate_engine):
|
|||
|
||||
new_id += 1
|
||||
|
||||
if migrate_engine.name == 'postgresql':
|
||||
# NOTE(e0ne): PostgreSQL can't cast string to int automatically
|
||||
table_column_pairs = [('volumes', 'volume_type_id'),
|
||||
('volume_types', 'id'),
|
||||
('volume_type_extra_specs', 'volume_type_id')]
|
||||
sql = 'ALTER TABLE {0} ALTER COLUMN {1} ' + \
|
||||
'TYPE INTEGER USING {1}::numeric'
|
||||
|
||||
for table, column in table_column_pairs:
|
||||
migrate_engine.execute(sql.format(table, column))
|
||||
else:
|
||||
volumes.c.volume_type_id.alter(Integer)
|
||||
volume_types.c.id.alter(Integer)
|
||||
extra_specs.c.volume_type_id.alter(Integer)
|
||||
|
|
|
@ -759,3 +759,8 @@ class TestMysqlMigrations(test_base.MySQLOpportunisticTestCase,
|
|||
"and TABLE_NAME!='migrate_version'")
|
||||
count = noninnodb.scalar()
|
||||
self.assertEqual(count, 0, "%d non InnoDB tables created" % count)
|
||||
|
||||
|
||||
class TestPostgresqlMigrations(test_base.PostgreSQLOpportunisticTestCase,
|
||||
MigrationsMixin):
|
||||
TIME_TYPE = sqlalchemy.types.TIMESTAMP
|
||||
|
|
Loading…
Reference in New Issue