diff options
| author | Rick Harris <rconradharris@gmail.com> | 2012-10-23 21:55:59 +0000 |
|---|---|---|
| committer | Rick Harris <rconradharris@gmail.com> | 2012-10-23 22:07:04 +0000 |
| commit | 5f3c2f9b8ea24b2a0e1909dbeac4dc47f2410d7a (patch) | |
| tree | c7f262405d63e7a5acd4bd8ed8ab32a132e42b45 | |
| parent | 1ff47d61ee39614ab2182e9e52d71d203eb250f2 (diff) | |
| download | nova-5f3c2f9b8ea24b2a0e1909dbeac4dc47f2410d7a.tar.gz nova-5f3c2f9b8ea24b2a0e1909dbeac4dc47f2410d7a.tar.xz nova-5f3c2f9b8ea24b2a0e1909dbeac4dc47f2410d7a.zip | |
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
| -rw-r--r-- | nova/db/sqlalchemy/migrate_repo/versions/091_convert_volume_ids_to_uuid.py | 43 |
1 files changed, 15 insertions, 28 deletions
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) |
