summaryrefslogtreecommitdiff
path: root/contrib/ast-db-manage
diff options
context:
space:
mode:
authorJonathan Rose <jrose@digium.com>2014-10-02 20:15:27 +0000
committerJonathan Rose <jrose@digium.com>2014-10-02 20:15:27 +0000
commit9ff743e9958e4fafa57a0ecd448e653f61668b5d (patch)
treedb8922d2a8389856a732ebf121ee50c8ef9e1b6f /contrib/ast-db-manage
parent1e620fe59ee34a16b786981a8618b22e6f6fd4c5 (diff)
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/ ........ Merged revisions 424372 from http://svn.asterisk.org/svn/asterisk/branches/12 git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/13@424373 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'contrib/ast-db-manage')
-rwxr-xr-xcontrib/ast-db-manage/config/versions/10aedae86a32_add_outgoing_enum_va.py83
1 files changed, 83 insertions, 0 deletions
diff --git a/contrib/ast-db-manage/config/versions/10aedae86a32_add_outgoing_enum_va.py b/contrib/ast-db-manage/config/versions/10aedae86a32_add_outgoing_enum_va.py
new file mode 100755
index 000000000..b4ea71cbd
--- /dev/null
+++ b/contrib/ast-db-manage/config/versions/10aedae86a32_add_outgoing_enum_va.py
@@ -0,0 +1,83 @@
+#
+# Asterisk -- An open source telephony toolkit.
+#
+# Copyright (C) 2014, Jonathan Rose
+#
+# Jonathan R. Rose <jrose@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)