Asterisk - The Open Source Telephony Project GIT-master-abe0018
539f68bede2c_add_peer_supported_to_100rel.py
Go to the documentation of this file.
1"""Add peer_supported to 100rel
2
3Revision ID: 539f68bede2c
4Revises: 9f3692b1654b
5Create Date: 2022-08-10 09:36:16.576049
6
7"""
8
9# revision identifiers, used by Alembic.
10revision = '539f68bede2c'
11down_revision = '9f3692b1654b'
12
13from alembic import op
14from sqlalchemy.dialects.postgresql import ENUM
15import sqlalchemy as sa
16
17
18OLD_ENUM = ['no', 'required', 'yes']
19NEW_ENUM = ['no', 'required', 'peer_supported', 'yes']
20
21old_type = sa.Enum(*OLD_ENUM, name='pjsip_100rel_values')
22new_type = sa.Enum(*NEW_ENUM, name='pjsip_100rel_values_v2')
23
24def 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
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)