Update migration 076 so it supports PostgreSQL.

Fixes LP Bug #32154.

Change-Id: I9d6ddfedcc39308811ff5264879b45b4847ec4a8
This commit is contained in:
Dan Prince 2012-02-14 09:58:26 -05:00
parent 028c62f378
commit 9b132000bf
3 changed files with 32 additions and 15 deletions

View File

@ -19,6 +19,7 @@
<dan@nicira.com> <danwent@dan-xs3-cs>
<dan@nicira.com> <danwent@gmail.com>
<devin.carlen@gmail.com> <devcamcar@illian.local>
<dprince@redhat.com> <dan.prince@rackspace.com>
<edouard1.thuleau@orange.com> <thuleau@gmail.com>
<ewan.mellor@citrix.com> <emellor@silver>
<ghe@debian.org> <ghe.rivero@gmail.com>

View File

@ -33,7 +33,7 @@ Chuck Short <zulcss@ubuntu.com>
Cole Robinson <crobinso@redhat.com>
Cor Cornelisse <cor@hyves.nl>
Cory Wright <corywright@gmail.com>
Dan Prince <dan.prince@rackspace.com>
Dan Prince <dprince@redhat.com>
Dan Wendlandt <dan@nicira.com>
Daniel P. Berrange <berrange@redhat.com>
Dave Lapsley <dlapsley@nicira.com>

View File

@ -21,46 +21,62 @@ from migrate.changeset.constraint import UniqueConstraint
meta = MetaData()
def upgrade(migrate_engine):
meta.bind = migrate_engine
table = Table('instance_types', meta, autoload=True)
def _get_constraint_names(engine_name):
# NOTE(vish): These constraint names may be dependent on the backend, but
# there doesn't seem to be we a way to determine the proper
# name for existing constraints. These names are correct for
# mysql.
# mysql and postgres.
if engine_name == "mysql":
return {
"instance_types_name": "name",
"instance_types_flavorid": "instance_types_flavorid_str_key",
"volume_types_name": "name",
}
else:
return {
"instance_types_name": "instance_types_name_key",
"instance_types_flavorid": "instance_types_flavorid_str_key",
"volume_types_name": "volume_types_name_key",
}
def upgrade(migrate_engine):
meta.bind = migrate_engine
c_names = _get_constraint_names(migrate_engine.name)
table = Table('instance_types', meta, autoload=True)
cons = UniqueConstraint('name',
name='name',
name=c_names['instance_types_name'],
table=table)
cons.drop()
cons = UniqueConstraint('flavorid',
name='instance_types_flavorid_str_key',
name=c_names['instance_types_flavorid'],
table=table)
cons.drop()
table = Table('volume_types', meta, autoload=True)
cons = UniqueConstraint('name',
name='name',
name=c_names['volume_types_name'],
table=table)
cons.drop()
def downgrade(migrate_engine):
meta.bind = migrate_engine
c_names = _get_constraint_names(migrate_engine.name)
table = Table('instance_types', meta, autoload=True)
# NOTE(vish): These constraint names may be dependent on the backend, but
# there doesn't seem to be we a way to determine the proper
# name for existing constraints. These names are correct for
# mysql.
cons = UniqueConstraint('name',
name='name',
name=c_names['instance_types_name'],
table=table)
cons.create()
table = Table('instance_types', meta, autoload=True)
cons = UniqueConstraint('flavorid',
name='instance_types_flavorid_str_key',
name=c_names['instance_types_flavorid'],
table=table)
cons.create()
table = Table('volume_types', meta, autoload=True)
cons = UniqueConstraint('name',
name='name',
name=c_names['volume_types_name'],
table=table)
cons.create()