Asterisk - The Open Source Telephony Project  21.4.1
9f3692b1654b_add_stir_shaken_profile_and_codec_.py
1 """Add Stir Shaken Profile and Codec Preference to ps endpoint
2 
3 Revision ID: 9f3692b1654b
4 Revises: 7197536bb68d
5 Create Date: 2022-08-17 11:20:56.433088
6 
7 """
8 
9 # revision identifiers, used by Alembic.
10 revision = '9f3692b1654b'
11 down_revision = '7197536bb68d'
12 
13 from alembic import op
14 import sqlalchemy as sa
15 from sqlalchemy.dialects.postgresql import ENUM
16 
17 PJSIP_INCOMING_CALL_OFFER_PREF_NAME ='pjsip_incoming_call_offer_pref_values'
18 PJSIP_INCOMING_CALL_OFFER_PREF_VALUES = ['local', 'local_first',
19  'remote', 'remote_first']
20 
21 PJSIP_OUTGOING_CALL_OFFER_PREF_NAME = 'pjsip_outgoing_call_offer_pref_values'
22 PJSIP_OUTGOING_CALL_OFFER_PREF_VALUES = ['local', 'local_merge', 'local_first',
23  'remote', 'remote_merge', 'remote_first']
24 
25 def upgrade():
26  context = op.get_context()
27 
28  if context.bind.dialect.name == 'postgresql':
29  enum_in = ENUM(*PJSIP_INCOMING_CALL_OFFER_PREF_VALUES, name=PJSIP_INCOMING_CALL_OFFER_PREF_NAME)
30  enum_out = ENUM(*PJSIP_OUTGOING_CALL_OFFER_PREF_VALUES, name=PJSIP_OUTGOING_CALL_OFFER_PREF_NAME)
31 
32  enum_in.create(op.get_bind(), checkfirst=False)
33  enum_out.create(op.get_bind(), checkfirst=False)
34 
35  op.add_column('ps_endpoints', sa.Column('incoming_call_offer_pref',
36  sa.Enum(*PJSIP_INCOMING_CALL_OFFER_PREF_VALUES, name=PJSIP_INCOMING_CALL_OFFER_PREF_NAME)))
37 
38  op.add_column('ps_endpoints', sa.Column('outgoing_call_offer_pref',
39  sa.Enum(*PJSIP_OUTGOING_CALL_OFFER_PREF_VALUES, name=PJSIP_OUTGOING_CALL_OFFER_PREF_NAME)))
40 
41  op.add_column('ps_endpoints', sa.Column('stir_shaken_profile', sa.String(80)))
42 
43 def downgrade():
44  context = op.get_context()
45 
46  if context.bind.dialect.name == 'mssql':
47  op.drop_constraint('ck_ps_endpoints_incoming_call_offer_pref_pjsip_incoming_call_offer_pref_values', 'ps_endpoints')
48  op.drop_constraint('ck_ps_endpoints_outgoing_call_offer_pref_pjsip_outgoing_call_offer_pref_values', 'ps_endpoints')
49 
50  op.drop_column('ps_endpoints', 'outgoing_call_offer_pref')
51  op.drop_column('ps_endpoints', 'incoming_call_offer_pref')
52  op.drop_column('ps_endpoints', 'stir_shaken_profile')
53 
54  enums = [PJSIP_INCOMING_CALL_OFFER_PREF_NAME, PJSIP_OUTGOING_CALL_OFFER_PREF_NAME]
55 
56  if context.bind.dialect.name == 'postgresql':
57  for e in enums:
58  ENUM(name=e).drop(op.get_bind(), checkfirst=False)