| 1 |
"""Fix mwi_subscribe_replaces_unsolicited |
| 2 |
|
| 3 |
Revision ID: fe6592859b85 |
| 4 |
Revises: 1d3ed26d9978 |
| 5 |
Create Date: 2018-08-06 15:50:44.405534 |
| 6 |
|
| 7 |
""" |
| 8 |
|
| 9 |
|
| 10 |
revision = 'fe6592859b85' |
| 11 |
down_revision = '1d3ed26d9978' |
| 12 |
|
| 13 |
from alembic import op |
| 14 |
import sqlalchemy as sa |
| 15 |
from sqlalchemy.dialects.postgresql import ENUM |
| 16 |
|
| 17 |
AST_BOOL_NAME = 'ast_bool_values' |
| 18 |
|
| 19 |
|
| 20 |
AST_BOOL_VALUES = [ '0', '1', |
| 21 |
'off', 'on', |
| 22 |
'false', 'true', |
| 23 |
'no', 'yes' ] |
| 24 |
|
| 25 |
|
| 26 |
def upgrade(): |
| 27 |
|
| 28 |
ast_bool_values = ENUM(*AST_BOOL_VALUES, name=AST_BOOL_NAME, create_type=False) |
| 29 |
if op.get_context().bind.dialect.name == 'postgresql': |
| 30 |
ast_bool_values.create(op.get_bind(), checkfirst=False) |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
op.alter_column('ps_endpoints', 'mwi_subscribe_replaces_unsolicited', |
| 35 |
type_=sa.String(5)) |
| 36 |
op.alter_column('ps_endpoints', 'mwi_subscribe_replaces_unsolicited', |
| 37 |
type_=ast_bool_values, postgresql_using='mwi_subscribe_replaces_unsolicited::{0}'.format(AST_BOOL_NAME)) |
| 38 |
|
| 39 |
|
| 40 |
def downgrade(): |
| 41 |
|
| 42 |
op.execute("UPDATE ps_endpoints SET mwi_subscribe_replaces_unsolicited='0'" |
| 43 |
" WHERE mwi_subscribe_replaces_unsolicited='off'" |
| 44 |
" OR mwi_subscribe_replaces_unsolicited='false'" |
| 45 |
" OR mwi_subscribe_replaces_unsolicited='no'") |
| 46 |
op.execute("UPDATE ps_endpoints SET mwi_subscribe_replaces_unsolicited='1'" |
| 47 |
" WHERE mwi_subscribe_replaces_unsolicited='on'" |
| 48 |
" OR mwi_subscribe_replaces_unsolicited='true'" |
| 49 |
" OR mwi_subscribe_replaces_unsolicited='yes'") |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
if op.get_context().bind.dialect.name == 'mssql': |
| 54 |
op.drop_constraint('ck_ps_endpoints_mwi_subscribe_replaces_unsolicited_ast_bool_values', 'ps_endpoints') |
| 55 |
op.alter_column('ps_endpoints', 'mwi_subscribe_replaces_unsolicited', |
| 56 |
type_=sa.String(5)) |
| 57 |
op.alter_column('ps_endpoints', 'mwi_subscribe_replaces_unsolicited', |
| 58 |
type_=sa.Integer, postgresql_using='mwi_subscribe_replaces_unsolicited::Integer') |
| 59 |
|
| 60 |
if op.get_context().bind.dialect.name == 'postgresql': |
| 61 |
ENUM(name=AST_BOOL_NAME).drop(op.get_bind(), checkfirst=False) |