19"""Add Outgoing enum value to sippeers directmedia
21Revision ID: 10aedae86a32
23Create Date: 2014-09-19 16:03:13.469436
28revision =
'10aedae86a32'
29down_revision =
'5950038a6ead'
32from sqlalchemy.dialects.postgresql
import ENUM
33import sqlalchemy
as sa
35OLD_ENUM = [
'yes',
'no',
'nonat',
'update']
36NEW_ENUM = [
'yes',
'no',
'nonat',
'update',
'outgoing']
38old_type = sa.Enum(*OLD_ENUM, name=
'sip_directmedia_values')
39new_type = sa.Enum(*NEW_ENUM, name=
'sip_directmedia_values_v2')
41tcr = sa.sql.table(
'sippeers', sa.Column(
'directmedia', new_type,
45 context = op.get_context()
48 if context.bind.dialect.name !=
'postgresql':
49 op.alter_column(
'sippeers',
'directmedia',
51 existing_type=old_type)
53 enum = ENUM(
"yes",
"no",
"nonat",
"update",
"outgoing",
54 name=
"sip_directmedia_values_v2")
55 enum.create(op.get_bind(), checkfirst=
False)
57 op.execute(
'ALTER TABLE sippeers ALTER COLUMN directmedia TYPE'
58 ' sip_directmedia_values_v2 USING'
59 ' directmedia::text::sip_directmedia_values_v2')
61 ENUM(name=
"sip_directmedia_values").drop(op.get_bind(), checkfirst=
False)
64 context = op.get_context()
66 op.execute(tcr.update().where(tcr.c.directmedia==
u'outgoing')
69 if context.bind.dialect.name !=
'postgresql':
70 op.alter_column(
'sippeers',
'directmedia',
72 existing_type=new_type)
74 enum = ENUM(
"yes",
"no",
"nonat",
"update",
75 name=
"sip_directmedia_values")
76 enum.create(op.get_bind(), checkfirst=
False)
78 op.execute(
'ALTER TABLE sippeers ALTER COLUMN directmedia TYPE'
79 ' sip_directmedia_values USING'
80 ' directmedia::text::sip_directmedia_values')
82 ENUM(name=
"sip_directmedia_values_v2").drop(op.get_bind(),