Merge lp:~dan-prince/nova/db_migrate_014_sqlite_fix into lp:~hudson-openstack/nova/trunk

Proposed by Dan Prince
Status: Merged
Approved by: Devin Carlen
Approved revision: 1006
Merged at revision: 1020
Proposed branch: lp:~dan-prince/nova/db_migrate_014_sqlite_fix
Merge into: lp:~hudson-openstack/nova/trunk
Diff against target: 18 lines (+4/-2)
1 file modified
nova/db/sqlalchemy/migrate_repo/versions/014_add_instance_type_id_to_instances.py (+4/-2)
To merge this branch: bzr merge lp:~dan-prince/nova/db_migrate_014_sqlite_fix
Reviewer Review Type Date Requested Status
Devin Carlen (community) Approve
termie (community) Approve
Review via email: mp+58402@code.launchpad.net

Commit message

Create a dictionary of instance_types before executing SQL updates in the instance_type_id migration (014). This should resolve a "cannot commit transaction - SQL statements in progress" error with some versions of sqlite.

Description of the change

Create a dictionary of instance_types before executing SQL updates in the instance_type_id migration (014). This should resolve a "cannot commit transaction - SQL statements in progress" error with some versions of sqlite. In this case an older version of Sqlite on SLES11 SP1.

While it is normally a bad idea to change database migrations after the fact this is a special case since it is just an implementation change. The functional database changes accomplished by this migration are the same.

To post a comment you must log in.
Revision history for this message
termie (termie) wrote :

lgtm

review: Approve
Revision history for this message
Devin Carlen (devcamcar) wrote :

lgtm

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'nova/db/sqlalchemy/migrate_repo/versions/014_add_instance_type_id_to_instances.py'
2--- nova/db/sqlalchemy/migrate_repo/versions/014_add_instance_type_id_to_instances.py 2011-04-05 17:02:42 +0000
3+++ nova/db/sqlalchemy/migrate_repo/versions/014_add_instance_type_id_to_instances.py 2011-04-19 21:48:39 +0000
4@@ -54,10 +54,12 @@
5
6 instances.create_column(c_instance_type_id)
7
8+ type_names = {}
9 recs = migrate_engine.execute(instance_types.select())
10 for row in recs:
11- type_id = row[0]
12- type_name = row[1]
13+ type_names[row[0]] = row[1]
14+
15+ for type_id, type_name in type_names.iteritems():
16 migrate_engine.execute(instances.update()\
17 .where(instances.c.instance_type == type_name)\
18 .values(instance_type_id=type_id))