diff options
author | George Joseph <george.joseph@fairview5.com> | 2016-03-01 19:03:04 -0700 |
---|---|---|
committer | George Joseph <george.joseph@fairview5.com> | 2016-03-02 15:48:27 -0700 |
commit | 86d6e44cc1ebc1c0e4ed5cf872ca9416d276c038 (patch) | |
tree | 70a7f807961332fef89f3ca6df2ba720cc7c4754 /contrib/ast-db-manage/config/versions/5139253c0423_make_q_member_uniqueid_autoinc.py | |
parent | d1495bc0ebed86d322488bed647b43aba0ae9b1f (diff) |
alembic: Fix downgrade and tweak for sqlite
Downgrade had a few issues. First there was an errant 'update' statement in
add_auto_dtmf_mode that looks like it was a copy/paste error. Second, we
weren't cleaning up the ENUMs so subsequent upgrades on postgres failed
because the types already existed.
For sqlite... sqlite doesn't support ALTER or DROP COLUMN directly.
Fortunately alembic batch_operations takes care of this for us if we
use it so the alter and drops were converted to use batch operations.
Here's an example downgrade:
with op.batch_alter_table('ps_endpoints') as batch_op:
batch_op.drop_column('tos_audio')
batch_op.drop_column('tos_video')
batch_op.add_column(sa.Column('tos_audio', yesno_values))
batch_op.add_column(sa.Column('tos_video', yesno_values))
batch_op.drop_column('cos_audio')
batch_op.drop_column('cos_video')
batch_op.add_column(sa.Column('cos_audio', yesno_values))
batch_op.add_column(sa.Column('cos_video', yesno_values))
with op.batch_alter_table('ps_transports') as batch_op:
batch_op.drop_column('tos')
batch_op.add_column(sa.Column('tos', yesno_values))
# Can't cast integers to YESNO_VALUES, so dropping and adding is required
batch_op.drop_column('cos')
batch_op.add_column(sa.Column('cos', yesno_values))
Upgrades from base to head and downgrades from head to base were tested
repeatedly for postgresql, mysql/mariadb, and sqlite3.
Change-Id: I862b0739eb3fd45ec3412dcc13c2340e1b7baef8
Diffstat (limited to 'contrib/ast-db-manage/config/versions/5139253c0423_make_q_member_uniqueid_autoinc.py')
-rwxr-xr-x | contrib/ast-db-manage/config/versions/5139253c0423_make_q_member_uniqueid_autoinc.py | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/contrib/ast-db-manage/config/versions/5139253c0423_make_q_member_uniqueid_autoinc.py b/contrib/ast-db-manage/config/versions/5139253c0423_make_q_member_uniqueid_autoinc.py index 6bcaa9a10..632f4c4eb 100755 --- a/contrib/ast-db-manage/config/versions/5139253c0423_make_q_member_uniqueid_autoinc.py +++ b/contrib/ast-db-manage/config/versions/5139253c0423_make_q_member_uniqueid_autoinc.py @@ -33,28 +33,31 @@ import sqlalchemy as sa def upgrade(): + context = op.get_context() # Was unable to find a way to use op.alter_column() to add the unique # index property. - op.drop_column('queue_members', 'uniqueid') - op.add_column( - 'queue_members', - sa.Column( - name='uniqueid', type_=sa.Integer, nullable=False, - unique=True)) + if context.bind.dialect.name == 'sqlite': + with op.batch_alter_table('queue_members') as batch_op: + batch_op.create_primary_key('queue_members_pj', columns='uniqueid') + else: + op.drop_column('queue_members', 'uniqueid') + op.add_column( + 'queue_members', + sa.Column( + name='uniqueid', type_=sa.Integer, nullable=False, + unique=True)) # The postgres backend does not like the autoincrement needed for # mysql here. It is just the backend that is giving a warning and # not the database itself. - op.alter_column( - table_name='queue_members', column_name='uniqueid', - existing_type=sa.Integer, existing_nullable=False, - autoincrement=True) + op.alter_column( + table_name='queue_members', column_name='uniqueid', + existing_type=sa.Integer, existing_nullable=False, + autoincrement=True) def downgrade(): # Was unable to find a way to use op.alter_column() to remove the # unique index property. - op.drop_column('queue_members', 'uniqueid') - op.add_column( - 'queue_members', - sa.Column(name='uniqueid', type_=sa.String(80), nullable=False)) - + with op.batch_alter_table('queue_members') as batch_op: + batch_op.drop_column('uniqueid') + batch_op.add_column(sa.Column(name='uniqueid', type_=sa.String(80), nullable=False)) |