Asterisk - The Open Source Telephony Project GIT-master-f36a736
37a5332640e2_update_pjsip_tls_method_list.py
Go to the documentation of this file.
1"""update pjsip tls method list
2
3Revision ID: 37a5332640e2
4Revises: dac2b4c328b8
5Create Date: 2023-11-14 18:02:18.857452
6
7"""
8
9# revision identifiers, used by Alembic.
10revision = '37a5332640e2'
11down_revision = 'dac2b4c328b8'
12
13from alembic import op
14from sqlalchemy.dialects.postgresql import ENUM
15import sqlalchemy as sa
16
17PJSIP_TRANSPORT_METHOD_OLD_NAME = 'pjsip_transport_method_values'
18PJSIP_TRANSPORT_METHOD_NEW_NAME = 'pjsip_transport_method_values_v2'
19
20PJSIP_TRANSPORT_METHOD_OLD_VALUES = ['default', 'unspecified', 'tlsv1', 'sslv2',
21 'sslv3', 'sslv23']
22PJSIP_TRANSPORT_METHOD_NEW_VALUES = ['default', 'unspecified',
23 'tlsv1', 'tlsv1_1', 'tlsv1_2', 'tlsv1_3',
24 'sslv2', 'sslv23', 'sslv3']
25
26PJSIP_TRANSPORT_METHOD_OLD_TYPE = sa.Enum(*PJSIP_TRANSPORT_METHOD_OLD_VALUES,
27 name=PJSIP_TRANSPORT_METHOD_OLD_NAME)
28PJSIP_TRANSPORT_METHOD_NEW_TYPE = sa.Enum(*PJSIP_TRANSPORT_METHOD_NEW_VALUES,
29 name=PJSIP_TRANSPORT_METHOD_NEW_NAME)
30def upgrade():
31 if op.get_context().bind.dialect.name == 'postgresql':
32 enum = PJSIP_TRANSPORT_METHOD_NEW_TYPE
33 enum.create(op.get_bind(), checkfirst=False)
34
35 op.alter_column('ps_transports', 'method',
36 type_=PJSIP_TRANSPORT_METHOD_NEW_TYPE,
37 existing_type=PJSIP_TRANSPORT_METHOD_OLD_TYPE,
38 postgresql_using='method::text::' + PJSIP_TRANSPORT_METHOD_NEW_NAME)
39
40 if op.get_context().bind.dialect.name == 'postgresql':
41 ENUM(name=PJSIP_TRANSPORT_METHOD_OLD_NAME).drop(op.get_bind(), checkfirst=False)
42
44 # First we need to ensure that columns are not using the enum values
45 # that are going away.
46 op.execute("UPDATE ps_transports SET method = 'tlsv1' WHERE method IN ('tlsv1_1', 'tlsv1_2', 'tlsv1_3')")
47
48 if op.get_context().bind.dialect.name == 'postgresql':
49 enum = PJSIP_TRANSPORT_METHOD_OLD_TYPE
50 enum.create(op.get_bind(), checkfirst=False)
51
52 op.alter_column('ps_transports', 'method',
53 type_=PJSIP_TRANSPORT_METHOD_OLD_TYPE,
54 existing_type=PJSIP_TRANSPORT_METHOD_NEW_TYPE,
55 postgresql_using='method::text::' + PJSIP_TRANSPORT_METHOD_OLD_NAME)
56
57 if op.get_context().bind.dialect.name == 'postgresql':
58 ENUM(name=PJSIP_TRANSPORT_METHOD_NEW_NAME).drop(op.get_bind(), checkfirst=False)