From 5f3c2f9b8ea24b2a0e1909dbeac4dc47f2410d7a Mon Sep 17 00:00:00 2001 From: Rick Harris Date: Tue, 23 Oct 2012 21:55:59 +0000 Subject: More specific exception handling in migration 091. The original code would catch and discard any exception generated when trying to create or drop fkey constraints using the SQLite engine. This has the side-effect of allowing the DB to become inconsistent (by leaving a `migration_tmp` table around), causing future migrations to fail and making bugs even hard to track down. Long term, we should fix the underlying cause of these exceptions, either by switching to Alembic or by fixing SQLALchemy-Migrate to fully support dropping of constraints via a temp table. For now though, tightening up the exception handling will at least make any future bugs a bit easier to diagnose. Fixes bug 1070559 Change-Id: If549d65afa758b6f8a0db6fc8478a5b0c9277e23 --- .../versions/091_convert_volume_ids_to_uuid.py | 43 ++++++++-------------- 1 file changed, 15 insertions(+), 28 deletions(-) (limited to 'nova') diff --git a/nova/db/sqlalchemy/migrate_repo/versions/091_convert_volume_ids_to_uuid.py b/nova/db/sqlalchemy/migrate_repo/versions/091_convert_volume_ids_to_uuid.py index 3938107da..dadf15d30 100644 --- a/nova/db/sqlalchemy/migrate_repo/versions/091_convert_volume_ids_to_uuid.py +++ b/nova/db/sqlalchemy/migrate_repo/versions/091_convert_volume_ids_to_uuid.py @@ -14,8 +14,7 @@ # 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 ForeignKeyConstraint +from migrate import ForeignKeyConstraint, NotSupportedError from sqlalchemy import MetaData, select, Table from nova.openstack.common import log as logging @@ -54,11 +53,11 @@ def upgrade(migrate_engine): name=fkey_name) try: fkey.drop() - except Exception: - if migrate_engine.url.get_dialect().name.startswith('sqlite'): - pass - else: - raise + except NotSupportedError: + # NOTE(sirp): sqlite doesn't support ALTER TABLE DROP + # CONSTRAINT and sqlalchemy-migrate doesn't yet have a + # work-around using temp tables. + pass volume_list = list(volumes.select().execute()) for v in volume_list: @@ -111,14 +110,8 @@ def upgrade(migrate_engine): if fkeys: fkey = ForeignKeyConstraint(columns=[column], refcolumns=[volumes.c.id]) - try: - fkey.create() - LOG.info('Created foreign key %s' % fkey_name) - except Exception: - if migrate_engine.url.get_dialect().name.startswith('sqlite'): - pass - else: - raise + fkey.create() + LOG.info('Created foreign key %s' % fkey_name) def downgrade(migrate_engine): @@ -151,11 +144,11 @@ def downgrade(migrate_engine): name=fkey_name) try: fkey.drop() - except Exception: - if migrate_engine.url.get_dialect().name.startswith('sqlite'): - pass - else: - raise + except NotSupportedError: + # NOTE(sirp): sqlite doesn't support ALTER TABLE DROP + # CONSTRAINT and sqlalchemy-migrate doesn't yet have a + # work-around using temp tables. + pass volume_list = list(volumes.select().execute()) for v in volume_list: @@ -208,11 +201,5 @@ def downgrade(migrate_engine): if fkeys: fkey = ForeignKeyConstraint(columns=[column], refcolumns=[volumes.c.id]) - try: - fkey.create() - LOG.info('Created foreign key %s' % fkey_name) - except Exception: - if migrate_engine.url.get_dialect().name.startswith('sqlite'): - pass - else: - raise + fkey.create() + LOG.info('Created foreign key %s' % fkey_name) -- cgit