alembic: Fix downgrade and tweak for sqlite
authorGeorge Joseph <george.joseph@fairview5.com>
Wed, 2 Mar 2016 02:03:04 +0000 (19:03 -0700)
committerGeorge Joseph <george.joseph@fairview5.com>
Wed, 2 Mar 2016 22:48:27 +0000 (15:48 -0700)
commit86d6e44cc1ebc1c0e4ed5cf872ca9416d276c038
tree70a7f807961332fef89f3ca6df2ba720cc7c4754
parentd1495bc0ebed86d322488bed647b43aba0ae9b1f
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
33 files changed:
contrib/ast-db-manage/config/env.py
contrib/ast-db-manage/config/versions/10aedae86a32_add_outgoing_enum_va.py
contrib/ast-db-manage/config/versions/136885b81223_add_regcontext_to_pj.py
contrib/ast-db-manage/config/versions/154177371065_add_default_from_user.py
contrib/ast-db-manage/config/versions/1758e8bbf6b_increase_useragent_column_size.py
contrib/ast-db-manage/config/versions/189a235b3fd7_add_keep_alive_interval.py
contrib/ast-db-manage/config/versions/1d50859ed02e_create_accountcode.py
contrib/ast-db-manage/config/versions/21e526ad3040_add_pjsip_debug_option.py
contrib/ast-db-manage/config/versions/23530d604b96_add_rpid_immediate.py
contrib/ast-db-manage/config/versions/26d7f3bf0fa5_add_bind_rtp_to_media_address_to_pjsip.py
contrib/ast-db-manage/config/versions/26f10cadc157_add_pjsip_timeout_options.py
contrib/ast-db-manage/config/versions/28b8e71e541f_add_g726_non_standard.py
contrib/ast-db-manage/config/versions/28ce1e718f05_add_fatal_response_interval.py
contrib/ast-db-manage/config/versions/2d078ec071b7_increaes_contact_column_size.py
contrib/ast-db-manage/config/versions/2fc7930b41b3_add_pjsip_endpoint_options_for_12_1.py
contrib/ast-db-manage/config/versions/31cd4f4891ec_add_auto_dtmf_mode.py
contrib/ast-db-manage/config/versions/371a3bf4143e_add_user_eq_phone_option_to_pjsip.py
contrib/ast-db-manage/config/versions/3855ee4e5f85_add_missing_pjsip_options.py
contrib/ast-db-manage/config/versions/3bcc0b5bc2c9_add_allow_reload_to_ps_transports.py
contrib/ast-db-manage/config/versions/423f34ad36e2_fix_pjsip_qualify_ti.py
contrib/ast-db-manage/config/versions/43956d550a44_add_tables_for_pjsip.py
contrib/ast-db-manage/config/versions/45e3f47c6c44_add_pjsip_endpoint_identifier_order.py
contrib/ast-db-manage/config/versions/461d7d691209_add_pjsip_qualify_timeout.py
contrib/ast-db-manage/config/versions/498357a710ae_add_rtp_keepalive.py
contrib/ast-db-manage/config/versions/4c573e7135bd_fix_tos_field_types.py
contrib/ast-db-manage/config/versions/4da0c5f79a9c_create_tables.py
contrib/ast-db-manage/config/versions/5139253c0423_make_q_member_uniqueid_autoinc.py
contrib/ast-db-manage/config/versions/51f8cb66540e_add_further_dtls_options.py
contrib/ast-db-manage/config/versions/5950038a6ead_fix_pjsip_verifiy_typo.py
contrib/ast-db-manage/config/versions/a541e0b5e89_add_pjsip_max_initial_qualify_time.py
contrib/ast-db-manage/config/versions/dbc44d5a908_add_missing_columns_to_sys_and_reg.py
contrib/ast-db-manage/config/versions/e96a0b8071c_increase_pjsip_column_size.py
contrib/ast-db-manage/config/versions/eb88a14f2a_add_media_encryption_optimistic_to_pjsip.py