6a5b9b230b324007e6ad96320a5194ead55b92c6
[asterisk/asterisk.git] / contrib / ast-db-manage / config / versions / f3c0b8695b66_taskprocessor_overload_trigger.py
1 """taskprocessor_overload_trigger
2
3 Revision ID: f3c0b8695b66
4 Revises: 0838f8db6a61
5 Create Date: 2019-02-15 15:03:50.106790
6
7 """
8
9 # revision identifiers, used by Alembic.
10 revision = 'f3c0b8695b66'
11 down_revision = '0838f8db6a61'
12
13 from alembic import op
14 import sqlalchemy as sa
15 from sqlalchemy.dialects.postgresql import ENUM
16
17 PJSIP_TASKPROCESSOR_OVERLOAD_TRIGGER_NAME = 'pjsip_taskprocessor_overload_trigger_values'
18 PJSIP_TASKPROCESSOR_OVERLOAD_TRIGGER_VALUES = ['none', 'global', 'pjsip_only']
19
20 def upgrade():
21     context = op.get_context()
22
23     if context.bind.dialect.name == 'postgresql':
24         enum = ENUM(*PJSIP_TASKPROCESSOR_OVERLOAD_TRIGGER_VALUES,
25                     name=PJSIP_TASKPROCESSOR_OVERLOAD_TRIGGER_NAME)
26         enum.create(op.get_bind(), checkfirst=False)
27
28     op.add_column('ps_globals',
29         sa.Column('taskprocessor_overload_trigger',
30             sa.Enum(*PJSIP_TASKPROCESSOR_OVERLOAD_TRIGGER_VALUES,
31             name=PJSIP_TASKPROCESSOR_OVERLOAD_TRIGGER_NAME,
32             create_type=False)))
33
34 def downgrade():
35     if op.get_context().bind.dialect.name == 'mssql':
36         op.drop_constraint('ck_ps_globals_taskprocessor_overload_trigger_pjsip_taskprocessor_overload_trigger_values', 'ps_globals')
37     op.drop_column('ps_globals', 'taskprocessor_overload_trigger')
38
39     if context.bind.dialect.name == 'postgresql':
40         enum = ENUM(*PJSIP_TASKPROCESSOR_OVERLOAD_TRIGGER_VALUES,
41                     name=PJSIP_TASKPROCESSOR_OVERLOAD_TRIGGER_NAME)
42         enum.drop(op.get_bind(), checkfirst=False)