pjsip configuration: Make transport TOS values consistent with endpoints
[asterisk/asterisk.git] / contrib / ast-db-manage / config / versions / 4c573e7135bd_fix_tos_field_types.py
1 """Fix tos and cos field types
2
3 Revision ID: 4c573e7135bd
4 Revises: 21e526ad3040
5 Create Date: 2014-03-05 12:16:56.618630
6
7 """
8
9 # revision identifiers, used by Alembic.
10 revision = '4c573e7135bd'
11 down_revision = '21e526ad3040'
12
13 from alembic import op
14 from alembic import context
15 import sqlalchemy as sa
16 from sqlalchemy.dialects.postgresql import ENUM
17
18 YESNO_NAME = 'yesno_values'
19 YESNO_VALUES = ['yes', 'no']
20
21 def upgrade():
22     op.alter_column('ps_endpoints', 'tos_audio',
23                     type_=sa.String(10))
24     op.alter_column('ps_endpoints', 'tos_video',
25                     type_=sa.String(10))
26     op.alter_column('ps_transports', 'tos',
27                     type_=sa.String(10))
28
29     # Can't cast YENO_VALUES to Integers, so dropping and adding is required
30     op.drop_column('ps_endpoints', 'cos_audio')
31     op.drop_column('ps_endpoints', 'cos_video')
32     op.drop_column('ps_transports', 'cos')
33
34     op.add_column('ps_endpoints', sa.Column('cos_audio', sa.Integer))
35     op.add_column('ps_endpoints', sa.Column('cos_video', sa.Integer))
36     op.add_column('ps_transports', sa.Column('cos', sa.Integer))
37     pass
38
39
40 def downgrade():
41
42     yesno_values = ENUM(*YESNO_VALUES, name=YESNO_NAME, create_type=False)
43
44     # Can't cast string to YESNO_VALUES, so dropping and adding is required
45     op.drop_column('ps_endpoints', 'tos_audio')
46     op.drop_column('ps_endpoints', 'tos_video')
47     op.drop_column('ps_transports', 'tos')
48
49     op.add_column('ps_endpoints', sa.Column('tos_audio', yesno_values))
50     op.add_column('ps_endpoints', sa.Column('tos_video', yesno_values))
51     op.add_column('ps_transports', sa.Column('tos', yesno_values))
52
53     # Can't cast integers to YESNO_VALUES, so dropping and adding is required
54     op.drop_column('ps_endpoints', 'cos_audio')
55     op.drop_column('ps_endpoints', 'cos_video')
56     op.drop_column('ps_transports', 'cos')
57
58     op.add_column('ps_endpoints', sa.Column('cos_audio', yesno_values))
59     op.add_column('ps_endpoints', sa.Column('cos_video', yesno_values))
60     op.add_column('ps_transports', sa.Column('cos', yesno_values))
61     pass