| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
"""Add Outgoing enum value to sippeers directmedia |
| 20 |
|
| 21 |
Revision ID: 10aedae86a32 |
| 22 |
Revises: 5950038a6ead |
| 23 |
Create Date: 2014-09-19 16:03:13.469436 |
| 24 |
|
| 25 |
""" |
| 26 |
|
| 27 |
|
| 28 |
revision = '10aedae86a32' |
| 29 |
down_revision = '5950038a6ead' |
| 30 |
|
| 31 |
from alembic import op |
| 32 |
from sqlalchemy.dialects.postgresql import ENUM |
| 33 |
import sqlalchemy as sa |
| 34 |
|
| 35 |
OLD_ENUM = ['yes', 'no', 'nonat', 'update'] |
| 36 |
NEW_ENUM = ['yes', 'no', 'nonat', 'update', 'outgoing'] |
| 37 |
|
| 38 |
old_type = sa.Enum(*OLD_ENUM, name='sip_directmedia_values') |
| 39 |
new_type = sa.Enum(*NEW_ENUM, name='sip_directmedia_values_v2') |
| 40 |
|
| 41 |
tcr = sa.sql.table('sippeers', sa.Column('directmedia', new_type, |
| 42 |
nullable=True)) |
| 43 |
|
| 44 |
def upgrade(): |
| 45 |
context = op.get_context() |
| 46 |
|
| 47 |
|
| 48 |
if context.bind.dialect.name != 'postgresql': |
| 49 |
op.alter_column('sippeers', 'directmedia', |
| 50 |
type_=new_type, |
| 51 |
existing_type=old_type) |
| 52 |
else: |
| 53 |
enum = ENUM("yes", "no", "nonat", "update", "outgoing", |
| 54 |
name="sip_directmedia_values_v2") |
| 55 |
enum.create(op.get_bind(), checkfirst=False) |
| 56 |
|
| 57 |
op.execute('ALTER TABLE sippeers ALTER COLUMN directmedia TYPE' |
| 58 |
' sip_directmedia_values_v2 USING' |
| 59 |
' directmedia::text::sip_directmedia_values_v2') |
| 60 |
|
| 61 |
ENUM(name="sip_directmedia_values").drop(op.get_bind(), checkfirst=False) |
| 62 |
|
| 63 |
def downgrade(): |
| 64 |
context = op.get_context() |
| 65 |
|
| 66 |
op.execute(tcr.update().where(tcr.c.directmedia==u'outgoing') |
| 67 |
.values(directmedia=None)) |
| 68 |
|
| 69 |
if context.bind.dialect.name != 'postgresql': |
| 70 |
op.alter_column('sippeers', 'directmedia', |
| 71 |
type_=old_type, |
| 72 |
existing_type=new_type) |
| 73 |
else: |
| 74 |
enum = ENUM("yes", "no", "nonat", "update", |
| 75 |
name="sip_directmedia_values") |
| 76 |
enum.create(op.get_bind(), checkfirst=False) |
| 77 |
|
| 78 |
op.execute('ALTER TABLE sippeers ALTER COLUMN directmedia TYPE' |
| 79 |
' sip_directmedia_values USING' |
| 80 |
' directmedia::text::sip_directmedia_values') |
| 81 |
|
| 82 |
ENUM(name="sip_directmedia_values_v2").drop(op.get_bind(), |
| 83 |
checkfirst=False) |