Asterisk - The Open Source Telephony Project GIT-master-f36a736
74dc751dfe8e_more_permission_boolean_columns.py
Go to the documentation of this file.
1"""more permission boolean columns
2
3Revision ID: 74dc751dfe8e
4Revises: bd335bae5d33
5Create Date: 2024-02-27 15:31:09.458313
6
7"""
8
9# revision identifiers, used by Alembic.
10revision = '74dc751dfe8e'
11down_revision = 'bd335bae5d33'
12
13import itertools
14import operator
15
16from alembic import op
17import sqlalchemy as sa
18from sqlalchemy import case, cast, or_, text
19from sqlalchemy.dialects.postgresql import ENUM
20from sqlalchemy.sql import table, column
21
22COLUMNS = [ ('ps_aors', 'authenticate_qualify'),
23 ('ps_aors', 'remove_existing'),
24 ('ps_aors', 'support_path'),
25 ('ps_asterisk_publications', 'device_state'),
26 ('ps_asterisk_publications', 'mailbox_state'),
27 ('ps_contacts', 'authenticate_qualify'),
28 ('ps_contacts', 'prune_on_boot'),
29 ('ps_endpoint_id_ips', 'srv_lookups'),
30 ('ps_endpoints', 'accept_multiple_sdp_answers'),
31 ('ps_endpoints', 'aggregate_mwi'),
32 ('ps_endpoints', 'allow_overlap'),
33 ('ps_endpoints', 'allow_subscribe'),
34 ('ps_endpoints', 'allow_transfer'),
35 ('ps_endpoints', 'asymmetric_rtp_codec'),
36 ('ps_endpoints', 'bind_rtp_to_media_address'),
37 ('ps_endpoints', 'bundle'),
38 ('ps_endpoints', 'direct_media'),
39 ('ps_endpoints', 'disable_direct_media_on_nat'),
40 ('ps_endpoints', 'dtls_auto_generate_cert'),
41 ('ps_endpoints', 'fax_detect'),
42 ('ps_endpoints', 'follow_early_media_fork'),
43 ('ps_endpoints', 'force_avp'),
44 ('ps_endpoints', 'force_rport'),
45 ('ps_endpoints', 'g726_non_standard'),
46 ('ps_endpoints', 'ice_support'),
47 ('ps_endpoints', 'inband_progress'),
48 ('ps_endpoints', 'media_encryption_optimistic'),
49 ('ps_endpoints', 'media_use_received_transport'),
50 ('ps_endpoints', 'moh_passthrough'),
51 ('ps_endpoints', 'notify_early_inuse_ringing'),
52 ('ps_endpoints', 'one_touch_recording'),
53 ('ps_endpoints', 'preferred_codec_only'),
54 ('ps_endpoints', 'refer_blind_progress'),
55 ('ps_endpoints', 'rewrite_contact'),
56 ('ps_endpoints', 'rpid_immediate'),
57 ('ps_endpoints', 'rtcp_mux'),
58 ('ps_endpoints', 'rtp_ipv6'),
59 ('ps_endpoints', 'rtp_symmetric'),
60 ('ps_endpoints', 'send_diversion'),
61 ('ps_endpoints', 'send_pai'),
62 ('ps_endpoints', 'send_rpid'),
63 ('ps_endpoints', 'srtp_tag_32'),
64 ('ps_endpoints', 'suppress_q850_reason_headers'),
65 ('ps_endpoints', 't38_udptl'),
66 ('ps_endpoints', 't38_udptl_ipv6'),
67 ('ps_endpoints', 't38_udptl_nat'),
68 ('ps_endpoints', 'trust_id_inbound'),
69 ('ps_endpoints', 'trust_id_outbound'),
70 ('ps_endpoints', 'use_avpf'),
71 ('ps_endpoints', 'use_ptime'),
72 ('ps_endpoints', 'user_eq_phone'),
73 ('ps_endpoints', 'webrtc'),
74 ('ps_globals', 'disable_multi_domain'),
75 ('ps_globals', 'ignore_uri_user_options'),
76 ('ps_globals', 'mwi_disable_initial_unsolicited'),
77 ('ps_outbound_publishes', 'multi_user'),
78 ('ps_registrations', 'auth_rejection_permanent'),
79 ('ps_registrations', 'line'),
80 ('ps_registrations', 'support_path'),
81 ('ps_resource_list', 'full_state'),
82 ('ps_subscription_persistence', 'prune_on_boot'),
83 ('ps_systems', 'accept_multiple_sdp_answers'),
84 ('ps_systems', 'compact_headers'),
85 ('ps_systems', 'disable_tcp_switch'),
86 ('ps_systems', 'follow_early_media_fork'),
87 ('ps_transports', 'allow_reload'),
88 ('ps_transports', 'allow_wildcard_certs'),
89 ('ps_transports', 'require_client_cert'),
90 ('ps_transports', 'symmetric_transport'),
91 ('ps_transports', 'verify_client'),
92 ('ps_transports', 'verify_server') ]
93
94YESNO_NAME = 'yesno_values'
95YESNO_VALUES = ['yes', 'no']
96
97AST_BOOL_NAME = 'ast_bool_values'
98AST_BOOL_VALUES = [ '0', '1',
99 'off', 'on',
100 'false', 'true',
101 'no', 'yes' ]
102
103yesno_values = ENUM(*YESNO_VALUES, name=YESNO_NAME, create_type=False)
104ast_bool_values = ENUM(*AST_BOOL_VALUES, name=AST_BOOL_NAME, create_type=False)
105
107 for table_name, column_list in itertools.groupby(COLUMNS, operator.itemgetter(0)):
108 with op.batch_alter_table(table_name) as batch_op:
109 for _, column_name in column_list:
110 batch_op.alter_column(column_name,
111 type_=ast_bool_values,
112 existing_type=yesno_values,
113 postgresql_using='"{}"::text::{}'.format(column_name, AST_BOOL_NAME))
114
116 for table_name, column_list in itertools.groupby(COLUMNS, operator.itemgetter(0)):
117 subject = table(table_name)
118 values_exprs = {}
119 for _, column_name in column_list:
120 subject.append_column(column(column_name))
121 values_exprs[column_name] = cast(
122 case((or_(subject.c[column_name] == text("'yes'"),
123 subject.c[column_name] == text("'1'"),
124 subject.c[column_name] == text("'on'"),
125 subject.c[column_name] == text("'true'")), text("'yes'")),
126 else_=text("'no'")),
127 ast_bool_values)
128
129 op.execute(
130 subject.update().values(values_exprs)
131 )
132
133 for table_name, column_list in itertools.groupby(COLUMNS, operator.itemgetter(0)):
134 with op.batch_alter_table(table_name) as batch_op:
135 for _, column_name in column_list:
136 batch_op.alter_column(column_name,
137 type_=yesno_values,
138 existing_type=ast_bool_values,
139 postgresql_using='"{}"::text::{}'.format(column_name, YESNO_NAME))
char * text
Definition: app_queue.c:1668
static char * table
Definition: cdr_odbc.c:55