Asterisk - The Open Source Telephony Project GIT-master-f36a736
4da0c5f79a9c_create_tables.py
Go to the documentation of this file.
2# Asterisk -- An open source telephony toolkit.
3#
4# Copyright (C) 2013, Russell Bryant
5#
6# Russell Bryant <russell@russellbryant.net>
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 tables
20
21Revision ID: 4da0c5f79a9c
22Revises: None
23Create Date: 2013-07-28 12:28:03.091587
24
25"""
26
27# revision identifiers, used by Alembic.
28revision = '4da0c5f79a9c'
29down_revision = None
30
31from alembic import op
32import sqlalchemy as sa
33from sqlalchemy.sql import quoted_name
34from sqlalchemy.dialects.postgresql import ENUM
35
36YESNO_VALUES = ['yes', 'no']
37TYPE_VALUES = ['friend', 'user', 'peer']
38
39SIP_TRANSPORT_VALUES = ['udp', 'tcp', 'tls', 'ws', 'wss', 'udp,tcp', 'tcp,udp']
40SIP_DTMFMODE_VALUES = ['rfc2833', 'info', 'shortinfo', 'inband', 'auto']
41SIP_DIRECTMEDIA_VALUES = ['yes', 'no', 'nonat', 'update']
42SIP_PROGRESSINBAND_VALUES = ['yes', 'no', 'never']
43SIP_SESSION_TIMERS_VALUES = ['accept', 'refuse', 'originate']
44SIP_SESSION_REFRESHER_VALUES = ['uac', 'uas']
45SIP_CALLINGPRES_VALUES = ['allowed_not_screened', 'allowed_passed_screen',
46 'allowed_failed_screen', 'allowed',
47 'prohib_not_screened', 'prohib_passed_screen',
48 'prohib_failed_screen', 'prohib']
49
50IAX_REQUIRECALLTOKEN_VALUES = ['yes', 'no', 'auto']
51IAX_ENCRYPTION_VALUES = ['yes', 'no', 'aes128']
52IAX_TRANSFER_VALUES = ['yes', 'no', 'mediaonly']
53
54MOH_MODE_VALUES = ['custom', 'files', 'mp3nb', 'quietmp3nb', 'quietmp3']
55
56
57def upgrade():
58 op.create_table(
59 'sippeers',
60 sa.Column('id', sa.Integer, primary_key=True, nullable=False,
61 autoincrement=True),
62 sa.Column('name', sa.String(40), nullable=False, unique=True),
63 sa.Column('ipaddr', sa.String(45)),
64 sa.Column('port', sa.Integer),
65 sa.Column('regseconds', sa.Integer),
66 sa.Column('defaultuser', sa.String(40)),
67 sa.Column('fullcontact', sa.String(80)),
68 sa.Column('regserver', sa.String(20)),
69 sa.Column('useragent', sa.String(20)),
70 sa.Column('lastms', sa.Integer),
71 sa.Column('host', sa.String(40)),
72 sa.Column('type', sa.Enum(*TYPE_VALUES, name='type_values')),
73 sa.Column('context', sa.String(40)),
74 sa.Column('permit', sa.String(95)),
75 sa.Column('deny', sa.String(95)),
76 sa.Column('secret', sa.String(40)),
77 sa.Column('md5secret', sa.String(40)),
78 sa.Column('remotesecret', sa.String(40)),
79 sa.Column('transport', sa.Enum(*SIP_TRANSPORT_VALUES,
80 name='sip_transport_values')),
81 sa.Column('dtmfmode', sa.Enum(*SIP_DTMFMODE_VALUES,
82 name='sip_dtmfmode_values')),
83 sa.Column('directmedia', sa.Enum(*SIP_DIRECTMEDIA_VALUES,
84 name='sip_directmedia_values')),
85 sa.Column('nat', sa.String(29)),
86 sa.Column('callgroup', sa.String(40)),
87 sa.Column('pickupgroup', sa.String(40)),
88 sa.Column('language', sa.String(40)),
89 sa.Column('disallow', sa.String(200)),
90 sa.Column('allow', sa.String(200)),
91 sa.Column('insecure', sa.String(40)),
92 sa.Column('trustrpid', sa.Enum(*YESNO_VALUES,
93 name='yes_no_values')),
94 sa.Column('progressinband', sa.Enum(*SIP_PROGRESSINBAND_VALUES,
95 name='sip_progressinband_values')),
96 sa.Column('promiscredir', sa.Enum(*YESNO_VALUES,
97 name='yes_no_values')),
98 sa.Column('useclientcode', sa.Enum(*YESNO_VALUES,
99 name='yes_no_values')),
100 sa.Column('accountcode', sa.String(40)),
101 sa.Column('setvar', sa.String(200)),
102 sa.Column('callerid', sa.String(40)),
103 sa.Column('amaflags', sa.String(40)),
104 sa.Column('callcounter', sa.Enum(*YESNO_VALUES,
105 name='yes_no_values')),
106 sa.Column('busylevel', sa.Integer),
107 sa.Column('allowoverlap', sa.Enum(*YESNO_VALUES,
108 name='yes_no_values')),
109 sa.Column('allowsubscribe', sa.Enum(*YESNO_VALUES,
110 name='yes_no_values')),
111 sa.Column('videosupport', sa.Enum(*YESNO_VALUES,
112 name='yes_no_values')),
113 sa.Column('maxcallbitrate', sa.Integer),
114 sa.Column('rfc2833compensate', sa.Enum(*YESNO_VALUES,
115 name='yes_no_values')),
116 sa.Column('mailbox', sa.String(40)),
117 sa.Column('session-timers', sa.Enum(*SIP_SESSION_TIMERS_VALUES,
118 name='sip_session_timers_values')),
119 sa.Column('session-expires', sa.Integer),
120 sa.Column('session-minse', sa.Integer),
121 sa.Column('session-refresher', sa.Enum(*SIP_SESSION_REFRESHER_VALUES,
122 name='sip_session_refresher_values')),
123 sa.Column('t38pt_usertpsource', sa.String(40)),
124 sa.Column('regexten', sa.String(40)),
125 sa.Column('fromdomain', sa.String(40)),
126 sa.Column('fromuser', sa.String(40)),
127 sa.Column(quoted_name('qualify', True), sa.String(40)),
128 sa.Column('defaultip', sa.String(45)),
129 sa.Column('rtptimeout', sa.Integer),
130 sa.Column('rtpholdtimeout', sa.Integer),
131 sa.Column('sendrpid', sa.Enum(*YESNO_VALUES,
132 name='yes_no_values')),
133 sa.Column('outboundproxy', sa.String(40)),
134 sa.Column('callbackextension', sa.String(40)),
135 sa.Column('timert1', sa.Integer),
136 sa.Column('timerb', sa.Integer),
137 sa.Column('qualifyfreq', sa.Integer),
138 sa.Column('constantssrc', sa.Enum(*YESNO_VALUES,
139 name='yes_no_values')),
140 sa.Column('contactpermit', sa.String(95)),
141 sa.Column('contactdeny', sa.String(95)),
142 sa.Column('usereqphone', sa.Enum(*YESNO_VALUES, name='yes_no_values')),
143 sa.Column('textsupport', sa.Enum(*YESNO_VALUES, name='yes_no_values')),
144 sa.Column('faxdetect', sa.Enum(*YESNO_VALUES, name='yes_no_values')),
145 sa.Column('buggymwi', sa.Enum(*YESNO_VALUES, name='yes_no_values')),
146 sa.Column('auth', sa.String(40)),
147 sa.Column('fullname', sa.String(40)),
148 sa.Column('trunkname', sa.String(40)),
149 sa.Column('cid_number', sa.String(40)),
150 sa.Column('callingpres', sa.Enum(*SIP_CALLINGPRES_VALUES,
151 name='sip_callingpres_values')),
152 sa.Column('mohinterpret', sa.String(40)),
153 sa.Column('mohsuggest', sa.String(40)),
154 sa.Column('parkinglot', sa.String(40)),
155 sa.Column('hasvoicemail', sa.Enum(*YESNO_VALUES,
156 name='yes_no_values')),
157 sa.Column('subscribemwi', sa.Enum(*YESNO_VALUES,
158 name='yes_no_values')),
159 sa.Column('vmexten', sa.String(40)),
160 sa.Column('autoframing', sa.Enum(*YESNO_VALUES, name='yes_no_values')),
161 sa.Column('rtpkeepalive', sa.Integer),
162 sa.Column('call-limit', sa.Integer),
163 sa.Column('g726nonstandard', sa.Enum(*YESNO_VALUES,
164 name='yes_no_values')),
165 sa.Column('ignoresdpversion', sa.Enum(*YESNO_VALUES,
166 name='yes_no_values')),
167 sa.Column('allowtransfer', sa.Enum(*YESNO_VALUES,
168 name='yes_no_values')),
169 sa.Column('dynamic', sa.Enum(*YESNO_VALUES, name='yes_no_values')),
170 sa.Column('path', sa.String(256)),
171 sa.Column('supportpath', sa.Enum(*YESNO_VALUES, name='yes_no_values'))
172 )
173 op.create_index('sippeers_name', 'sippeers', ['name'])
174 op.create_index('sippeers_name_host', 'sippeers', ['name', 'host'])
175 op.create_index('sippeers_ipaddr_port', 'sippeers', ['ipaddr', 'port'])
176 op.create_index('sippeers_host_port', 'sippeers', ['host', 'port'])
177
178 op.create_table(
179 'iaxfriends',
180 sa.Column('id', sa.Integer, primary_key=True, nullable=False,
181 autoincrement=True),
182 sa.Column('name', sa.String(40), nullable=False, unique=True),
183 sa.Column('type', sa.Enum(*TYPE_VALUES, name='type_values')),
184 sa.Column('username', sa.String(40)),
185 sa.Column('mailbox', sa.String(40)),
186 sa.Column('secret', sa.String(40)),
187 sa.Column('dbsecret', sa.String(40)),
188 sa.Column('context', sa.String(40)),
189 sa.Column('regcontext', sa.String(40)),
190 sa.Column('host', sa.String(40)),
191 sa.Column('ipaddr', sa.String(40)),
192 sa.Column('port', sa.Integer),
193 sa.Column('defaultip', sa.String(20)),
194 sa.Column('sourceaddress', sa.String(20)),
195 sa.Column('mask', sa.String(20)),
196 sa.Column('regexten', sa.String(40)),
197 sa.Column('regseconds', sa.Integer),
198 sa.Column('accountcode', sa.String(20)),
199 sa.Column('mohinterpret', sa.String(20)),
200 sa.Column('mohsuggest', sa.String(20)),
201 sa.Column('inkeys', sa.String(40)),
202 sa.Column('outkeys', sa.String(40)),
203 sa.Column('language', sa.String(10)),
204 sa.Column('callerid', sa.String(100)),
205 sa.Column('cid_number', sa.String(40)),
206 sa.Column('sendani', sa.Enum(*YESNO_VALUES, name='yes_no_values')),
207 sa.Column('fullname', sa.String(40)),
208 sa.Column('trunk', sa.Enum(*YESNO_VALUES, name='yes_no_values')),
209 sa.Column('auth', sa.String(20)),
210 sa.Column('maxauthreq', sa.Integer),
211 sa.Column('requirecalltoken', sa.Enum(*IAX_REQUIRECALLTOKEN_VALUES,
212 name='iax_requirecalltoken_values')),
213 sa.Column('encryption', sa.Enum(*IAX_ENCRYPTION_VALUES,
214 name='iax_encryption_values')),
215 sa.Column('transfer', sa.Enum(*IAX_TRANSFER_VALUES,
216 name='iax_transfer_values')),
217 sa.Column('jitterbuffer', sa.Enum(*YESNO_VALUES,
218 name='yes_no_values')),
219 sa.Column('forcejitterbuffer', sa.Enum(*YESNO_VALUES,
220 name='yes_no_values')),
221 sa.Column('disallow', sa.String(200)),
222 sa.Column('allow', sa.String(200)),
223 sa.Column('codecpriority', sa.String(40)),
224 sa.Column(quoted_name('qualify', True), sa.String(10)),
225 sa.Column('qualifysmoothing',
226 sa.Enum(*YESNO_VALUES, name='yes_no_values')),
227 sa.Column('qualifyfreqok', sa.String(10)),
228 sa.Column('qualifyfreqnotok', sa.String(10)),
229 sa.Column('timezone', sa.String(20)),
230 sa.Column('adsi', sa.Enum(*YESNO_VALUES, name='yes_no_values')),
231 sa.Column('amaflags', sa.String(20)),
232 sa.Column('setvar', sa.String(200))
233 )
234 op.create_index('iaxfriends_name', 'iaxfriends', ['name'])
235 op.create_index('iaxfriends_name_host', 'iaxfriends', ['name', 'host'])
236 op.create_index('iaxfriends_name_ipaddr_port', 'iaxfriends',
237 ['name', 'ipaddr', 'port'])
238 op.create_index('iaxfriends_ipaddr_port', 'iaxfriends', ['ipaddr', 'port'])
239 op.create_index('iaxfriends_host_port', 'iaxfriends', ['host', 'port'])
240
241 op.create_table(
242 'voicemail',
243 sa.Column('uniqueid', sa.Integer, primary_key=True, nullable=False,
244 autoincrement=True),
245 sa.Column('context', sa.String(80), nullable=False),
246 sa.Column('mailbox', sa.String(80), nullable=False),
247 sa.Column('password', sa.String(80), nullable=False),
248 sa.Column('fullname', sa.String(80)),
249 sa.Column('alias', sa.String(80)),
250 sa.Column('email', sa.String(80)),
251 sa.Column('pager', sa.String(80)),
252 sa.Column('attach', sa.Enum(*YESNO_VALUES, name='yes_no_values')),
253 sa.Column('attachfmt', sa.String(10)),
254 sa.Column('serveremail', sa.String(80)),
255 sa.Column('language', sa.String(20)),
256 sa.Column('tz', sa.String(30)),
257 sa.Column('deletevoicemail', sa.Enum(*YESNO_VALUES,
258 name='yes_no_values')),
259 sa.Column('saycid', sa.Enum(*YESNO_VALUES,
260 name='yes_no_values')),
261 sa.Column('sendvoicemail', sa.Enum(*YESNO_VALUES,
262 name='yes_no_values')),
263 sa.Column('review', sa.Enum(*YESNO_VALUES,
264 name='yes_no_values')),
265 sa.Column('tempgreetwarn', sa.Enum(*YESNO_VALUES,
266 name='yes_no_values')),
267 sa.Column('operator', sa.Enum(*YESNO_VALUES,
268 name='yes_no_values')),
269 sa.Column('envelope', sa.Enum(*YESNO_VALUES,
270 name='yes_no_values')),
271 sa.Column('sayduration', sa.Integer),
272 sa.Column('forcename', sa.Enum(*YESNO_VALUES,
273 name='yes_no_values')),
274 sa.Column('forcegreetings', sa.Enum(*YESNO_VALUES,
275 name='yes_no_values')),
276 sa.Column('callback', sa.String(80)),
277 sa.Column('dialout', sa.String(80)),
278 sa.Column('exitcontext', sa.String(80)),
279 sa.Column('maxmsg', sa.Integer),
280 sa.Column('volgain', sa.Numeric(precision=5, scale=2)),
281 sa.Column('imapuser', sa.String(80)),
282 sa.Column('imappassword', sa.String(80)),
283 sa.Column('imapserver', sa.String(80)),
284 sa.Column('imapport', sa.String(8)),
285 sa.Column('imapflags', sa.String(80)),
286 sa.Column('stamp', sa.DateTime())
287 )
288 op.create_index('voicemail_mailbox', 'voicemail', ['mailbox'])
289 op.create_index('voicemail_context', 'voicemail', ['context'])
290 op.create_index('voicemail_mailbox_context', 'voicemail',
291 ['mailbox', 'context'])
292 op.create_index('voicemail_imapuser', 'voicemail', ['imapuser'])
293
294 op.create_table(
295 'meetme',
296 sa.Column('bookid', sa.Integer, primary_key=True, nullable=False,
297 autoincrement=True),
298 sa.Column('confno', sa.String(80), nullable=False),
299 sa.Column('starttime', sa.DateTime()),
300 sa.Column('endtime', sa.DateTime()),
301 sa.Column('pin', sa.String(20)),
302 sa.Column('adminpin', sa.String(20)),
303 sa.Column('opts', sa.String(20)),
304 sa.Column('adminopts', sa.String(20)),
305 sa.Column('recordingfilename', sa.String(80)),
306 sa.Column('recordingformat', sa.String(10)),
307 sa.Column('maxusers', sa.Integer),
308 sa.Column('members', sa.Integer, nullable=False, default=0)
309 )
310 op.create_index('meetme_confno_start_end', 'meetme',
311 ['confno', 'starttime', 'endtime'])
312
313 op.create_table(
314 'musiconhold',
315 sa.Column('name', sa.String(80), primary_key=True, nullable=False),
316 sa.Column('mode', sa.Enum(*MOH_MODE_VALUES, name='moh_mode_values')),
317 sa.Column('directory', sa.String(255)),
318 sa.Column('application', sa.String(255)),
319 sa.Column('digit', sa.String(1)),
320 sa.Column('sort', sa.String(10)),
321 sa.Column('format', sa.String(10)),
322 sa.Column('stamp', sa.DateTime())
323 )
324
325
327 context = op.get_context()
328
329 op.drop_table('sippeers')
330 op.drop_table('iaxfriends')
331 op.drop_table('voicemail')
332 op.drop_table('meetme')
333 op.drop_table('musiconhold')
334
335 enums = ['type_values', 'yes_no_values',
336 'sip_transport_values','sip_dtmfmode_values','sip_directmedia_values',
337 'sip_progressinband_values','sip_session_timers_values','sip_session_refresher_values',
338 'sip_callingpres_values','iax_requirecalltoken_values','iax_encryption_values',
339 'iax_transfer_values','moh_mode_values']
340
341 if context.bind.dialect.name == 'postgresql':
342 for e in enums:
343 ENUM(name=e).drop(op.get_bind(), checkfirst=False)