~singpolyma/asterisk

ref: 130ba7aeba07eb8bb3ea34418ca458bb58b05080 asterisk/contrib/ast-db-manage/config/versions/28887f25a46f_create_queue_tables.py -rw-r--r-- 5.4 KiB
130ba7ae — Bernhard Schmidt Import asterisk_16.2.1~dfsg.orig.tar.xz 3 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#
# Asterisk -- An open source telephony toolkit.
#
# Copyright (C) 2014, Richard Mudgett
#
# Richard Mudgett <rmudgett@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.
#

"""Create queue tables

Revision ID: 28887f25a46f
Revises: 21e526ad3040
Create Date: 2014-03-03 12:26:25.261640

"""

# revision identifiers, used by Alembic.
revision = '28887f25a46f'
down_revision = '21e526ad3040'

from alembic import op
from alembic import context
import sqlalchemy as sa
from sqlalchemy.dialects.postgresql import ENUM


YESNO_NAME = 'yesno_values'
YESNO_VALUES = ['yes', 'no']

QUEUE_STRATEGY_NAME = 'queue_strategy_values'
QUEUE_STRATEGY_VALUES = [ 'ringall', 'leastrecent', 'fewestcalls', 'random', 'rrmemory',
    'linear', 'wrandom', 'rrordered', ]

QUEUE_AUTOPAUSE_NAME = 'queue_autopause_values'
QUEUE_AUTOPAUSE_VALUES = ['yes', 'no', 'all']


def upgrade():
    ############################# Enums ##############################

    # yesno_values have already been created, so use postgres enum object
    # type to get around "already created" issue - works okay with mysql
    yesno_values = ENUM(*YESNO_VALUES, name=YESNO_NAME, create_type=False)

    queue_strategy_values = sa.Enum(*QUEUE_STRATEGY_VALUES, name=QUEUE_STRATEGY_NAME)
    queue_autopause_values = sa.Enum(*QUEUE_AUTOPAUSE_VALUES, name=QUEUE_AUTOPAUSE_NAME)

    ######################### create tables ##########################

    op.create_table(
        'queues',
        sa.Column('name', sa.String(128), primary_key=True, nullable=False),
        sa.Column('musiconhold', sa.String(128)),
        sa.Column('announce', sa.String(128)),
        sa.Column('context', sa.String(128)),
        sa.Column('timeout', sa.Integer),
        sa.Column('ringinuse', yesno_values),
        sa.Column('setinterfacevar', yesno_values),
        sa.Column('setqueuevar', yesno_values),
        sa.Column('setqueueentryvar', yesno_values),
        sa.Column('monitor_format', sa.String(8)),
        sa.Column('membermacro', sa.String(512)),
        sa.Column('membergosub', sa.String(512)),
        sa.Column('queue_youarenext', sa.String(128)),
        sa.Column('queue_thereare', sa.String(128)),
        sa.Column('queue_callswaiting', sa.String(128)),
        sa.Column('queue_quantity1', sa.String(128)),
        sa.Column('queue_quantity2', sa.String(128)),
        sa.Column('queue_holdtime', sa.String(128)),
        sa.Column('queue_minutes', sa.String(128)),
        sa.Column('queue_minute', sa.String(128)),
        sa.Column('queue_seconds', sa.String(128)),
        sa.Column('queue_thankyou', sa.String(128)),
        sa.Column('queue_callerannounce', sa.String(128)),
        sa.Column('queue_reporthold', sa.String(128)),
        sa.Column('announce_frequency', sa.Integer),
        sa.Column('announce_to_first_user', yesno_values),
        sa.Column('min_announce_frequency', sa.Integer),
        sa.Column('announce_round_seconds', sa.Integer),
        sa.Column('announce_holdtime', sa.String(128)),
        sa.Column('announce_position', sa.String(128)),
        sa.Column('announce_position_limit', sa.Integer),
        sa.Column('periodic_announce', sa.String(50)),
        sa.Column('periodic_announce_frequency', sa.Integer),
        sa.Column('relative_periodic_announce', yesno_values),
        sa.Column('random_periodic_announce', yesno_values),
        sa.Column('retry', sa.Integer),
        sa.Column('wrapuptime', sa.Integer),
        sa.Column('penaltymemberslimit', sa.Integer),
        sa.Column('autofill', yesno_values),
        sa.Column('monitor_type', sa.String(128)),
        sa.Column('autopause', queue_autopause_values),
        sa.Column('autopausedelay', sa.Integer),
        sa.Column('autopausebusy', yesno_values),
        sa.Column('autopauseunavail', yesno_values),
        sa.Column('maxlen', sa.Integer),
        sa.Column('servicelevel', sa.Integer),
        sa.Column('strategy', queue_strategy_values),
        sa.Column('joinempty', sa.String(128)),
        sa.Column('leavewhenempty', sa.String(128)),
        sa.Column('reportholdtime', yesno_values),
        sa.Column('memberdelay', sa.Integer),
        sa.Column('weight', sa.Integer),
        sa.Column('timeoutrestart', yesno_values),
        sa.Column('defaultrule', sa.String(128)),
        sa.Column('timeoutpriority', sa.String(128))
    )

    op.create_table(
        'queue_members',
        sa.Column('queue_name', sa.String(80), primary_key=True, nullable=False),
        sa.Column('interface', sa.String(80), primary_key=True, nullable=False),
        sa.Column('uniqueid', sa.String(80), nullable=False),
        sa.Column('membername', sa.String(80)),
        sa.Column('state_interface', sa.String(80)),
        sa.Column('penalty', sa.Integer),
        sa.Column('paused', sa.Integer)
    )


def downgrade():
    ########################## drop tables ###########################

    op.drop_table('queues')
    op.drop_table('queue_members')

    ########################## drop enums ############################

    sa.Enum(name=QUEUE_STRATEGY_NAME).drop(op.get_bind(), checkfirst=False)
    sa.Enum(name=QUEUE_AUTOPAUSE_NAME).drop(op.get_bind(), checkfirst=False)