meta = MetaData()
meta.bind = migrate_engine
- 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.
- 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'}
+ fk_name = None
+ if migrate_engine.name == 'mysql':
+ 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': 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:
new_id += 1
- volumes.c.volume_type_id.alter(Integer)
- volume_types.c.id.alter(Integer)
- extra_specs.c.volume_type_id.alter(Integer)
+ 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)
for column in fkey_remove_list:
fkeys = list(column.foreign_keys)
"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