[asterisk-commits] alembic: Add support for MS-SQL (asterisk[13])

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Sep 11 06:39:29 CDT 2017


Jenkins2 has submitted this change and it was merged. ( https://gerrit.asterisk.org/6459 )

Change subject: alembic: Add support for MS-SQL
......................................................................

alembic: Add support for MS-SQL

MS-SQL has no native Enum-type support and therefore
needs to work with constraints.
Since these constraints need unique names the suggested approach
referenced in the following alembic documentation has been applied:
http://bit.ly/2x9r8pb

ASTERISK-27255 #close

Change-Id: I4a399ba3eed41a33ce8cb294968ad340221580ee
---
M contrib/ast-db-manage/config/versions/15db7b91a97a_add_rtcp_mux.py
M contrib/ast-db-manage/config/versions/23530d604b96_add_rpid_immediate.py
M contrib/ast-db-manage/config/versions/26d7f3bf0fa5_add_bind_rtp_to_media_address_to_pjsip.py
M contrib/ast-db-manage/config/versions/28ab27a7826d_add_srv_lookups_to_identify.py
M contrib/ast-db-manage/config/versions/28b8e71e541f_add_g726_non_standard.py
M contrib/ast-db-manage/config/versions/2fc7930b41b3_add_pjsip_endpoint_options_for_12_1.py
M contrib/ast-db-manage/config/versions/371a3bf4143e_add_user_eq_phone_option_to_pjsip.py
M contrib/ast-db-manage/config/versions/3772f8f828da_update_identify_by.py
M contrib/ast-db-manage/config/versions/3bcc0b5bc2c9_add_allow_reload_to_ps_transports.py
M contrib/ast-db-manage/config/versions/4468b4a91372_add_pjsip_asymmetric_rtp_codec.py
M contrib/ast-db-manage/config/versions/4c573e7135bd_fix_tos_field_types.py
M contrib/ast-db-manage/config/versions/5139253c0423_make_q_member_uniqueid_autoinc.py
M contrib/ast-db-manage/config/versions/51f8cb66540e_add_further_dtls_options.py
M contrib/ast-db-manage/config/versions/5950038a6ead_fix_pjsip_verifiy_typo.py
M contrib/ast-db-manage/config/versions/837aa67461fb_ps_contacts_add_authenticate_qualify.py
M contrib/ast-db-manage/config/versions/86bb1efa278d_add_ps_endpoints_refer_blind_progress.py
M contrib/ast-db-manage/config/versions/8d478ab86e29_pjsip_add_disable_multi_domain.py
M contrib/ast-db-manage/config/versions/8fce4c573e15_add_pjsip_allow_overlap.py
M contrib/ast-db-manage/config/versions/a6ef36f1309_ps_globals_add_ignore_uri_user_options.py
M contrib/ast-db-manage/config/versions/b83645976fdd_add_dtls_fingerprint_to_ps_endpoints.py
M contrib/ast-db-manage/config/versions/c7a44a5a0851_pjsip_add_global_mwi_options.py
M contrib/ast-db-manage/config/versions/d7983954dd96_add_ps_endpoints_notify_early_inuse_.py
M contrib/ast-db-manage/config/versions/dbc44d5a908_add_missing_columns_to_sys_and_reg.py
M contrib/ast-db-manage/config/versions/e96a0b8071c_increase_pjsip_column_size.py
M contrib/ast-db-manage/config/versions/eb88a14f2a_add_media_encryption_optimistic_to_pjsip.py
M contrib/ast-db-manage/config/versions/ef7efc2d3964_ps_contacts_add_endpoint_and_modify_.py
M contrib/ast-db-manage/config/versions/f3d1c5d38b56_add_prune_on_boot.py
M contrib/ast-db-manage/config/versions/f638dbe2eb23_symmetric_transport.py
M contrib/ast-db-manage/env.py
29 files changed, 102 insertions(+), 12 deletions(-)

Approvals:
  Kevin Harwell: Looks good to me, but someone else must approve
  George Joseph: Looks good to me, approved
  Jenkins2: Approved for Submit



diff --git a/contrib/ast-db-manage/config/versions/15db7b91a97a_add_rtcp_mux.py b/contrib/ast-db-manage/config/versions/15db7b91a97a_add_rtcp_mux.py
index 8b0214a..de9e10a 100644
--- a/contrib/ast-db-manage/config/versions/15db7b91a97a_add_rtcp_mux.py
+++ b/contrib/ast-db-manage/config/versions/15db7b91a97a_add_rtcp_mux.py
@@ -28,4 +28,6 @@
 
 
 def downgrade():
+    if op.get_context().bind.dialect.name == 'mssql':
+        op.drop_constraint('ck_ps_endpoints_rtcp_mux_yesno_values','ps_endpoints')
     op.drop_column('ps_endpoints', 'rtcp_mux')
diff --git a/contrib/ast-db-manage/config/versions/23530d604b96_add_rpid_immediate.py b/contrib/ast-db-manage/config/versions/23530d604b96_add_rpid_immediate.py
index dc0c01c..b3ffaee 100644
--- a/contrib/ast-db-manage/config/versions/23530d604b96_add_rpid_immediate.py
+++ b/contrib/ast-db-manage/config/versions/23530d604b96_add_rpid_immediate.py
@@ -45,4 +45,6 @@
     op.add_column('ps_endpoints', sa.Column('rpid_immediate', yesno_values))
 
 def downgrade():
+    if op.get_context().bind.dialect.name == 'mssql':
+        op.drop_constraint('ck_ps_endpoints_rpid_immediate_yesno_values','ps_endpoints')
     op.drop_column('ps_endpoints', 'rpid_immediate')
diff --git a/contrib/ast-db-manage/config/versions/26d7f3bf0fa5_add_bind_rtp_to_media_address_to_pjsip.py b/contrib/ast-db-manage/config/versions/26d7f3bf0fa5_add_bind_rtp_to_media_address_to_pjsip.py
index e7c11da..ce2ac1e 100644
--- a/contrib/ast-db-manage/config/versions/26d7f3bf0fa5_add_bind_rtp_to_media_address_to_pjsip.py
+++ b/contrib/ast-db-manage/config/versions/26d7f3bf0fa5_add_bind_rtp_to_media_address_to_pjsip.py
@@ -28,4 +28,6 @@
 
 
 def downgrade():
+    if op.get_context().bind.dialect.name == 'mssql':
+        op.drop_constraint('ck_ps_endpoints_bind_rtp_to_media_address_yesno_values','ps_endpoints')
     op.drop_column('ps_endpoints', 'bind_rtp_to_media_address')
diff --git a/contrib/ast-db-manage/config/versions/28ab27a7826d_add_srv_lookups_to_identify.py b/contrib/ast-db-manage/config/versions/28ab27a7826d_add_srv_lookups_to_identify.py
index 8831e20..9325da3 100644
--- a/contrib/ast-db-manage/config/versions/28ab27a7826d_add_srv_lookups_to_identify.py
+++ b/contrib/ast-db-manage/config/versions/28ab27a7826d_add_srv_lookups_to_identify.py
@@ -28,4 +28,6 @@
 
 
 def downgrade():
+    if op.get_context().bind.dialect.name == 'mssql':
+        op.drop_constraint('ck_ps_endpoint_id_ips_srv_lookups_yesno_values','ps_endpoint_id_ips')
     op.drop_column('ps_endpoint_id_ips', 'srv_lookups')
diff --git a/contrib/ast-db-manage/config/versions/28b8e71e541f_add_g726_non_standard.py b/contrib/ast-db-manage/config/versions/28b8e71e541f_add_g726_non_standard.py
index ad36bd9..08e2e3f 100644
--- a/contrib/ast-db-manage/config/versions/28b8e71e541f_add_g726_non_standard.py
+++ b/contrib/ast-db-manage/config/versions/28b8e71e541f_add_g726_non_standard.py
@@ -27,4 +27,6 @@
 
 
 def downgrade():
+    if op.get_context().bind.dialect.name == 'mssql':
+        op.drop_constraint('ck_ps_endpoints_g726_non_standard_yesno_values','ps_endpoints')
     op.drop_column('ps_endpoints', 'g726_non_standard')
diff --git a/contrib/ast-db-manage/config/versions/2fc7930b41b3_add_pjsip_endpoint_options_for_12_1.py b/contrib/ast-db-manage/config/versions/2fc7930b41b3_add_pjsip_endpoint_options_for_12_1.py
index d39ddb4..3ca16fe 100644
--- a/contrib/ast-db-manage/config/versions/2fc7930b41b3_add_pjsip_endpoint_options_for_12_1.py
+++ b/contrib/ast-db-manage/config/versions/2fc7930b41b3_add_pjsip_endpoint_options_for_12_1.py
@@ -142,6 +142,8 @@
 def downgrade():
     ########################## drop columns ##########################
 
+    if op.get_context().bind.dialect.name == 'mssql':
+        op.drop_constraint('ck_ps_aors_support_path_yesno_values', 'ps_aors')
     op.drop_column('ps_aors', 'support_path')
     op.drop_column('ps_aors', 'outbound_proxy')
     op.drop_column('ps_aors', 'maximum_expiration')
@@ -153,6 +155,8 @@
         new_column_name='mwi_fromuser', existing_type=sa.String(40))
 
     op.drop_column('ps_endpoints', 'set_var')
+    if op.get_context().bind.dialect.name == 'mssql':
+        op.drop_constraint('ck_ps_endpoints_redirect_method_pjsip_redirect_method_values', 'ps_endpoints')
     op.drop_column('ps_endpoints', 'redirect_method')
     op.drop_column('ps_endpoints', 'media_address')
 
diff --git a/contrib/ast-db-manage/config/versions/371a3bf4143e_add_user_eq_phone_option_to_pjsip.py b/contrib/ast-db-manage/config/versions/371a3bf4143e_add_user_eq_phone_option_to_pjsip.py
index ea2b291..62e9668 100644
--- a/contrib/ast-db-manage/config/versions/371a3bf4143e_add_user_eq_phone_option_to_pjsip.py
+++ b/contrib/ast-db-manage/config/versions/371a3bf4143e_add_user_eq_phone_option_to_pjsip.py
@@ -27,4 +27,6 @@
     op.add_column('ps_endpoints', sa.Column('user_eq_phone', yesno_values))
 
 def downgrade():
+    if op.get_context().bind.dialect.name == 'mssql':
+        op.drop_constraint('ck_ps_endpoints_user_eq_phone_yesno_values','ps_endpoints')
     op.drop_column('ps_endpoints', 'user_eq_phone')
diff --git a/contrib/ast-db-manage/config/versions/3772f8f828da_update_identify_by.py b/contrib/ast-db-manage/config/versions/3772f8f828da_update_identify_by.py
index 92695b0..3c80f48 100644
--- a/contrib/ast-db-manage/config/versions/3772f8f828da_update_identify_by.py
+++ b/contrib/ast-db-manage/config/versions/3772f8f828da_update_identify_by.py
@@ -16,6 +16,8 @@
 
 def enum_update(table_name, column_name, enum_name, enum_values):
     if op.get_context().bind.dialect.name != 'postgresql':
+        if op.get_context().bind.dialect.name == 'mssql':
+            op.drop_constraint('ck_ps_endpoints_identify_by_pjsip_identify_by_values', 'ps_endpoints')
         op.alter_column(table_name, column_name,
                         type_=sa.Enum(*enum_values, name=enum_name))
         return
diff --git a/contrib/ast-db-manage/config/versions/3bcc0b5bc2c9_add_allow_reload_to_ps_transports.py b/contrib/ast-db-manage/config/versions/3bcc0b5bc2c9_add_allow_reload_to_ps_transports.py
index 0becc1e..093a5d4 100644
--- a/contrib/ast-db-manage/config/versions/3bcc0b5bc2c9_add_allow_reload_to_ps_transports.py
+++ b/contrib/ast-db-manage/config/versions/3bcc0b5bc2c9_add_allow_reload_to_ps_transports.py
@@ -22,4 +22,6 @@
     op.add_column('ps_transports', sa.Column('allow_reload', yesno_values))
 
 def downgrade():
+    if op.get_context().bind.dialect.name == 'mssql':
+        op.drop_constraint('ck_ps_transports_allow_reload_yesno_values','ps_transports')
     op.drop_column('ps_transports', 'allow_reload')
diff --git a/contrib/ast-db-manage/config/versions/4468b4a91372_add_pjsip_asymmetric_rtp_codec.py b/contrib/ast-db-manage/config/versions/4468b4a91372_add_pjsip_asymmetric_rtp_codec.py
index c121495..1a8ede6 100644
--- a/contrib/ast-db-manage/config/versions/4468b4a91372_add_pjsip_asymmetric_rtp_codec.py
+++ b/contrib/ast-db-manage/config/versions/4468b4a91372_add_pjsip_asymmetric_rtp_codec.py
@@ -28,4 +28,6 @@
 
 
 def downgrade():
+    if op.get_context().bind.dialect.name == 'mssql':
+        op.drop_constraint('ck_ps_endpoints_asymmetric_rtp_codec_yesno_values','ps_endpoints')
     op.drop_column('ps_endpoints', 'asymmetric_rtp_codec')
diff --git a/contrib/ast-db-manage/config/versions/4c573e7135bd_fix_tos_field_types.py b/contrib/ast-db-manage/config/versions/4c573e7135bd_fix_tos_field_types.py
index 27b498f..f99e2ea 100644
--- a/contrib/ast-db-manage/config/versions/4c573e7135bd_fix_tos_field_types.py
+++ b/contrib/ast-db-manage/config/versions/4c573e7135bd_fix_tos_field_types.py
@@ -29,7 +29,7 @@
     op.alter_column('ps_transports', 'tos', type_=sa.String(10))
 
     # Can't cast YENO_VALUES to Integers, so dropping and adding is required
-    op.drop_column('ps_transports', 'cos')
+    op.drop_column('ps_transports', 'cos', schema=None, mssql_drop_check=True)
     op.add_column('ps_transports', sa.Column('cos', sa.Integer))
 
 def downgrade():
@@ -46,6 +46,8 @@
     op.add_column('ps_endpoints', sa.Column('cos_audio', yesno_values))
     op.add_column('ps_endpoints', sa.Column('cos_video', yesno_values))
 
+    if op.get_context().bind.dialect.name == 'mssql':
+        op.drop_constraint('ck_ps_transports_tos_yesno_values', 'ps_transports')
     op.drop_column('ps_transports', 'tos')
     op.add_column('ps_transports', sa.Column('tos', yesno_values))
     # Can't cast integers to YESNO_VALUES, so dropping and adding is required
diff --git a/contrib/ast-db-manage/config/versions/5139253c0423_make_q_member_uniqueid_autoinc.py b/contrib/ast-db-manage/config/versions/5139253c0423_make_q_member_uniqueid_autoinc.py
index 01d4985..3b329b5 100644
--- a/contrib/ast-db-manage/config/versions/5139253c0423_make_q_member_uniqueid_autoinc.py
+++ b/contrib/ast-db-manage/config/versions/5139253c0423_make_q_member_uniqueid_autoinc.py
@@ -39,7 +39,7 @@
     op.drop_column('queue_members', 'uniqueid')
     op.add_column('queue_members', sa.Column(name='uniqueid', type_=sa.Integer,
                                              nullable=False, unique=True))
-    # The postgres backend does not like the autoincrement needed for
+    # The postgres and mssql backends do not like the autoincrement needed for
     # mysql here.  It is just the backend that is giving a warning and
     # not the database itself.
     op.alter_column(table_name='queue_members', column_name='uniqueid',
@@ -50,5 +50,7 @@
 def downgrade():
     # Was unable to find a way to use op.alter_column() to remove the
     # unique index property.
+    if op.get_context().bind.dialect.name == 'mssql':
+        op.drop_constraint('uq_queue_members_uniqueid', 'queue_members')
     op.drop_column('queue_members', 'uniqueid')
     op.add_column('queue_members', sa.Column(name='uniqueid', type_=sa.String(80), nullable=False))
diff --git a/contrib/ast-db-manage/config/versions/51f8cb66540e_add_further_dtls_options.py b/contrib/ast-db-manage/config/versions/51f8cb66540e_add_further_dtls_options.py
index c2dacda..2eea713 100644
--- a/contrib/ast-db-manage/config/versions/51f8cb66540e_add_further_dtls_options.py
+++ b/contrib/ast-db-manage/config/versions/51f8cb66540e_add_further_dtls_options.py
@@ -28,5 +28,8 @@
     op.add_column('ps_endpoints', sa.Column('media_use_received_transport', yesno_values))
 
 def downgrade():
+    if op.get_context().bind.dialect.name == 'mssql':
+        op.drop_constraint('ck_ps_endpoints_force_avp_yesno_values', 'ps_endpoints')
+        op.drop_constraint('ck_ps_endpoints_media_use_received_transport_yesno_values', 'ps_endpoints')
     op.drop_column('ps_endpoints', 'force_avp')
     op.drop_column('ps_endpoints', 'media_use_received_transport')
diff --git a/contrib/ast-db-manage/config/versions/5950038a6ead_fix_pjsip_verifiy_typo.py b/contrib/ast-db-manage/config/versions/5950038a6ead_fix_pjsip_verifiy_typo.py
index 28ebc8b..a1154a3 100644
--- a/contrib/ast-db-manage/config/versions/5950038a6ead_fix_pjsip_verifiy_typo.py
+++ b/contrib/ast-db-manage/config/versions/5950038a6ead_fix_pjsip_verifiy_typo.py
@@ -11,19 +11,32 @@
 down_revision = 'd39508cb8d8'
 
 from alembic import op
+import sqlalchemy as sa
 from sqlalchemy.dialects.postgresql import ENUM
 
 YESNO_NAME = 'yesno_values'
 YESNO_VALUES = ['yes', 'no']
 
-
 def upgrade():
     yesno_values = ENUM(*YESNO_VALUES, name=YESNO_NAME, create_type=False)
-    op.alter_column('ps_transports', 'verifiy_server', type_=yesno_values,
-                    new_column_name='verify_server')
+
+    if op.get_context().bind.dialect.name != 'mssql':
+        op.alter_column('ps_transports', 'verifiy_server', type_=yesno_values,
+                        new_column_name='verify_server')
+    else:
+        op.alter_column('ps_transports', 'verifiy_server', existing_type=yesno_values, type_=sa.String(3),
+                        new_column_name='verify_server')
+        yesno_values = ENUM(*YESNO_VALUES, name=YESNO_NAME, create_type=True)
+        op.alter_column('ps_transports', 'verify_server', existing_type=sa.String(3), type_=yesno_values)
 
 
 def downgrade():
     yesno_values = ENUM(*YESNO_VALUES, name=YESNO_NAME, create_type=False)
-    op.alter_column('ps_transports', 'verify_server', type_=yesno_values,
-                    new_column_name='verifiy_server')
+    if op.get_context().bind.dialect.name != 'mssql':
+        op.alter_column('ps_transports', 'verify_server', type_=yesno_values,
+                        new_column_name='verifiy_server')
+    else:
+        op.alter_column('ps_transports', 'verify_server', existing_type=yesno_values, type_=sa.String(3),
+                        new_column_name='verifiy_server')
+        yesno_values = ENUM(*YESNO_VALUES, name=YESNO_NAME, create_type=True)
+        op.alter_column('ps_transports', 'verifiy_server', existing_type=sa.String(3), type_=yesno_values)
diff --git a/contrib/ast-db-manage/config/versions/837aa67461fb_ps_contacts_add_authenticate_qualify.py b/contrib/ast-db-manage/config/versions/837aa67461fb_ps_contacts_add_authenticate_qualify.py
index 76faf39..033a999 100644
--- a/contrib/ast-db-manage/config/versions/837aa67461fb_ps_contacts_add_authenticate_qualify.py
+++ b/contrib/ast-db-manage/config/versions/837aa67461fb_ps_contacts_add_authenticate_qualify.py
@@ -28,5 +28,7 @@
 
 
 def downgrade():
+    if op.get_context().bind.dialect.name == 'mssql':
+        op.drop_constraint('ck_ps_contacts_authenticate_qualify_yesno_values','ps_contacts')
     op.drop_column('ps_contacts', 'authenticate_qualify')
 
diff --git a/contrib/ast-db-manage/config/versions/86bb1efa278d_add_ps_endpoints_refer_blind_progress.py b/contrib/ast-db-manage/config/versions/86bb1efa278d_add_ps_endpoints_refer_blind_progress.py
index 9b0f6d4..a46ed0c 100644
--- a/contrib/ast-db-manage/config/versions/86bb1efa278d_add_ps_endpoints_refer_blind_progress.py
+++ b/contrib/ast-db-manage/config/versions/86bb1efa278d_add_ps_endpoints_refer_blind_progress.py
@@ -27,4 +27,6 @@
     op.add_column('ps_endpoints', sa.Column('refer_blind_progress', yesno_values))
 
 def downgrade():
+    if op.get_context().bind.dialect.name == 'mssql':
+        op.drop_constraint('ck_ps_endpoints_refer_blind_progress_yesno_values','ps_endpoints')
     op.drop_column('ps_endpoints', 'refer_blind_progress')
diff --git a/contrib/ast-db-manage/config/versions/8d478ab86e29_pjsip_add_disable_multi_domain.py b/contrib/ast-db-manage/config/versions/8d478ab86e29_pjsip_add_disable_multi_domain.py
index a782685..a8d7b48 100644
--- a/contrib/ast-db-manage/config/versions/8d478ab86e29_pjsip_add_disable_multi_domain.py
+++ b/contrib/ast-db-manage/config/versions/8d478ab86e29_pjsip_add_disable_multi_domain.py
@@ -28,4 +28,6 @@
 
 
 def downgrade():
+    if op.get_context().bind.dialect.name == 'mssql':
+        op.drop_constraint('ck_ps_globals_disable_multi_domain_yesno_values','ps_globals')
     op.drop_column('ps_globals', 'disable_multi_domain')
diff --git a/contrib/ast-db-manage/config/versions/8fce4c573e15_add_pjsip_allow_overlap.py b/contrib/ast-db-manage/config/versions/8fce4c573e15_add_pjsip_allow_overlap.py
index 24057ec..539944e 100644
--- a/contrib/ast-db-manage/config/versions/8fce4c573e15_add_pjsip_allow_overlap.py
+++ b/contrib/ast-db-manage/config/versions/8fce4c573e15_add_pjsip_allow_overlap.py
@@ -28,4 +28,6 @@
 
 
 def downgrade():
+    if op.get_context().bind.dialect.name == 'mssql':
+        op.drop_constraint('ck_ps_endpoints_allow_overlap_yesno_values','ps_endpoints')
     op.drop_column('ps_endpoints', 'allow_overlap')
diff --git a/contrib/ast-db-manage/config/versions/a6ef36f1309_ps_globals_add_ignore_uri_user_options.py b/contrib/ast-db-manage/config/versions/a6ef36f1309_ps_globals_add_ignore_uri_user_options.py
index 2ce40a0..4daa422 100644
--- a/contrib/ast-db-manage/config/versions/a6ef36f1309_ps_globals_add_ignore_uri_user_options.py
+++ b/contrib/ast-db-manage/config/versions/a6ef36f1309_ps_globals_add_ignore_uri_user_options.py
@@ -28,5 +28,7 @@
 
 
 def downgrade():
+    if op.get_context().bind.dialect.name == 'mssql':
+        op.drop_constraint('ck_ps_globals_ignore_uri_user_options_yesno_values','ps_globals')
     op.drop_column('ps_globals', 'ignore_uri_user_options')
 
diff --git a/contrib/ast-db-manage/config/versions/b83645976fdd_add_dtls_fingerprint_to_ps_endpoints.py b/contrib/ast-db-manage/config/versions/b83645976fdd_add_dtls_fingerprint_to_ps_endpoints.py
index 3d4f74d..d957104 100644
--- a/contrib/ast-db-manage/config/versions/b83645976fdd_add_dtls_fingerprint_to_ps_endpoints.py
+++ b/contrib/ast-db-manage/config/versions/b83645976fdd_add_dtls_fingerprint_to_ps_endpoints.py
@@ -31,6 +31,8 @@
 def downgrade():
     context = op.get_context()
 
+    if op.get_context().bind.dialect.name == 'mssql':
+        op.drop_constraint('ck_ps_endpoints_dtls_fingerprint_sha_hash_values', 'ps_endpoints')
     op.drop_column('ps_endpoints', 'dtls_fingerprint')
 
     if context.bind.dialect.name == 'postgresql':
diff --git a/contrib/ast-db-manage/config/versions/c7a44a5a0851_pjsip_add_global_mwi_options.py b/contrib/ast-db-manage/config/versions/c7a44a5a0851_pjsip_add_global_mwi_options.py
index d3efa22..c762fc4 100644
--- a/contrib/ast-db-manage/config/versions/c7a44a5a0851_pjsip_add_global_mwi_options.py
+++ b/contrib/ast-db-manage/config/versions/c7a44a5a0851_pjsip_add_global_mwi_options.py
@@ -32,4 +32,6 @@
 def downgrade():
     op.drop_column('ps_globals', 'mwi_tps_queue_high')
     op.drop_column('ps_globals', 'mwi_tps_queue_low')
+    if op.get_context().bind.dialect.name == 'mssql':
+        op.drop_constraint('ck_ps_globals_mwi_disable_initial_unsolicited_yesno_values','ps_globals')
     op.drop_column('ps_globals', 'mwi_disable_initial_unsolicited')
diff --git a/contrib/ast-db-manage/config/versions/d7983954dd96_add_ps_endpoints_notify_early_inuse_.py b/contrib/ast-db-manage/config/versions/d7983954dd96_add_ps_endpoints_notify_early_inuse_.py
index e1dcdd1..a5419a1 100644
--- a/contrib/ast-db-manage/config/versions/d7983954dd96_add_ps_endpoints_notify_early_inuse_.py
+++ b/contrib/ast-db-manage/config/versions/d7983954dd96_add_ps_endpoints_notify_early_inuse_.py
@@ -27,4 +27,6 @@
     op.add_column('ps_endpoints', sa.Column('notify_early_inuse_ringing', yesno_values))
 
 def downgrade():
+    if op.get_context().bind.dialect.name == 'mssql':
+        op.drop_constraint('ck_ps_endpoints_notify_early_inuse_ringing_yesno_values', 'ps_endpoints')
     op.drop_column('ps_endpoints', 'notify_early_inuse_ringing')
diff --git a/contrib/ast-db-manage/config/versions/dbc44d5a908_add_missing_columns_to_sys_and_reg.py b/contrib/ast-db-manage/config/versions/dbc44d5a908_add_missing_columns_to_sys_and_reg.py
index 8aa16f1..9acd4a0 100644
--- a/contrib/ast-db-manage/config/versions/dbc44d5a908_add_missing_columns_to_sys_and_reg.py
+++ b/contrib/ast-db-manage/config/versions/dbc44d5a908_add_missing_columns_to_sys_and_reg.py
@@ -29,6 +29,9 @@
     op.add_column('ps_registrations', sa.Column('endpoint', sa.String(40)))
 
 def downgrade():
+    if op.get_context().bind.dialect.name == 'mssql':
+        op.drop_constraint('ck_ps_systems_disable_tcp_switch_yesno_values','ps_systems')
+        op.drop_constraint('ck_ps_registrations_line_yesno_values','ps_registrations')
     op.drop_column('ps_systems', 'disable_tcp_switch')
     op.drop_column('ps_registrations', 'line')
     op.drop_column('ps_registrations', 'endpoint')
diff --git a/contrib/ast-db-manage/config/versions/e96a0b8071c_increase_pjsip_column_size.py b/contrib/ast-db-manage/config/versions/e96a0b8071c_increase_pjsip_column_size.py
index 9c00c01..da103b1 100644
--- a/contrib/ast-db-manage/config/versions/e96a0b8071c_increase_pjsip_column_size.py
+++ b/contrib/ast-db-manage/config/versions/e96a0b8071c_increase_pjsip_column_size.py
@@ -28,7 +28,13 @@
 def downgrade():
     op.alter_column('ps_globals', 'user_agent', type_=sa.String(40))
 
-    op.alter_column('ps_contacts', 'id', type_=sa.String(40))
+    if op.get_context().bind.dialect.name != 'mssql':
+        op.alter_column('ps_contacts', 'id', type_=sa.String(40))
+    else:
+        op.drop_constraint('uq_ps_contacts_id', 'ps_contacts')
+        op.drop_index('ps_contacts_id', 'ps_contacts')
+        op.alter_column('ps_contacts', 'id', type_=sa.String(40))
+        op.create_index('ps_contacts_id', 'ps_contacts', ['id'])
     op.alter_column('ps_contacts', 'uri', type_=sa.String(40))
     op.alter_column('ps_contacts', 'user_agent', type_=sa.String(40))
 
diff --git a/contrib/ast-db-manage/config/versions/eb88a14f2a_add_media_encryption_optimistic_to_pjsip.py b/contrib/ast-db-manage/config/versions/eb88a14f2a_add_media_encryption_optimistic_to_pjsip.py
index 2d96b37..6653aa6 100644
--- a/contrib/ast-db-manage/config/versions/eb88a14f2a_add_media_encryption_optimistic_to_pjsip.py
+++ b/contrib/ast-db-manage/config/versions/eb88a14f2a_add_media_encryption_optimistic_to_pjsip.py
@@ -28,4 +28,6 @@
 
 
 def downgrade():
+    if op.get_context().bind.dialect.name == 'mssql':
+        op.drop_constraint('ck_ps_endpoints_media_encryption_optimistic_yesno_values','ps_endpoints')
     op.drop_column('ps_endpoints', 'media_encryption_optimistic')
diff --git a/contrib/ast-db-manage/config/versions/ef7efc2d3964_ps_contacts_add_endpoint_and_modify_.py b/contrib/ast-db-manage/config/versions/ef7efc2d3964_ps_contacts_add_endpoint_and_modify_.py
index 43d4028..0ac63c8 100644
--- a/contrib/ast-db-manage/config/versions/ef7efc2d3964_ps_contacts_add_endpoint_and_modify_.py
+++ b/contrib/ast-db-manage/config/versions/ef7efc2d3964_ps_contacts_add_endpoint_and_modify_.py
@@ -27,7 +27,11 @@
     op.create_index('ps_contacts_qualifyfreq_exp', 'ps_contacts', ['qualify_frequency', 'expiration_time'])
     op.create_index('ps_aors_qualifyfreq_contact', 'ps_aors', ['qualify_frequency', 'contact'])
 def downgrade():
-    op.drop_index('ps_aors_qualifyfreq_contact')
-    op.drop_index('ps_contacts_qualifyfreq_exp')
+    if op.get_context().bind.dialect.name != 'mssql':
+        op.drop_index('ps_aors_qualifyfreq_contact')
+        op.drop_index('ps_contacts_qualifyfreq_exp')
+    else:
+        op.drop_index('ps_aors_qualifyfreq_contact', table_name='ps_aors')
+        op.drop_index('ps_contacts_qualifyfreq_exp', table_name='ps_contacts')
     op.drop_column('ps_contacts', 'endpoint')
     op.alter_column('ps_contacts', 'expiration_time', type_=sa.String(40))
diff --git a/contrib/ast-db-manage/config/versions/f3d1c5d38b56_add_prune_on_boot.py b/contrib/ast-db-manage/config/versions/f3d1c5d38b56_add_prune_on_boot.py
index 7596646..83baf5b 100644
--- a/contrib/ast-db-manage/config/versions/f3d1c5d38b56_add_prune_on_boot.py
+++ b/contrib/ast-db-manage/config/versions/f3d1c5d38b56_add_prune_on_boot.py
@@ -28,4 +28,6 @@
 
 
 def downgrade():
+    if op.get_context().bind.dialect.name == 'mssql':
+        op.drop_constraint('ck_ps_contacts_prune_on_boot_yesno_values', 'ps_contacts')
     op.drop_column('ps_contacts', 'prune_on_boot')
diff --git a/contrib/ast-db-manage/config/versions/f638dbe2eb23_symmetric_transport.py b/contrib/ast-db-manage/config/versions/f638dbe2eb23_symmetric_transport.py
index 51b5066..0585aa5 100644
--- a/contrib/ast-db-manage/config/versions/f638dbe2eb23_symmetric_transport.py
+++ b/contrib/ast-db-manage/config/versions/f638dbe2eb23_symmetric_transport.py
@@ -29,4 +29,6 @@
 
 def downgrade():
     op.drop_column('ps_subscription_persistence', 'contact_uri')
+    if op.get_context().bind.dialect.name == 'mssql':
+        op.drop_constraint('ck_ps_transports_symmetric_transport_yesno_values','ps_transports')
     op.drop_column('ps_transports', 'symmetric_transport')
diff --git a/contrib/ast-db-manage/env.py b/contrib/ast-db-manage/env.py
index a903451..1864239 100644
--- a/contrib/ast-db-manage/env.py
+++ b/contrib/ast-db-manage/env.py
@@ -2,7 +2,8 @@
 from alembic import context
 from alembic.script import ScriptDirectory
 from alembic.operations import Operations
-from sqlalchemy import engine_from_config, pool
+from sqlalchemy import engine_from_config, pool, MetaData
+from sqlalchemy.ext.declarative import declarative_base
 from logging.config import fileConfig
 import logging
 
@@ -17,12 +18,24 @@
 except:
     pass
 
+## below block is needed for mssql
+meta = MetaData(naming_convention = {
+	"ix": 'ix_%(column_0_label)s',
+	"uq": "uq_%(table_name)s_%(column_0_name)s",
+	"ck": "ck_%(table_name)s_%(column_0_name)s_%(constraint_name)s",
+	"fk": "fk_%(table_name)s_%(column_0_name)s_%(referred_table_name)s",
+	"pk": "pk_%(table_name)s"
+})
+Base = declarative_base(metadata=meta)
+
 logger = logging.getLogger('alembic.runtime.setup')
 # add your model's MetaData object here
 # for 'autogenerate' support
 # from myapp import mymodel
 # target_metadata = mymodel.Base.metadata
 target_metadata = None
+#Comment above line and uncomment below line for mssql
+#target_metadata = Base.metadata
 
 # other values from the config, defined by the needs of env.py,
 # can be acquired:
@@ -42,7 +55,7 @@
 
     """
     url = config.get_main_option("sqlalchemy.url")
-    context.configure(url=url)
+    context.configure(url=url,target_metadata=target_metadata)
 
     with context.begin_transaction():
         context.run_migrations()

-- 
To view, visit https://gerrit.asterisk.org/6459
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-MessageType: merged
Gerrit-Change-Id: I4a399ba3eed41a33ce8cb294968ad340221580ee
Gerrit-Change-Number: 6459
Gerrit-PatchSet: 2
Gerrit-Owner: Florian Floimair <f.floimair at commend.com>
Gerrit-Reviewer: Florian Floimair <f.floimair at commend.com>
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Jenkins2
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-commits/attachments/20170911/7a44ea0a/attachment-0001.html>


More information about the asterisk-commits mailing list