31cd4f4891ec_add_auto_dtmf_mode.py

Go to the documentation of this file.
00001 """Add auto DTMF mode
00002 
00003 Revision ID: 31cd4f4891ec
00004 Revises: 23530d604b96
00005 Create Date: 2015-04-10 12:36:51.619419
00006 
00007 """
00008 
00009 # revision identifiers, used by Alembic.
00010 revision = '31cd4f4891ec'
00011 down_revision = '23530d604b96'
00012 
00013 from alembic import op
00014 import sqlalchemy as sa
00015 
00016 OLD_ENUM = ['rfc4733', 'inband', 'info']
00017 NEW_ENUM = ['rfc4733', 'inband', 'info', 'auto']
00018 
00019 old_type = sa.Enum(*OLD_ENUM, name='pjsip_dtmf_mode_values')
00020 new_type = sa.Enum(*NEW_ENUM, name='pjsip_dtmf_mode_values_v2')
00021 
00022 tcr = sa.sql.table('ps_endpoints', sa.Column('dtmf_mode', new_type,
00023                    nullable=True))
00024 
00025 def upgrade():
00026     context = op.get_context()
00027 
00028     # Upgrading to this revision WILL clear your directmedia values.
00029     if context.bind.dialect.name != 'postgresql':
00030         op.alter_column('ps_endpoints', 'dtmf_mode',
00031                         type_=new_type,
00032                         existing_type=old_type)
00033     else:
00034         enum = ENUM('rfc4733', 'inband', 'info', 'auto',
00035                     name='pjsip_dtmf_mode_values_v2')
00036         enum.create(op.get_bind(), checkfirst=False)
00037 
00038         op.execute('ALTER TABLE ps_endpoints ALTER COLUMN dtmf_mode TYPE'
00039                    ' pjsip_dtmf_mode_values_v2 USING'
00040                    ' dtmf_mode::text::pjsip_dtmf_mode_values_v2')
00041 
00042         ENUM(name="pjsip_dtmf_mode_values").drop(op.get_bind(), checkfirst=False)
00043 
00044 def downgrade():
00045     context = op.get_context()
00046 
00047     op.execute(tcr.update().where(tcr.c.directmedia==u'outgoing')
00048                .values(directmedia=None))
00049 
00050     if context.bind.dialect.name != 'postgresql':
00051         op.alter_column('ps_endpoints', 'dtmf_mode',
00052                         type_=old_type,
00053                         existing_type=new_type)
00054     else:
00055         enum = ENUM('rfc4733', 'inband', 'info',
00056                     name='pjsip_dtmf_mode_values')
00057         enum.create(op.get_bind(), checkfirst=False)
00058 
00059         op.execute('ALTER TABLE ps_endpoints ALTER COLUMN dtmf_mode TYPE'
00060                    ' pjsip_dtmf_mode_values USING'
00061                    ' dtmf_mode::text::pjsip_dtmf_mode_values')
00062 
00063         ENUM(name="pjsip_dtmf_mode_values_v2").drop(op.get_bind(), checkfirst=False)

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