2 # Asterisk -- An open source telephony toolkit.
4 # Copyright (C) 2014, Jonathan Rose
6 # Jonathan R. Rose <jrose@digium.com>
8 # See http://www.asterisk.org for more information about
9 # the Asterisk project. Please do not directly contact
10 # any of the maintainers of this project for assistance;
11 # the project provides a web site, mailing lists and IRC
12 # channels for your use.
14 # This program is free software, distributed under the terms of
15 # the GNU General Public License Version 2. See the LICENSE file
16 # at the top of the source tree.
19 """Add Outgoing enum value to sippeers directmedia
21 Revision ID: 10aedae86a32
23 Create Date: 2014-09-19 16:03:13.469436
27 # revision identifiers, used by Alembic.
28 revision = '10aedae86a32'
29 down_revision = '5950038a6ead'
31 from alembic import op
32 from sqlalchemy.dialects.postgresql import ENUM
33 import sqlalchemy as sa
35 OLD_ENUM = ['yes', 'no', 'nonat', 'update']
36 NEW_ENUM = ['yes', 'no', 'nonat', 'update', 'outgoing']
38 old_type = sa.Enum(*OLD_ENUM, name='sip_directmedia_values')
39 new_type = sa.Enum(*NEW_ENUM, name='sip_directmedia_values_v2')
41 tcr = sa.sql.table('sippeers', sa.Column('directmedia', new_type,
45 context = op.get_context()
47 # Upgrading to this revision WILL clear your directmedia values.
48 if context.bind.dialect.name == 'sqlite':
49 with op.batch_alter_table('sippeers') as batch_op:
50 batch_op.alter_column('directmedia', type_=new_type)
51 elif context.bind.dialect.name != 'postgresql':
52 op.alter_column('sippeers', 'directmedia',
54 existing_type=old_type)
56 enum = ENUM("yes", "no", "nonat", "update", "outgoing",
57 name="sip_directmedia_values_v2")
58 enum.create(op.get_bind(), checkfirst=False)
60 op.execute('ALTER TABLE sippeers ALTER COLUMN directmedia TYPE'
61 ' sip_directmedia_values_v2 USING'
62 ' directmedia::text::sip_directmedia_values_v2')
64 ENUM(name="sip_directmedia_values").drop(op.get_bind(), checkfirst=False)
67 context = op.get_context()
69 op.execute(tcr.update().where(tcr.c.directmedia==u'outgoing')
70 .values(directmedia=None))
72 if context.bind.dialect.name == 'sqlite':
73 with op.batch_alter_table('sippeers') as batch_op:
74 batch_op.alter_column('directmedia', type_=old_type)
75 elif context.bind.dialect.name != 'postgresql':
76 op.alter_column('sippeers', 'directmedia',
78 existing_type=new_type)
80 enum = ENUM("yes", "no", "nonat", "update",
81 name="sip_directmedia_values")
82 enum.create(op.get_bind(), checkfirst=False)
84 op.execute('ALTER TABLE sippeers ALTER COLUMN directmedia TYPE'
85 ' sip_directmedia_values USING'
86 ' directmedia::text::sip_directmedia_values')
88 ENUM(name="sip_directmedia_values_v2").drop(op.get_bind(),