Fix migrations to maintain compatibility with sqlite

The current command used for alter a column (drop or alter) missing
the compatibility with sqllite. Solution, pass by using batch alembic.
Read http://alembic.readthedocs.org/en/latest/batch.html for more info.

Change-Id: I32c5cecaad111f2bde559de74ecefa339739b994
This commit is contained in:
Jesus Perez 2016-01-19 09:20:09 +01:00
parent b50564d65d
commit 9941585945
2 changed files with 12 additions and 6 deletions

View File

@ -31,8 +31,10 @@ MYSQL_CHARSET = 'utf8'
def upgrade():
op.drop_column('environment', 'networking')
op.drop_column('environment-template', 'networking')
with op.batch_alter_table("environment") as batch_op:
batch_op.drop_column('networking')
with op.batch_alter_table("environment-template") as batch_op2:
batch_op2.drop_column('networking')
def downgrade():

View File

@ -33,12 +33,16 @@ MYSQL_CHARSET = 'utf8'
def upgrade():
op.alter_column('session', 'user_id', type_=sa.String(64), nullable=False)
op.alter_column('package', 'owner_id', type_=sa.String(64), nullable=False)
with op.batch_alter_table("session") as batch_op:
batch_op.alter_column('user_id', type_=sa.String(64), nullable=False)
with op.batch_alter_table("package") as batch_op2:
batch_op2.alter_column('owner_id', type_=sa.String(64), nullable=False)
# end Alembic commands #
def downgrade():
op.alter_column('package', 'owner_id', type_=sa.String(36), nullable=False)
op.alter_column('session', 'user_id', type_=sa.String(36), nullable=False)
with op.batch_alter_table("session") as batch_op:
batch_op.alter_column('user_id', type_=sa.String(36), nullable=False)
with op.batch_alter_table("package") as batch_op2:
batch_op2.alter_column('owner_id', type_=sa.String(36), nullable=False)
# end Alembic commands #