| 1 |
"""add pjsip google voice sip options |
| 2 |
|
| 3 |
Revision ID: 465f47f880be |
| 4 |
Revises: 7f85dd44c775 |
| 5 |
Create Date: 2018-09-25 17:26:12.892161 |
| 6 |
|
| 7 |
""" |
| 8 |
|
| 9 |
|
| 10 |
revision = '465f47f880be' |
| 11 |
down_revision = '7f85dd44c775' |
| 12 |
|
| 13 |
from alembic import op |
| 14 |
from sqlalchemy.dialects.postgresql import ENUM |
| 15 |
import sqlalchemy as sa |
| 16 |
|
| 17 |
AST_BOOL_NAME = 'ast_bool_values' |
| 18 |
|
| 19 |
|
| 20 |
AST_BOOL_VALUES = [ '0', '1', |
| 21 |
'off', 'on', |
| 22 |
'false', 'true', |
| 23 |
'no', 'yes' ] |
| 24 |
|
| 25 |
PJSIP_TRANSPORT_PROTOCOL_OLD_NAME = 'pjsip_transport_protocol_values' |
| 26 |
PJSIP_TRANSPORT_PROTOCOL_NEW_NAME = 'pjsip_transport_protocol_values_v2' |
| 27 |
|
| 28 |
PJSIP_TRANSPORT_PROTOCOL_OLD_VALUES = ['udp', 'tcp', 'tls', 'ws', 'wss'] |
| 29 |
PJSIP_TRANSPORT_PROTOCOL_NEW_VALUES = ['udp', 'tcp', 'tls', 'ws', 'wss', 'flow'] |
| 30 |
|
| 31 |
PJSIP_TRANSPORT_PROTOCOL_OLD_TYPE = sa.Enum(*PJSIP_TRANSPORT_PROTOCOL_OLD_VALUES, |
| 32 |
name=PJSIP_TRANSPORT_PROTOCOL_OLD_NAME) |
| 33 |
PJSIP_TRANSPORT_PROTOCOL_NEW_TYPE = sa.Enum(*PJSIP_TRANSPORT_PROTOCOL_NEW_VALUES, |
| 34 |
name=PJSIP_TRANSPORT_PROTOCOL_NEW_NAME) |
| 35 |
|
| 36 |
PJSIP_AUTH_TYPE_OLD_NAME = 'pjsip_auth_type_values' |
| 37 |
PJSIP_AUTH_TYPE_NEW_NAME = 'pjsip_auth_type_values_v2' |
| 38 |
|
| 39 |
PJSIP_AUTH_TYPE_OLD_VALUES = ['md5', 'userpass'] |
| 40 |
PJSIP_AUTH_TYPE_NEW_VALUES = ['md5', 'userpass', 'google_oauth'] |
| 41 |
|
| 42 |
PJSIP_AUTH_TYPE_OLD_TYPE = sa.Enum(*PJSIP_AUTH_TYPE_OLD_VALUES, |
| 43 |
name=PJSIP_AUTH_TYPE_OLD_NAME) |
| 44 |
PJSIP_AUTH_TYPE_NEW_TYPE = sa.Enum(*PJSIP_AUTH_TYPE_NEW_VALUES, |
| 45 |
name=PJSIP_AUTH_TYPE_NEW_NAME) |
| 46 |
|
| 47 |
|
| 48 |
def upgrade(): |
| 49 |
if op.get_context().bind.dialect.name == 'postgresql': |
| 50 |
enum = PJSIP_TRANSPORT_PROTOCOL_NEW_TYPE |
| 51 |
enum.create(op.get_bind(), checkfirst=False) |
| 52 |
op.execute('ALTER TABLE ps_transports ALTER COLUMN protocol TYPE' |
| 53 |
' ' + PJSIP_TRANSPORT_PROTOCOL_NEW_NAME + ' USING' |
| 54 |
' protocol::text::' + PJSIP_TRANSPORT_PROTOCOL_NEW_NAME) |
| 55 |
ENUM(name=PJSIP_TRANSPORT_PROTOCOL_OLD_NAME).drop(op.get_bind(), checkfirst=False) |
| 56 |
|
| 57 |
enum = PJSIP_AUTH_TYPE_NEW_TYPE |
| 58 |
enum.create(op.get_bind(), checkfirst=False) |
| 59 |
op.execute('ALTER TABLE ps_auths ALTER COLUMN auth_type TYPE' |
| 60 |
' ' + PJSIP_AUTH_TYPE_NEW_NAME + ' USING' |
| 61 |
' auth_type::text::' + PJSIP_AUTH_TYPE_NEW_NAME) |
| 62 |
ENUM(name=PJSIP_AUTH_TYPE_OLD_NAME).drop(op.get_bind(), checkfirst=False) |
| 63 |
else: |
| 64 |
op.alter_column('ps_transports', 'protocol', |
| 65 |
type_=PJSIP_TRANSPORT_PROTOCOL_NEW_TYPE, |
| 66 |
existing_type=PJSIP_TRANSPORT_PROTOCOL_OLD_TYPE) |
| 67 |
op.alter_column('ps_auths', 'auth_type', |
| 68 |
type_=PJSIP_AUTH_TYPE_NEW_TYPE, |
| 69 |
existing_type=PJSIP_AUTH_TYPE_OLD_TYPE) |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
ast_bool_values = ENUM(*AST_BOOL_VALUES, name=AST_BOOL_NAME, create_type=False) |
| 74 |
|
| 75 |
op.add_column('ps_registrations', sa.Column('support_outbound', ast_bool_values)) |
| 76 |
op.add_column('ps_registrations', sa.Column('contact_header_params', sa.String(255))) |
| 77 |
|
| 78 |
op.add_column('ps_auths', sa.Column('refresh_token', sa.String(255))) |
| 79 |
op.add_column('ps_auths', sa.Column('oauth_clientid', sa.String(255))) |
| 80 |
op.add_column('ps_auths', sa.Column('oauth_secret', sa.String(255))) |
| 81 |
|
| 82 |
def downgrade(): |
| 83 |
|
| 84 |
|
| 85 |
op.execute("UPDATE ps_transports SET protocol='udp' WHERE protocol='flow'") |
| 86 |
op.execute("UPDATE ps_auths SET auth_type='userpass' WHERE auth_type='google_oauth'") |
| 87 |
|
| 88 |
if op.get_context().bind.dialect.name == 'postgresql': |
| 89 |
enum = PJSIP_TRANSPORT_PROTOCOL_OLD_TYPE |
| 90 |
enum.create(op.get_bind(), checkfirst=False) |
| 91 |
op.execute('ALTER TABLE ps_transports ALTER COLUMN protocol TYPE' |
| 92 |
' ' + PJSIP_TRANSPORT_PROTOCOL_OLD_NAME + ' USING' |
| 93 |
' protocol::text::' + PJSIP_TRANSPORT_PROTOCOL_OLD_NAME) |
| 94 |
ENUM(name=PJSIP_TRANSPORT_PROTOCOL_NEW_NAME).drop(op.get_bind(), checkfirst=False) |
| 95 |
|
| 96 |
enum = PJSIP_AUTH_TYPE_OLD_TYPE |
| 97 |
enum.create(op.get_bind(), checkfirst=False) |
| 98 |
op.execute('ALTER TABLE ps_auths ALTER COLUMN auth_type TYPE' |
| 99 |
' ' + PJSIP_AUTH_TYPE_OLD_NAME + ' USING' |
| 100 |
' auth_type::text::' + PJSIP_AUTH_TYPE_OLD_NAME) |
| 101 |
ENUM(name=PJSIP_AUTH_TYPE_NEW_NAME).drop(op.get_bind(), checkfirst=False) |
| 102 |
else: |
| 103 |
op.alter_column('ps_transports', 'protocol', |
| 104 |
type_=PJSIP_TRANSPORT_PROTOCOL_OLD_TYPE, |
| 105 |
existing_type=PJSIP_TRANSPORT_PROTOCOL_NEW_TYPE) |
| 106 |
op.alter_column('ps_auths', 'auth_type', |
| 107 |
type_=PJSIP_AUTH_TYPE_OLD_TYPE, |
| 108 |
existing_type=PJSIP_AUTH_TYPE_NEW_TYPE) |
| 109 |
|
| 110 |
op.drop_column('ps_registrations', 'support_outbound') |
| 111 |
op.drop_column('ps_registrations', 'contact_header_params') |
| 112 |
|
| 113 |
op.drop_column('ps_auths', 'refresh_token') |
| 114 |
op.drop_column('ps_auths', 'oauth_clientid') |
| 115 |
op.drop_column('ps_auths', 'oauth_secret') |