10aedae86a32_add_outgoing_enum_va.py 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #
  2. # Asterisk -- An open source telephony toolkit.
  3. #
  4. # Copyright (C) 2014, Jonathan Rose
  5. #
  6. # Jonathan R. Rose <jrose@digium.com>
  7. #
  8. # See http://www.asterisk.org for more information about
  9. # the Asterisk project. Please do not directly contact
  10. # any of the maintainers of this project for assistance;
  11. # the project provides a web site, mailing lists and IRC
  12. # channels for your use.
  13. #
  14. # This program is free software, distributed under the terms of
  15. # the GNU General Public License Version 2. See the LICENSE file
  16. # at the top of the source tree.
  17. #
  18. """Add Outgoing enum value to sippeers directmedia
  19. Revision ID: 10aedae86a32
  20. Revises: 5950038a6ead
  21. Create Date: 2014-09-19 16:03:13.469436
  22. """
  23. # revision identifiers, used by Alembic.
  24. revision = '10aedae86a32'
  25. down_revision = '5950038a6ead'
  26. from alembic import op
  27. from sqlalchemy.dialects.postgresql import ENUM
  28. import sqlalchemy as sa
  29. OLD_ENUM = ['yes', 'no', 'nonat', 'update']
  30. NEW_ENUM = ['yes', 'no', 'nonat', 'update', 'outgoing']
  31. old_type = sa.Enum(*OLD_ENUM, name='sip_directmedia_values')
  32. new_type = sa.Enum(*NEW_ENUM, name='sip_directmedia_values_v2')
  33. tcr = sa.sql.table('sippeers', sa.Column('directmedia', new_type,
  34. nullable=True))
  35. def upgrade():
  36. context = op.get_context()
  37. # Upgrading to this revision WILL clear your directmedia values.
  38. if context.bind.dialect.name != 'postgresql':
  39. op.alter_column('sippeers', 'directmedia',
  40. type_=new_type,
  41. existing_type=old_type)
  42. else:
  43. enum = ENUM("yes", "no", "nonat", "update", "outgoing",
  44. name="sip_directmedia_values_v2")
  45. enum.create(op.get_bind(), checkfirst=False)
  46. op.execute('ALTER TABLE sippeers ALTER COLUMN directmedia TYPE'
  47. ' sip_directmedia_values_v2 USING'
  48. ' directmedia::text::sip_directmedia_values_v2')
  49. ENUM(name="sip_directmedia_values").drop(op.get_bind(), checkfirst=False)
  50. def downgrade():
  51. context = op.get_context()
  52. op.execute(tcr.update().where(tcr.c.directmedia==u'outgoing')
  53. .values(directmedia=None))
  54. if context.bind.dialect.name != 'postgresql':
  55. op.alter_column('sippeers', 'directmedia',
  56. type_=old_type,
  57. existing_type=new_type)
  58. else:
  59. enum = ENUM("yes", "no", "nonat", "update",
  60. name="sip_directmedia_values")
  61. enum.create(op.get_bind(), checkfirst=False)
  62. op.execute('ALTER TABLE sippeers ALTER COLUMN directmedia TYPE'
  63. ' sip_directmedia_values USING'
  64. ' directmedia::text::sip_directmedia_values')
  65. ENUM(name="sip_directmedia_values_v2").drop(op.get_bind(),
  66. checkfirst=False)