Merge "Fix DB2 column 'id' autoincrement issue"

This commit is contained in:
Jenkins 2014-10-21 18:47:07 +00:00 committed by Gerrit Code Review
commit 466937da1f
1 changed files with 9 additions and 1 deletions

View File

@ -84,7 +84,15 @@ def upgrade(migrate_engine):
cons = constraint.PrimaryKeyConstraint('tmp_id', table=event_table)
cons.create()
event_table.c.tmp_id.alter(sqlalchemy.Integer, autoincrement=True)
if migrate_engine.name == 'ibm_db_sa':
# NOTE(chenxiao): For DB2, setting "ID" column "autoincrement=True"
# can't make sense after above "tmp_id=>id" transformation,
# so should work around it.
sql = "ALTER TABLE EVENT ALTER COLUMN ID SET GENERATED BY " \
"DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1)"
migrate_engine.execute(sql)
else:
event_table.c.tmp_id.alter(sqlalchemy.Integer, autoincrement=True)
def upgrade_sqlite(migrate_engine):