[Asterisk-code-review] build: 'postgresql_using' was causing problems. (...asterisk[13])

Benjamin Keith Ford asteriskteam at digium.com
Fri Mar 29 14:31:19 CDT 2019


Benjamin Keith Ford has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/11208


Change subject: build: 'postgresql_using' was causing problems.
......................................................................

build: 'postgresql_using' was causing problems.

During local testing, using the parameter 'postgresql_using' when using
alembic to alter a column (op.alter_column) worked fine. It is
documented in their changelog as a valid keyword argument to use.
Unfortunately, this parameter is not recognized when running on
combuilder for unknown reasons. Quick fix to do an execute statement
with USING SQL syntax instead of the 'postgresql_using' parameter.

Change-Id: I7fdde0efa33ad91e761512bc2e2d0bab02cb6baf
---
M contrib/ast-db-manage/config/versions/fe6592859b85_fix_mwi_subscribe_replaces_.py
1 file changed, 17 insertions(+), 8 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/08/11208/1

diff --git a/contrib/ast-db-manage/config/versions/fe6592859b85_fix_mwi_subscribe_replaces_.py b/contrib/ast-db-manage/config/versions/fe6592859b85_fix_mwi_subscribe_replaces_.py
index c0f528a..3d74c08 100644
--- a/contrib/ast-db-manage/config/versions/fe6592859b85_fix_mwi_subscribe_replaces_.py
+++ b/contrib/ast-db-manage/config/versions/fe6592859b85_fix_mwi_subscribe_replaces_.py
@@ -24,20 +24,28 @@
 
 
 def upgrade():
+    context = op.get_context()
+
     # Create the new enum
     ast_bool_values = ENUM(*AST_BOOL_VALUES, name=AST_BOOL_NAME, create_type=False)
-    if op.get_context().bind.dialect.name == 'postgresql':
+    if context.bind.dialect.name == 'postgresql':
         ast_bool_values.create(op.get_bind(), checkfirst=False)
 
     # There is no direct way to convert from Integer to ENUM that is
     # not database specific so we transition through a string type.
     op.alter_column('ps_endpoints', 'mwi_subscribe_replaces_unsolicited',
                     type_=sa.String(5))
-    op.alter_column('ps_endpoints', 'mwi_subscribe_replaces_unsolicited',
-            type_=ast_bool_values, postgresql_using='mwi_subscribe_replaces_unsolicited::{0}'.format(AST_BOOL_NAME))
+    if context.bind.dialect.name != 'postgresql':
+        op.alter_column('ps_endpoints', 'mwi_subscribe_replaces_unsolicited',
+                type_=ast_bool_values)
+    else:
+        op.execute('ALTER TABLE ps_endpoints ALTER COLUMN mwi_subscribe_replaces_unsolicited '
+                   'TYPE {0} USING mwi_subscribe_replaces_unsolicited::{0}'.format(AST_BOOL_NAME))
 
 
 def downgrade():
+    context = op.get_context()
+
     # First we need to ensure the column is using only the 'numeric' bool enum values.
     op.execute("UPDATE ps_endpoints SET mwi_subscribe_replaces_unsolicited='0'"
                " WHERE mwi_subscribe_replaces_unsolicited='off'"
@@ -50,12 +58,13 @@
 
     # There is no direct way to convert from ENUM to Integer that is
     # not database specific so we transition through a string type.
-    if op.get_context().bind.dialect.name == 'mssql':
+    if context.bind.dialect.name == 'mssql':
         op.drop_constraint('ck_ps_endpoints_mwi_subscribe_replaces_unsolicited_ast_bool_values', 'ps_endpoints')
     op.alter_column('ps_endpoints', 'mwi_subscribe_replaces_unsolicited',
                     type_=sa.String(5))
-    op.alter_column('ps_endpoints', 'mwi_subscribe_replaces_unsolicited',
-            type_=sa.Integer, postgresql_using='mwi_subscribe_replaces_unsolicited::Integer')
-
-    if op.get_context().bind.dialect.name == 'postgresql':
+    if context.bind.dialect.name != 'postgresql':
+        op.alter_column('ps_endpoints', 'mwi_subscribe_replaces_unsolicited', type_=sa.Integer)
+    else:
+        op.execute('ALTER TABLE ps_endpoints ALTER COLUMN mwi_subscribe_replaces_unsolicited '
+                   'TYPE Integer USING mwi_subscribe_replaces_unsolicited::Integer')
         ENUM(name=AST_BOOL_NAME).drop(op.get_bind(), checkfirst=False)

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/11208
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-Change-Id: I7fdde0efa33ad91e761512bc2e2d0bab02cb6baf
Gerrit-Change-Number: 11208
Gerrit-PatchSet: 1
Gerrit-Owner: Benjamin Keith Ford <bford at digium.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20190329/f8cdcd92/attachment.html>


More information about the asterisk-code-review mailing list