1"""Fix mwi_subscribe_replaces_unsolicited
3Revision ID: fe6592859b85
5Create Date: 2018-08-06 15:50:44.405534
10revision =
'fe6592859b85'
11down_revision =
'1d3ed26d9978'
14import sqlalchemy
as sa
15from sqlalchemy.dialects.postgresql
import ENUM
17AST_BOOL_NAME =
'ast_bool_values'
20AST_BOOL_VALUES = [
'0',
'1',
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)
34 op.alter_column(
'ps_endpoints',
'mwi_subscribe_replaces_unsolicited',
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))
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'")
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',
57 op.alter_column(
'ps_endpoints',
'mwi_subscribe_replaces_unsolicited',
58 type_=sa.Integer, postgresql_using=
'mwi_subscribe_replaces_unsolicited::Integer')
60 if op.get_context().bind.dialect.name ==
'postgresql':
61 ENUM(name=AST_BOOL_NAME).drop(op.get_bind(), checkfirst=
False)