]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Run NOT NULL alterations before foreign key adds
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 3 Dec 2015 19:21:13 +0000 (14:21 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 3 Dec 2015 19:24:42 +0000 (14:24 -0500)
The "migrate resources table" migration will fail
for some MariaDB versions if the NOT NULL alteration
is applied after the foreign key constraint has been
added [1].   This patch reverses the order so that
NOT NULL is applied first.

[1] http://paste.openstack.org/show/480820/

Change-Id: Iab2b9fc7d82c739ae458ee48c1830541fb0f9579

neutron/db/migration/alembic_migrations/versions/mitaka/contract/8a6d8bdae39_migrate_neutron_resources_table.py

index b2a424ce0754bb4d68af6b0002adb92cf8795d4b..e7acce8bac3cd2d189a5508d6abfdd03982fff36 100644 (file)
@@ -49,15 +49,18 @@ standardattrs = sa.Table(
 def upgrade():
     generate_records_for_existing()
     for table, model in TABLE_MODELS:
-        # add the constraint now that everything is populated on that table
+        # add constraint(s) now that everything is populated on that table.
+        # note that some MariaDB versions will *not* allow the ALTER to
+        # NOT NULL on a column that has an FK constraint, so we set NOT NULL
+        # first, then the FK constraint.
+        op.alter_column(table, 'standard_attr_id', nullable=False,
+                        existing_type=sa.BigInteger(), existing_nullable=True,
+                        existing_server_default=False)
         op.create_foreign_key(
             constraint_name=None, source_table=table,
             referent_table='standardattributes',
             local_cols=['standard_attr_id'], remote_cols=['id'],
             ondelete='CASCADE')
-        op.alter_column(table, 'standard_attr_id', nullable=False,
-                        existing_type=sa.BigInteger(), existing_nullable=True,
-                        existing_server_default=False)
         op.create_unique_constraint(
             constraint_name='uniq_%s0standard_attr_id' % table,
             table_name=table, columns=['standard_attr_id'])