10aedae86a32_add_outgoing_enum_va.py

Go to the documentation of this file.
00001 #
00002 # Asterisk -- An open source telephony toolkit.
00003 #
00004 # Copyright (C) 2014, Jonathan Rose
00005 #
00006 # Jonathan R. Rose <jrose@digium.com>
00007 #
00008 # See http://www.asterisk.org for more information about
00009 # the Asterisk project. Please do not directly contact
00010 # any of the maintainers of this project for assistance;
00011 # the project provides a web site, mailing lists and IRC
00012 # channels for your use.
00013 #
00014 # This program is free software, distributed under the terms of
00015 # the GNU General Public License Version 2. See the LICENSE file
00016 # at the top of the source tree.
00017 #
00018 
00019 """Add Outgoing enum value to sippeers directmedia
00020 
00021 Revision ID: 10aedae86a32
00022 Revises: 5950038a6ead
00023 Create Date: 2014-09-19 16:03:13.469436
00024 
00025 """
00026 
00027 # revision identifiers, used by Alembic.
00028 revision = '10aedae86a32'
00029 down_revision = '5950038a6ead'
00030 
00031 from alembic import op
00032 from sqlalchemy.dialects.postgresql import ENUM
00033 import sqlalchemy as sa
00034 
00035 OLD_ENUM = ['yes', 'no', 'nonat', 'update']
00036 NEW_ENUM = ['yes', 'no', 'nonat', 'update', 'outgoing']
00037 
00038 old_type = sa.Enum(*OLD_ENUM, name='sip_directmedia_values')
00039 new_type = sa.Enum(*NEW_ENUM, name='sip_directmedia_values_v2')
00040 
00041 tcr = sa.sql.table('sippeers', sa.Column('directmedia', new_type,
00042                    nullable=True))
00043 
00044 def upgrade():
00045     context = op.get_context()
00046 
00047     # Upgrading to this revision WILL clear your directmedia values.
00048     if context.bind.dialect.name != 'postgresql':
00049         op.alter_column('sippeers', 'directmedia',
00050                         type_=new_type,
00051                         existing_type=old_type)
00052     else:
00053         enum = ENUM("yes", "no", "nonat", "update", "outgoing",
00054                     name="sip_directmedia_values_v2")
00055         enum.create(op.get_bind(), checkfirst=False)
00056 
00057         op.execute('ALTER TABLE sippeers ALTER COLUMN directmedia TYPE'
00058                    ' sip_directmedia_values_v2 USING'
00059                    ' directmedia::text::sip_directmedia_values_v2')
00060 
00061         ENUM(name="sip_directmedia_values").drop(op.get_bind(), checkfirst=False)
00062 
00063 def downgrade():
00064     context = op.get_context()
00065 
00066     op.execute(tcr.update().where(tcr.c.directmedia==u'outgoing')
00067                .values(directmedia=None))
00068 
00069     if context.bind.dialect.name != 'postgresql':
00070         op.alter_column('sippeers', 'directmedia',
00071                         type_=old_type,
00072                         existing_type=new_type)
00073     else:
00074         enum = ENUM("yes", "no", "nonat", "update",
00075                     name="sip_directmedia_values")
00076         enum.create(op.get_bind(), checkfirst=False)
00077 
00078         op.execute('ALTER TABLE sippeers ALTER COLUMN directmedia TYPE'
00079                    ' sip_directmedia_values USING'
00080                    ' directmedia::text::sip_directmedia_values')
00081 
00082         ENUM(name="sip_directmedia_values_v2").drop(op.get_bind(),
00083                                                 checkfirst=False)

Generated on Thu Apr 16 06:27:05 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6