Asterisk - The Open Source Telephony Project  21.4.1
539f68bede2c_add_peer_supported_to_100rel.py
1 """Add peer_supported to 100rel
2 
3 Revision ID: 539f68bede2c
4 Revises: 9f3692b1654b
5 Create Date: 2022-08-10 09:36:16.576049
6 
7 """
8 
9 # revision identifiers, used by Alembic.
10 revision = '539f68bede2c'
11 down_revision = '9f3692b1654b'
12 
13 from alembic import op
14 from sqlalchemy.dialects.postgresql import ENUM
15 import sqlalchemy as sa
16 
17 
18 OLD_ENUM = ['no', 'required', 'yes']
19 NEW_ENUM = ['no', 'required', 'peer_supported', 'yes']
20 
21 old_type = sa.Enum(*OLD_ENUM, name='pjsip_100rel_values')
22 new_type = sa.Enum(*NEW_ENUM, name='pjsip_100rel_values_v2')
23 
24 def upgrade():
25  context = op.get_context()
26 
27  # Upgrading to this revision WILL clear your directmedia values.
28  if context.bind.dialect.name != 'postgresql':
29  op.alter_column('ps_endpoints', '100rel',
30  type_=new_type,
31  existing_type=old_type)
32  else:
33  enum = ENUM(*NEW_ENUM, name='pjsip_100rel_values_v2')
34  enum.create(op.get_bind(), checkfirst=False)
35 
36  op.execute('ALTER TABLE ps_endpoints ALTER COLUMN "100rel" TYPE'
37  ' pjsip_100rel_values_v2 USING'
38  ' "100rel"::text::pjsip_100rel_values_v2')
39 
40  ENUM(name="pjsip_100rel_values").drop(op.get_bind(), checkfirst=False)
41 
42 def downgrade():
43  context = op.get_context()
44 
45  if context.bind.dialect.name != 'postgresql':
46  op.alter_column('ps_endpoints', '100rel',
47  type_=old_type,
48  existing_type=new_type)
49  else:
50  enum = ENUM(*OLD_ENUM, name='pjsip_100rel_values')
51  enum.create(op.get_bind(), checkfirst=False)
52 
53  op.execute('ALTER TABLE ps_endpoints ALTER COLUMN "100rel" TYPE'
54  ' pjsip_100rel_values USING'
55  ' "100rel"::text::pjsip_100rel_values')
56 
57  ENUM(name="pjsip_100rel_values_v2").drop(op.get_bind(), checkfirst=False)