Asterisk - The Open Source Telephony Project  18.5.0
28887f25a46f_create_queue_tables.py
Go to the documentation of this file.
1 #
2 # Asterisk -- An open source telephony toolkit.
3 #
4 # Copyright (C) 2014, Richard Mudgett
5 #
6 # Richard Mudgett <[email protected]>
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 
19 """Create queue tables
20 
21 Revision ID: 28887f25a46f
22 Revises: 21e526ad3040
23 Create Date: 2014-03-03 12:26:25.261640
24 
25 """
26 
27 # revision identifiers, used by Alembic.
28 revision = '28887f25a46f'
29 down_revision = '21e526ad3040'
30 
31 from alembic import op
32 from alembic import context
33 import sqlalchemy as sa
34 from sqlalchemy.dialects.postgresql import ENUM
35 
36 
37 YESNO_NAME = 'yesno_values'
38 YESNO_VALUES = ['yes', 'no']
39 
40 QUEUE_STRATEGY_NAME = 'queue_strategy_values'
41 QUEUE_STRATEGY_VALUES = [ 'ringall', 'leastrecent', 'fewestcalls', 'random', 'rrmemory',
42  'linear', 'wrandom', 'rrordered', ]
43 
44 QUEUE_AUTOPAUSE_NAME = 'queue_autopause_values'
45 QUEUE_AUTOPAUSE_VALUES = ['yes', 'no', 'all']
46 
47 
48 def upgrade():
49  ############################# Enums ##############################
50 
51  # yesno_values have already been created, so use postgres enum object
52  # type to get around "already created" issue - works okay with mysql
53  yesno_values = ENUM(*YESNO_VALUES, name=YESNO_NAME, create_type=False)
54 
55  queue_strategy_values = sa.Enum(*QUEUE_STRATEGY_VALUES, name=QUEUE_STRATEGY_NAME)
56  queue_autopause_values = sa.Enum(*QUEUE_AUTOPAUSE_VALUES, name=QUEUE_AUTOPAUSE_NAME)
57 
58  ######################### create tables ##########################
59 
60  op.create_table(
61  'queues',
62  sa.Column('name', sa.String(128), primary_key=True, nullable=False),
63  sa.Column('musiconhold', sa.String(128)),
64  sa.Column('announce', sa.String(128)),
65  sa.Column('context', sa.String(128)),
66  sa.Column('timeout', sa.Integer),
67  sa.Column('ringinuse', yesno_values),
68  sa.Column('setinterfacevar', yesno_values),
69  sa.Column('setqueuevar', yesno_values),
70  sa.Column('setqueueentryvar', yesno_values),
71  sa.Column('monitor_format', sa.String(8)),
72  sa.Column('membermacro', sa.String(512)),
73  sa.Column('membergosub', sa.String(512)),
74  sa.Column('queue_youarenext', sa.String(128)),
75  sa.Column('queue_thereare', sa.String(128)),
76  sa.Column('queue_callswaiting', sa.String(128)),
77  sa.Column('queue_quantity1', sa.String(128)),
78  sa.Column('queue_quantity2', sa.String(128)),
79  sa.Column('queue_holdtime', sa.String(128)),
80  sa.Column('queue_minutes', sa.String(128)),
81  sa.Column('queue_minute', sa.String(128)),
82  sa.Column('queue_seconds', sa.String(128)),
83  sa.Column('queue_thankyou', sa.String(128)),
84  sa.Column('queue_callerannounce', sa.String(128)),
85  sa.Column('queue_reporthold', sa.String(128)),
86  sa.Column('announce_frequency', sa.Integer),
87  sa.Column('announce_to_first_user', yesno_values),
88  sa.Column('min_announce_frequency', sa.Integer),
89  sa.Column('announce_round_seconds', sa.Integer),
90  sa.Column('announce_holdtime', sa.String(128)),
91  sa.Column('announce_position', sa.String(128)),
92  sa.Column('announce_position_limit', sa.Integer),
93  sa.Column('periodic_announce', sa.String(50)),
94  sa.Column('periodic_announce_frequency', sa.Integer),
95  sa.Column('relative_periodic_announce', yesno_values),
96  sa.Column('random_periodic_announce', yesno_values),
97  sa.Column('retry', sa.Integer),
98  sa.Column('wrapuptime', sa.Integer),
99  sa.Column('penaltymemberslimit', sa.Integer),
100  sa.Column('autofill', yesno_values),
101  sa.Column('monitor_type', sa.String(128)),
102  sa.Column('autopause', queue_autopause_values),
103  sa.Column('autopausedelay', sa.Integer),
104  sa.Column('autopausebusy', yesno_values),
105  sa.Column('autopauseunavail', yesno_values),
106  sa.Column('maxlen', sa.Integer),
107  sa.Column('servicelevel', sa.Integer),
108  sa.Column('strategy', queue_strategy_values),
109  sa.Column('joinempty', sa.String(128)),
110  sa.Column('leavewhenempty', sa.String(128)),
111  sa.Column('reportholdtime', yesno_values),
112  sa.Column('memberdelay', sa.Integer),
113  sa.Column('weight', sa.Integer),
114  sa.Column('timeoutrestart', yesno_values),
115  sa.Column('defaultrule', sa.String(128)),
116  sa.Column('timeoutpriority', sa.String(128))
117  )
118 
119  op.create_table(
120  'queue_members',
121  sa.Column('queue_name', sa.String(80), primary_key=True, nullable=False),
122  sa.Column('interface', sa.String(80), primary_key=True, nullable=False),
123  sa.Column('uniqueid', sa.String(80), nullable=False),
124  sa.Column('membername', sa.String(80)),
125  sa.Column('state_interface', sa.String(80)),
126  sa.Column('penalty', sa.Integer),
127  sa.Column('paused', sa.Integer)
128  )
129 
130 
131 def downgrade():
132  ########################## drop tables ###########################
133 
134  op.drop_table('queues')
135  op.drop_table('queue_members')
136 
137  ########################## drop enums ############################
138 
139  sa.Enum(name=QUEUE_STRATEGY_NAME).drop(op.get_bind(), checkfirst=False)
140  sa.Enum(name=QUEUE_AUTOPAUSE_NAME).drop(op.get_bind(), checkfirst=False)