[svn-commits] jrose: branch 12 r424372 - /branches/12/contrib/ast-db-manage/config/versions/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Thu Oct 2 14:58:15 CDT 2014


Author: jrose
Date: Thu Oct  2 14:58:08 2014
New Revision: 424372

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=424372
Log:
Alembic: Add enumerator value to sippeers -> directmedia - 'outgoing'

The 'outgoing' value was left off of the enumerator when first creating the
column. This patch adds it, and should gracefully upgrade keeping the existing
data in tact.

ASTERISK-23781 #close
Reported by: Stephen More
Review: https://reviewboard.asterisk.org/r/4013/


Added:
    branches/12/contrib/ast-db-manage/config/versions/10aedae86a32_add_outgoing_enum_va.py   (with props)

Added: branches/12/contrib/ast-db-manage/config/versions/10aedae86a32_add_outgoing_enum_va.py
URL: http://svnview.digium.com/svn/asterisk/branches/12/contrib/ast-db-manage/config/versions/10aedae86a32_add_outgoing_enum_va.py?view=auto&rev=424372
==============================================================================
--- branches/12/contrib/ast-db-manage/config/versions/10aedae86a32_add_outgoing_enum_va.py (added)
+++ branches/12/contrib/ast-db-manage/config/versions/10aedae86a32_add_outgoing_enum_va.py Thu Oct  2 14:58:08 2014
@@ -1,0 +1,83 @@
+#
+# Asterisk -- An open source telephony toolkit.
+#
+# Copyright (C) 2014, Jonathan Rose
+#
+# Jonathan R. Rose <jrose at digium.com>
+#
+# See http://www.asterisk.org for more information about
+# the Asterisk project. Please do not directly contact
+# any of the maintainers of this project for assistance;
+# the project provides a web site, mailing lists and IRC
+# channels for your use.
+#
+# This program is free software, distributed under the terms of
+# the GNU General Public License Version 2. See the LICENSE file
+# at the top of the source tree.
+#
+
+"""Add Outgoing enum value to sippeers directmedia
+
+Revision ID: 10aedae86a32
+Revises: 5950038a6ead
+Create Date: 2014-09-19 16:03:13.469436
+
+"""
+
+# revision identifiers, used by Alembic.
+revision = '10aedae86a32'
+down_revision = '5950038a6ead'
+
+from alembic import op
+from sqlalchemy.dialects.postgresql import ENUM
+import sqlalchemy as sa
+
+OLD_ENUM = ['yes', 'no', 'nonat', 'update']
+NEW_ENUM = ['yes', 'no', 'nonat', 'update', 'outgoing']
+
+old_type = sa.Enum(*OLD_ENUM, name='sip_directmedia_values')
+new_type = sa.Enum(*NEW_ENUM, name='sip_directmedia_values_v2')
+
+tcr = sa.sql.table('sippeers', sa.Column('directmedia', new_type,
+                   nullable=True))
+
+def upgrade():
+    context = op.get_context()
+
+    # Upgrading to this revision WILL clear your directmedia values.
+    if context.bind.dialect.name != 'postgresql':
+        op.alter_column('sippeers', 'directmedia',
+                        type_=new_type,
+                        existing_type=old_type)
+    else:
+        enum = ENUM("yes", "no", "nonat", "update", "outgoing",
+                    name="sip_directmedia_values_v2")
+        enum.create(op.get_bind(), checkfirst=False)
+
+        op.execute('ALTER TABLE sippeers ALTER COLUMN directmedia TYPE'
+                   ' sip_directmedia_values_v2 USING'
+                   ' directmedia::text::sip_directmedia_values_v2')
+
+        ENUM(name="sip_directmedia_values").drop(op.get_bind(), checkfirst=False)
+
+def downgrade():
+    context = op.get_context()
+
+    op.execute(tcr.update().where(tcr.c.directmedia==u'outgoing')
+               .values(directmedia=None))
+
+    if context.bind.dialect.name != 'postgresql':
+        op.alter_column('sippeers', 'directmedia',
+                        type_=old_type,
+                        existing_type=new_type)
+    else:
+        enum = ENUM("yes", "no", "nonat", "update",
+                    name="sip_directmedia_values")
+        enum.create(op.get_bind(), checkfirst=False)
+
+        op.execute('ALTER TABLE sippeers ALTER COLUMN directmedia TYPE'
+                   ' sip_directmedia_values USING'
+                   ' directmedia::text::sip_directmedia_values')
+
+        ENUM(name="sip_directmedia_values_v2").drop(op.get_bind(),
+                                                checkfirst=False)

Propchange: branches/12/contrib/ast-db-manage/config/versions/10aedae86a32_add_outgoing_enum_va.py
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: branches/12/contrib/ast-db-manage/config/versions/10aedae86a32_add_outgoing_enum_va.py
------------------------------------------------------------------------------
    svn:executable = *

Propchange: branches/12/contrib/ast-db-manage/config/versions/10aedae86a32_add_outgoing_enum_va.py
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: branches/12/contrib/ast-db-manage/config/versions/10aedae86a32_add_outgoing_enum_va.py
------------------------------------------------------------------------------
    svn:mime-type = text/plain




More information about the svn-commits mailing list