diff options
author | Matt Riedemann <mriedem@us.ibm.com> | 2015-06-16 08:38:39 -0700 |
---|---|---|
committer | Matt Riedemann <mriedem@us.ibm.com> | 2015-07-08 16:45:37 -0700 |
commit | 9a84211729ef30c1b568856a91b82d581b02688b (patch) | |
tree | 0d021ea98d760699c59dd23bade0306562359cb7 /tools | |
parent | 47b233f988bddd1272e4a1bc02be97f15701a8ca (diff) | |
download | nova-9a84211729ef30c1b568856a91b82d581b02688b.tar.gz |
Add DB2 support
Notes on migration changes/tests:
1. The initial havana migration does not create any foreign keys which
require the instances.uuid column since it's nullable and DB2 won't
allow creating a unique constraint over a nullable column. To create
the foreign keys on instances.uuid, this change depends on commit
e07a2b2d4be0503ad8dad75daa632be27cf83320 to make instances.uuid
non-nullable and create a unique constraint on that column. Then
the new migration here creates the missing instances.uuid
related foreign keys for DB2.
2. Commit b930fb3a6b0ab8cbe0c19eb3ab8ba33d60d147be changed
test_migrations.py to use oslo.db's opportunistic test fixture
which currently only supports sqlite/mysql/postgresql. Unit test
support for DB2 therefore needs to be added to oslo.db and then
hooked into nova, but that's targeted for the 2016.1 'M' release
so is not part of this change.
3. The 247_nullable_mismatch migration is updated for DB2 because
making the pci_devices.deleted column nullable=True fails since
the column is in a UniqueConstraint already (DB2 would require
it to be in a unique index instead for the column to be nullable).
There is a foreign key involved (created in 246) so for DB2 to
have the same FKey it requires a UC and that requires the deleted
column to be non-null, which doesn't work with the SoftDeleteMixin.
So in this case the schema will diverge for DB2 until we make
the deleted column non-nullable for all tables.
4. The 252_add_instance_extra_table migration is updated for DB2
because a foreign key is created between the instance_extra
table and the instances.uuid column (which is nullable at the
time) so we have to handle that foreign key constraint creation
in the 296 migration with the other foreign keys to
instances.uuid.
5. The 271 migration is updated to add ibm_db_sa the same as
sqlite and postgresql since it works the same in this case for
DB2.
6. The API migrations need checks for DB2 to avoid a duplicate index
SQL0605W error since DB2 implicitly creates an Index when a
UniqueConstraint is created and will fail if trying to add a
duplicate index on the same column(s) that are in the UC.
Implements blueprint db2-database
Change-Id: Ic4224e2545bcdfeb236b071642f9f16d9ee3b99f
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/db/schema_diff.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/tools/db/schema_diff.py b/tools/db/schema_diff.py index 46034d2806..bc145cf04a 100755 --- a/tools/db/schema_diff.py +++ b/tools/db/schema_diff.py @@ -39,6 +39,10 @@ Run like: ./tools/db/schema_diff.py postgresql://localhost \ master:latest my_branch:82 + + DB2: + ./tools/db/schema_diff.py ibm_db_sa://localhost \ + master:latest my_branch:82 """ from __future__ import print_function @@ -117,6 +121,28 @@ class Postgresql(object): shell=True) +class Ibm_db_sa(object): + + @classmethod + def db2cmd(cls, cmd): + """Wraps a command to be run under the DB2 instance user.""" + subprocess.check_call('su - $(db2ilist) -c "%s"' % cmd, shell=True) + + def create(self, name): + self.db2cmd('db2 \'create database %s\'' % name) + + def drop(self, name): + self.db2cmd('db2 \'drop database %s\'' % name) + + def dump(self, name, dump_filename): + self.db2cmd('db2look -d %(name)s -e -o %(dump_filename)s' % + {'name': name, 'dump_filename': dump_filename}) + # The output file gets dumped to the db2 instance user's home directory + # so we have to copy it back to our current working directory. + subprocess.check_call('cp /home/$(db2ilist)/%s ./' % dump_filename, + shell=True) + + def _get_db_driver_class(db_url): try: return globals()[db_url.split('://')[0].capitalize()] |