summaryrefslogtreecommitdiff
path: root/contrib/ast-db-manage/config/versions/164abbd708c_add_auto_info_to_endpoint_dtmf_mode.py
blob: d7d111dd729d9d051231c2b2cdfa591073a0e0ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
"""Add auto_info to endpoint dtmf_mode

Revision ID: 164abbd708c
Revises: 86bb1efa278d
Create Date: 2017-06-19 13:55:15.354706

"""

# revision identifiers, used by Alembic.
revision = '164abbd708c'
down_revision = 'd7983954dd96'

from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects.postgresql import ENUM

OLD_ENUM = ['rfc4733', 'inband', 'info', 'auto']
NEW_ENUM = ['rfc4733', 'inband', 'info', 'auto', 'auto_info']

old_type = sa.Enum(*OLD_ENUM, name='pjsip_dtmf_mode_values_v2')
new_type = sa.Enum(*NEW_ENUM, name='pjsip_dtmf_mode_values_v3')

def upgrade():
    context = op.get_context()

    # Upgrading to this revision WILL clear your directmedia values.
    if context.bind.dialect.name != 'postgresql':
        op.alter_column('ps_endpoints', 'dtmf_mode',
                        type_=new_type,
                        existing_type=old_type)
    else:
        enum = ENUM('rfc4733', 'inband', 'info', 'auto', 'auto_info',
                    name='pjsip_dtmf_mode_values_v3')
        enum.create(op.get_bind(), checkfirst=False)

        op.execute('ALTER TABLE ps_endpoints ALTER COLUMN dtmf_mode TYPE'
                   ' pjsip_dtmf_mode_values_v3 USING'
                   ' dtmf_mode::text::pjsip_dtmf_mode_values_v3')

        ENUM(name="pjsip_dtmf_mode_values_v2").drop(op.get_bind(), checkfirst=False)

def downgrade():
    context = op.get_context()

    if context.bind.dialect.name != 'postgresql':
        op.alter_column('ps_endpoints', 'dtmf_mode',
                        type_=old_type,
                        existing_type=new_type)
    else:
        enum = ENUM('rfc4733', 'inband', 'info', 'auto',
                    name='pjsip_dtmf_mode_values_v2')
        enum.create(op.get_bind(), checkfirst=False)

        op.execute('ALTER TABLE ps_endpoints ALTER COLUMN dtmf_mode TYPE'
                   ' pjsip_dtmf_mode_values_v2 USING'
                   ' dtmf_mode::text::pjsip_dtmf_mode_values_v2')

        ENUM(name="pjsip_dtmf_mode_values_v3").drop(op.get_bind(), checkfirst=False)