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/dbc44d5a908_add_missing_columns_to_sys_and_reg.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/dbc44d5a908_add_missing_columns_to_sys_and_reg.py')
-rw-r--r-- | contrib/ast-db-manage/config/versions/dbc44d5a908_add_missing_columns_to_sys_and_reg.py | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/contrib/ast-db-manage/config/versions/dbc44d5a908_add_missing_columns_to_sys_and_reg.py b/contrib/ast-db-manage/config/versions/dbc44d5a908_add_missing_columns_to_sys_and_reg.py index 8f4621642..b4502eb3d 100644 --- a/contrib/ast-db-manage/config/versions/dbc44d5a908_add_missing_columns_to_sys_and_reg.py +++ b/contrib/ast-db-manage/config/versions/dbc44d5a908_add_missing_columns_to_sys_and_reg.py @@ -27,11 +27,10 @@ def upgrade(): op.add_column('ps_systems', sa.Column('disable_tcp_switch', yesno_values)) op.add_column('ps_registrations', sa.Column('line', yesno_values)) op.add_column('ps_registrations', sa.Column('endpoint', sa.String(40))) - pass - def downgrade(): - op.drop_column('ps_systems', 'disable_tcp_switch') - op.drop_column('ps_registrations', 'line') - op.drop_column('ps_registrations', 'endpoint') - pass + with op.batch_alter_table('ps_systems') as batch_op: + batch_op.drop_column('disable_tcp_switch') + with op.batch_alter_table('ps_registrations') as batch_op: + batch_op.drop_column('line') + batch_op.drop_column('endpoint') |