Asterisk - The Open Source Telephony Project GIT-master-f36a736
52798ad97bdf_add_pjsip_identify_by_header.py
Go to the documentation of this file.
1"""add pjsip identify by header
2
3Revision ID: 52798ad97bdf
4Revises: e2f04d309071
5Create Date: 2018-01-08 12:16:02.782277
6
7"""
8
9# revision identifiers, used by Alembic.
10revision = '52798ad97bdf'
11down_revision = 'e2f04d309071'
12
13from alembic import op
14import sqlalchemy as sa
15
16
17def column_upgrade(table_name, column_name, enum_name):
18 if op.get_context().bind.dialect.name != 'postgresql':
19 if op.get_context().bind.dialect.name == 'mssql':
20 op.drop_constraint('ck_ps_endpoints_identify_by_pjsip_identify_by_values',
21 table_name)
22 op.alter_column(table_name, column_name, type_=sa.String(80))
23 return
24
25 # Postgres requires a few more steps
26 op.execute('ALTER TABLE ' + table_name + ' ALTER COLUMN ' + column_name +
27 ' TYPE varchar(80) USING identify_by::text::' + enum_name)
28
29 op.execute('DROP TYPE ' + enum_name)
30
31
32def column_downgrade(table_name, column_name, enum_name, enum_values):
33 if op.get_context().bind.dialect.name != 'postgresql':
34 op.alter_column(table_name, column_name,
35 type_=sa.Enum(*enum_values, name=enum_name))
36 return
37
38 # Postgres requires a few more steps
39 updated = sa.Enum(*enum_values, name=enum_name)
40 updated.create(op.get_bind(), checkfirst=False)
41
42 op.execute('ALTER TABLE ' + table_name + ' ALTER COLUMN ' + column_name +
43 ' TYPE ' + enum_name + ' USING identify_by::text::' + enum_name)
44
45
46def upgrade():
47 # The ps_endpoints identify_by column has always been a comma separated
48 # list of enum values. This is better represented as a string anyway to
49 # avoid database compatibility issues. Also future changes are likely
50 # to allow loadable endpoint identifier names and negating fixed enum
51 # benefits.
52 column_upgrade('ps_endpoints', 'identify_by', 'pjsip_identify_by_values')
53
54
56 column_downgrade('ps_endpoints', 'identify_by', 'pjsip_identify_by_values',
57 ['username', 'auth_username', 'ip'])
def column_downgrade(table_name, column_name, enum_name, enum_values)