dbc8ce9c4d0c8ba5f44b6d8a14b7c5aabc970046
[asterisk/asterisk.git] / contrib / ast-db-manage / config / versions / 164abbd708c_add_auto_info_to_endpoint_dtmf_mode.py
1 """Add auto_info to endpoint dtmf_mode
2
3 Revision ID: 164abbd708c
4 Revises: 86bb1efa278d
5 Create Date: 2017-06-19 13:55:15.354706
6
7 """
8
9 # revision identifiers, used by Alembic.
10 revision = '164abbd708c'
11 down_revision = '86bb1efa278d'
12
13 from alembic import op
14 import sqlalchemy as sa
15
16 OLD_ENUM = ['rfc4733', 'inband', 'info', 'auto']
17 NEW_ENUM = ['rfc4733', 'inband', 'info', 'auto', 'auto_info']
18
19 old_type = sa.Enum(*OLD_ENUM, name='pjsip_dtmf_mode_values_v2')
20 new_type = sa.Enum(*NEW_ENUM, name='pjsip_dtmf_mode_values_v3')
21
22 def upgrade():
23     context = op.get_context()
24
25     # Upgrading to this revision WILL clear your directmedia values.
26     if context.bind.dialect.name != 'postgresql':
27         op.alter_column('ps_endpoints', 'dtmf_mode',
28                         type_=new_type,
29                         existing_type=old_type)
30     else:
31         enum = ENUM('rfc4733', 'inband', 'info', 'auto', 'auto_info',
32                     name='pjsip_dtmf_mode_values_v3')
33         enum.create(op.get_bind(), checkfirst=False)
34
35         op.execute('ALTER TABLE ps_endpoints ALTER COLUMN dtmf_mode TYPE'
36                    ' pjsip_dtmf_mode_values_v3 USING'
37                    ' dtmf_mode::text::pjsip_dtmf_mode_values_v3')
38
39         ENUM(name="pjsip_dtmf_mode_values_v2").drop(op.get_bind(), checkfirst=False)
40
41 def downgrade():
42     context = op.get_context()
43
44     if context.bind.dialect.name != 'postgresql':
45         op.alter_column('ps_endpoints', 'dtmf_mode',
46                         type_=old_type,
47                         existing_type=new_type)
48     else:
49         enum = ENUM('rfc4733', 'inband', 'info', 'auto',
50                     name='pjsip_dtmf_mode_values_v2')
51         enum.create(op.get_bind(), checkfirst=False)
52
53         op.execute('ALTER TABLE ps_endpoints ALTER COLUMN dtmf_mode TYPE'
54                    ' pjsip_dtmf_mode_values USING'
55                    ' dtmf_mode::text::pjsip_dtmf_mode_values_v2')
56
57         ENUM(name="pjsip_dtmf_mode_values_v3").drop(op.get_bind(), checkfirst=False)