Asterisk - The Open Source Telephony Project GIT-master-545c459
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 = ENUM(*GEOLOC_LOCATION_FORMAT_VALUES, name=GEOLOC_LOCATION_FORMAT_NAME, checkfirst=True)
34 enum_pidf_element = ENUM(*GEOLOC_PROFILE_PIDF_ELEMENT_VALUES, name=GEOLOC_PROFILE_PIDF_ELEMENT_NAME, checkfirst=True)
35 enum_precedence = ENUM(*GEOLOC_PROFILE_PRECEDENCE_VALUES, name=GEOLOC_PROFILE_PRECEDENCE_NAME, checkfirst=True)
36 ast_bool_values = ENUM(*AST_BOOL_VALUES, name=AST_BOOL_NAME, create_type=False)
37
38 op.create_table(
39 'geoloc_location',
40 sa.Column('id', sa.String(80), nullable=False, primary_key=True),
41 sa.Column('format', enum_format, nullable=True),
42 sa.Column('location_info', sa.String(2048), nullable=True),
43 sa.Column('location_source', sa.String(1024), nullable=True),
44 sa.Column('confidence', sa.String(2048), nullable=True),
45 sa.Column('method', sa.String(2048), nullable=True)
46 )
47
48 op.create_table(
49 'geoloc_profile',
50 sa.Column('id', sa.String(80), nullable=False, primary_key=True),
51 sa.Column('pidf_element', enum_pidf_element, nullable=True),
52 sa.Column('pidf_element_id', sa.String(80), nullable=True),
53 sa.Column('device_id', sa.String(1024), nullable=True),
54 sa.Column('location_reference', sa.String(80), nullable=True),
55 sa.Column('location_info_refinement', sa.String(2048), nullable=True),
56 sa.Column('location_variables', sa.String(2048), nullable=True),
57 sa.Column('usage_rules', sa.String(2048), nullable=True),
58 sa.Column('notes', sa.String(2048), nullable=True),
59 sa.Column('allow_routing_use', ast_bool_values),
60 sa.Column('suppress_empty_ca_elements', ast_bool_values),
61 sa.Column('profile_precedence', enum_precedence, nullable=True),
62 sa.Column('format', enum_format, nullable=True),
63 sa.Column('location_info', sa.String(2048), nullable=True),
64 sa.Column('location_source', sa.String(1024), nullable=True),
65 sa.Column('confidence', sa.String(2048), nullable=True),
66 sa.Column('method', sa.String(2048), nullable=True)
67 )
68
70 op.drop_table('geoloc_location')
71 op.drop_table('geoloc_profile')
72 sa.Enum(*GEOLOC_LOCATION_FORMAT_VALUES, name=GEOLOC_LOCATION_FORMAT_NAME).drop(op.get_bind(), checkfirst=True)
73 sa.Enum(*GEOLOC_PROFILE_PIDF_ELEMENT_VALUES, name=GEOLOC_PROFILE_PIDF_ELEMENT_NAME).drop(op.get_bind(), checkfirst=True)
74 sa.Enum(*GEOLOC_PROFILE_PRECEDENCE_VALUES, name=GEOLOC_PROFILE_PRECEDENCE_NAME).drop(op.get_bind(), checkfirst=True)