wmjie / ibm-db

Automatically exported from code.google.com/p/ibm-db
0 stars 0 forks source link

Don't create invalid primary key index on Column alter #173

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

OpenStack keystone has code like this (see 
https://review.openstack.org/#/c/142472/15/keystone/common/sql/migrate_repo/vers
ions/073_insert_assignment_inherited_pk.py )

        migrate.PrimaryKeyConstraint(table=assignment_table).drop()
        assignment_table.c.inherited.alter(primary_key=True)
        migrate.PrimaryKeyConstraint(table=assignment_table).create()

From earlier migrations, the assignment_table was created with a primary key 
over a several columns. This code is trying to add another column ("inherited") 
to the primary key.

What is the expected output? What do you see instead?

Using the DB2 dialect this fails because 
"assignment_table.c.inherited.alter(primary_key=True)" actually creates a 
primary key over only the "inherited" column. This is wrong because the primary 
key for the table actually covers other columns too, not just the "inherited" 
column.

Since the primary key already exists for the table after the Column.alter() 
call, it causes the next line to fail with an error that the primary key 
already exists.

This all works fine using the mysql dialect. The primary key isn't recreated on 
the call to Column.alter(), and the primary key is created over all the table's 
primary key columns on the call to PrimaryKeyConstraint().create().

What version of the product are you using? On what operating system?

ibm-db==2.0.5.1
ibm-db-sa==0.3.2
sqlalchemy-migrate==0.9.6

Ubuntu 14.04

Original issue reported on code.google.com by BrantKnu...@gmail.com on 9 May 2015 at 4:30

GoogleCodeExporter commented 9 years ago
This issue is related to sqlalchemy-migrate, If 
assignment_table.c.inherited.alter(primary_key=True) doesn't create primary key 
on other database backends then to match the behavior you need to remove 
line#187 to #189 of 
https://github.com/stackforge/sqlalchemy-migrate/blob/master/migrate/changeset/d
atabases/ibmdb2.py .

Original comment by rahul.pr...@in.ibm.com on 12 May 2015 at 11:13