Asterisk - The Open Source Telephony Project GIT-master-57e2743
Loading...
Searching...
No Matches
2b45fd748a4f_add_geolocation_tables.py
Go to the documentation of this file.
1"""Add geolocation tables
2
3Revision ID: 2b45fd748a4f
4Revises: 2285f2ace275
5Create Date: 2026-08-31 09:56:07.441814
6
7"""
8
9# revision identifiers, used by Alembic.
10revision = '2b45fd748a4f'
11down_revision = '2285f2ace275'
12
13from alembic import op
14import sqlalchemy as sa
15from sqlalchemy.dialects.postgresql import ENUM
16
17AST_BOOL_NAME = 'ast_bool_values'
18AST_BOOL_VALUES = [ '0', '1',
19 'off', 'on',
20 'false', 'true',
21 'no', 'yes' ]
22
23GEOLOC_LOCATION_FORMAT_NAME ='geoloc_location_format_values'
24GEOLOC_LOCATION_FORMAT_VALUES = ['<none>','civicAddress','GML','URI']
25
26GEOLOC_PROFILE_PIDF_ELEMENT_NAME = 'geoloc_profile_pidf_element_values'
27GEOLOC_PROFILE_PIDF_ELEMENT_VALUES = ['<none>','tuple', 'device', 'person']
28
29GEOLOC_PROFILE_PRECEDENCE_NAME = 'geoloc_profile_precedence_values'
30GEOLOC_PROFILE_PRECEDENCE_VALUES = ['prefer_incoming', 'prefer_config', 'discard_incoming','discard_config']
31
32def upgrade():
33 enum_format = sa.Enum(*GEOLOC_LOCATION_FORMAT_VALUES, name=GEOLOC_LOCATION_FORMAT_NAME)
34 enum_pidf_element = sa.Enum(*GEOLOC_PROFILE_PIDF_ELEMENT_VALUES, name=GEOLOC_PROFILE_PIDF_ELEMENT_NAME)
35 enum_precedence = sa.Enum(*GEOLOC_PROFILE_PRECEDENCE_VALUES, name=GEOLOC_PROFILE_PRECEDENCE_NAME)
36 ast_bool_values = ENUM(*AST_BOOL_VALUES, name=AST_BOOL_NAME, create_type=False)
37
38#
39# The use of the 'TEXT' column type instead of 'String' for the string data columns
40# is deliberate. Many of the columns can be very long (>= 2048) and if defined as
41# 'String(n)' would add up to more than the maximum row size (65535) for MySql.
42#
43 op.create_table(
44 'geoloc_location',
45 sa.Column('id', sa.String(80), nullable=False, primary_key=True),
46 sa.Column('format', enum_format, nullable=True),
47 sa.Column('location_info', sa.TEXT, nullable=True),
48 sa.Column('location_source', sa.TEXT, nullable=True),
49 sa.Column('confidence', sa.TEXT, nullable=True),
50 sa.Column('method', sa.TEXT, nullable=True)
51 )
52
53 op.create_table(
54 'geoloc_profile',
55 sa.Column('id', sa.String(80), nullable=False, primary_key=True),
56 sa.Column('pidf_element', enum_pidf_element, nullable=True),
57 sa.Column('pidf_element_id', sa.TEXT, nullable=True),
58 sa.Column('device_id', sa.TEXT, nullable=True),
59 sa.Column('location_reference', sa.TEXT, nullable=True),
60 sa.Column('location_info_refinement', sa.TEXT, nullable=True),
61 sa.Column('location_variables', sa.TEXT, nullable=True),
62 sa.Column('usage_rules', sa.TEXT, nullable=True),
63 sa.Column('notes', sa.TEXT, nullable=True),
64 sa.Column('allow_routing_use', ast_bool_values),
65 sa.Column('suppress_empty_ca_elements', ast_bool_values),
66 sa.Column('profile_precedence', enum_precedence, nullable=True),
67 sa.Column('format', enum_format, nullable=True),
68 sa.Column('location_info', sa.TEXT, nullable=True),
69 sa.Column('location_source', sa.TEXT, nullable=True),
70 sa.Column('confidence', sa.TEXT, nullable=True),
71 sa.Column('method', sa.TEXT, nullable=True)
72 )
73
75 op.drop_table('geoloc_location')
76 op.drop_table('geoloc_profile')
77 sa.Enum(*GEOLOC_LOCATION_FORMAT_VALUES, name=GEOLOC_LOCATION_FORMAT_NAME).drop(op.get_bind(), checkfirst=True)
78 sa.Enum(*GEOLOC_PROFILE_PIDF_ELEMENT_VALUES, name=GEOLOC_PROFILE_PIDF_ELEMENT_NAME).drop(op.get_bind(), checkfirst=True)
79 sa.Enum(*GEOLOC_PROFILE_PRECEDENCE_VALUES, name=GEOLOC_PROFILE_PRECEDENCE_NAME).drop(op.get_bind(), checkfirst=True)