Asterisk - The Open Source Telephony Project  18.5.0
2fc7930b41b3_add_pjsip_endpoint_options_for_12_1.py
Go to the documentation of this file.
1 """Add/Update tables for pjsip
2 
3 Revision ID: 2fc7930b41b3
4 Revises: 581a4264e537
5 Create Date: 2014-01-14 09:23:53.923454
6 
7 """
8 
9 # revision identifiers, used by Alembic.
10 revision = '2fc7930b41b3'
11 down_revision = '581a4264e537'
12 
13 from alembic import op
14 from alembic import context
15 import sqlalchemy as sa
16 from sqlalchemy.dialects.postgresql import ENUM
17 
18 YESNO_NAME = 'yesno_values'
19 YESNO_VALUES = ['yes', 'no']
20 
21 PJSIP_REDIRECT_METHOD_NAME = 'pjsip_redirect_method_values'
22 PJSIP_REDIRECT_METHOD_VALUES = ['user', 'uri_core', 'uri_pjsip']
23 
24 PJSIP_TRANSPORT_METHOD_NAME = 'pjsip_transport_method_values'
25 PJSIP_TRANSPORT_METHOD_VALUES = ['default', 'unspecified', 'tlsv1', 'sslv2',
26  'sslv3', 'sslv23']
27 
28 PJSIP_TRANSPORT_PROTOCOL_NAME = 'pjsip_transport_protocol_values'
29 PJSIP_TRANSPORT_PROTOCOL_VALUES = ['udp', 'tcp', 'tls', 'ws', 'wss']
30 
31 def upgrade():
32  ############################# Enums ##############################
33 
34  # yesno_values have already been created, so use postgres enum object
35  # type to get around "already created" issue - works okay with mysql
36  yesno_values = ENUM(*YESNO_VALUES, name=YESNO_NAME, create_type=False)
37 
38  # for some reason when using 'add_column' if you don't create the enum
39  # first it will think it already exists and fail
40  pjsip_redirect_method_values = sa.Enum(
41  *PJSIP_REDIRECT_METHOD_VALUES, name=PJSIP_REDIRECT_METHOD_NAME)
42  check = False if context.is_offline_mode() else True
43  pjsip_redirect_method_values.create(op.get_bind(), checkfirst=check)
44 
45  pjsip_transport_method_values = sa.Enum(
46  *PJSIP_TRANSPORT_METHOD_VALUES, name=PJSIP_TRANSPORT_METHOD_NAME)
47 
48  pjsip_transport_protocol_values = sa.Enum(
49  *PJSIP_TRANSPORT_PROTOCOL_VALUES, name=PJSIP_TRANSPORT_PROTOCOL_NAME)
50 
51  ######################### create tables ##########################
52 
53  op.create_table(
54  'ps_systems',
55  sa.Column('id', sa.String(40), nullable=False, unique=True),
56  sa.Column('timer_t1', sa.Integer),
57  sa.Column('timer_b', sa.Integer),
58  sa.Column('compact_headers', yesno_values),
59  sa.Column('threadpool_initial_size', sa.Integer),
60  sa.Column('threadpool_auto_increment', sa.Integer),
61  sa.Column('threadpool_idle_timeout', sa.Integer),
62  sa.Column('threadpool_max_size', sa.Integer),
63  )
64 
65  op.create_index('ps_systems_id', 'ps_systems', ['id'])
66 
67  op.create_table(
68  'ps_globals',
69  sa.Column('id', sa.String(40), nullable=False, unique=True),
70  sa.Column('max_forwards', sa.Integer),
71  sa.Column('user_agent', sa.String(40)),
72  sa.Column('default_outbound_endpoint', sa.String(40)),
73  )
74 
75  op.create_index('ps_globals_id', 'ps_globals', ['id'])
76 
77  op.create_table(
78  'ps_transports',
79  sa.Column('id', sa.String(40), nullable=False, unique=True),
80  sa.Column('async_operations', sa.Integer),
81  sa.Column('bind', sa.String(40)),
82  sa.Column('ca_list_file', sa.String(200)),
83  sa.Column('cert_file', sa.String(200)),
84  sa.Column('cipher', sa.String(200)),
85  sa.Column('domain', sa.String(40)),
86  sa.Column('external_media_address', sa.String(40)),
87  sa.Column('external_signaling_address', sa.String(40)),
88  sa.Column('external_signaling_port', sa.Integer),
89  sa.Column('method', pjsip_transport_method_values),
90  sa.Column('local_net', sa.String(40)),
91  sa.Column('password', sa.String(40)),
92  sa.Column('priv_key_file', sa.String(200)),
93  sa.Column('protocol', pjsip_transport_protocol_values),
94  sa.Column('require_client_cert', yesno_values),
95  sa.Column('verify_client', yesno_values),
96  sa.Column('verifiy_server', yesno_values),
97  sa.Column('tos', yesno_values),
98  sa.Column('cos', yesno_values),
99  )
100 
101  op.create_index('ps_transports_id', 'ps_transports', ['id'])
102 
103  op.create_table(
104  'ps_registrations',
105  sa.Column('id', sa.String(40), nullable=False, unique=True),
106  sa.Column('auth_rejection_permanent', yesno_values),
107  sa.Column('client_uri', sa.String(40)),
108  sa.Column('contact_user', sa.String(40)),
109  sa.Column('expiration', sa.Integer),
110  sa.Column('max_retries', sa.Integer),
111  sa.Column('outbound_auth', sa.String(40)),
112  sa.Column('outbound_proxy', sa.String(40)),
113  sa.Column('retry_interval', sa.Integer),
114  sa.Column('forbidden_retry_interval', sa.Integer),
115  sa.Column('server_uri', sa.String(40)),
116  sa.Column('transport', sa.String(40)),
117  sa.Column('support_path', yesno_values),
118  )
119 
120  op.create_index('ps_registrations_id', 'ps_registrations', ['id'])
121 
122  ########################## add columns ###########################
123  # new columns for endpoints
124  op.add_column('ps_endpoints', sa.Column('media_address', sa.String(40)))
125  op.add_column('ps_endpoints', sa.Column('redirect_method',
126  pjsip_redirect_method_values))
127  op.add_column('ps_endpoints', sa.Column('set_var', sa.Text()))
128 
129  # rename mwi_fromuser to mwi_from_user
130  op.alter_column('ps_endpoints', 'mwi_fromuser',
131  new_column_name='mwi_from_user', existing_type=sa.String(40))
132 
133  # new columns for contacts
134  op.add_column('ps_contacts', sa.Column('outbound_proxy', sa.String(40)))
135  op.add_column('ps_contacts', sa.Column('path', sa.Text()))
136 
137  # new columns for aors
138  op.add_column('ps_aors', sa.Column('maximum_expiration', sa.Integer))
139  op.add_column('ps_aors', sa.Column('outbound_proxy', sa.String(40)))
140  op.add_column('ps_aors', sa.Column('support_path', yesno_values))
141 
142 def downgrade():
143  ########################## drop columns ##########################
144 
145  if op.get_context().bind.dialect.name == 'mssql':
146  op.drop_constraint('ck_ps_aors_support_path_yesno_values', 'ps_aors')
147  op.drop_column('ps_aors', 'support_path')
148  op.drop_column('ps_aors', 'outbound_proxy')
149  op.drop_column('ps_aors', 'maximum_expiration')
150 
151  op.drop_column('ps_contacts', 'path')
152  op.drop_column('ps_contacts', 'outbound_proxy')
153 
154  op.alter_column('ps_endpoints', 'mwi_from_user',
155  new_column_name='mwi_fromuser', existing_type=sa.String(40))
156 
157  op.drop_column('ps_endpoints', 'set_var')
158  if op.get_context().bind.dialect.name == 'mssql':
159  op.drop_constraint('ck_ps_endpoints_redirect_method_pjsip_redirect_method_values', 'ps_endpoints')
160  op.drop_column('ps_endpoints', 'redirect_method')
161  op.drop_column('ps_endpoints', 'media_address')
162 
163  ########################## drop tables ###########################
164 
165  op.drop_table('ps_registrations')
166  op.drop_table('ps_transports')
167  op.drop_table('ps_globals')
168  op.drop_table('ps_systems')
169 
170  ########################## drop enums ############################
171 
172  sa.Enum(name=PJSIP_TRANSPORT_PROTOCOL_NAME).drop(
173  op.get_bind(), checkfirst=False)
174  sa.Enum(name=PJSIP_TRANSPORT_METHOD_NAME).drop(
175  op.get_bind(), checkfirst=False)
176  sa.Enum(name=PJSIP_REDIRECT_METHOD_NAME).drop(
177  op.get_bind(), checkfirst=False)