3 Revision ID: 3772f8f828da 5 Create Date: 2016-08-11 10:47:29.211063 10 revision =
'3772f8f828da' 11 down_revision =
'c7a44a5a0851' 13 from alembic
import op
14 import sqlalchemy
as sa
17 def enum_update(table_name, column_name, enum_name, enum_values):
18 if op.get_context().bind.dialect.name !=
'postgresql':
19 if op.get_context().bind.dialect.name ==
'mssql':
20 op.drop_constraint(
'ck_ps_endpoints_identify_by_pjsip_identify_by_values',
'ps_endpoints')
21 op.alter_column(table_name, column_name,
22 type_=sa.Enum(*enum_values, name=enum_name))
26 tmp = enum_name +
'_tmp' 28 op.execute(
'ALTER TYPE ' + enum_name +
' RENAME TO ' + tmp)
30 updated = sa.Enum(*enum_values, name=enum_name)
31 updated.create(op.get_bind(), checkfirst=
False)
33 op.execute(
'ALTER TABLE ' + table_name +
' ALTER COLUMN ' + column_name +
34 ' TYPE ' + enum_name +
' USING identify_by::text::' + enum_name)
36 op.execute(
'DROP TYPE ' + tmp)
40 enum_update(
'ps_endpoints',
'identify_by',
'pjsip_identify_by_values',
41 [
'username',
'auth_username'])
45 enum_update(
'ps_endpoints',
'identify_by',
'pjsip_identify_by_values',
def enum_update(table_name, column_name, enum_name, enum_values)