forked from twilio/OpenVBX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
openvbx.sql
315 lines (280 loc) · 9.99 KB
/
openvbx.sql
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
SET foreign_key_checks=0;
DROP TABLE IF EXISTS `flows`;
CREATE TABLE IF NOT EXISTS `flows` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(100) NOT NULL,
`user_id` int(11) NOT NULL,
`created` datetime default NULL,
`updated` datetime default NULL,
`data` text NULL,
`sms_data` text NULL,
`tenant_id` BIGINT(20) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `name` (`name`, `tenant_id`)
) ENGINE=InnoDB CHARSET=UTF8;
DROP TABLE IF EXISTS `groups`;
CREATE TABLE IF NOT EXISTS `groups` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(100) default NULL,
`is_active` tinyint NOT NULL DEFAULT 1,
`tenant_id` BIGINT(20) NOT NULL,
PRIMARY KEY (`id`),
INDEX(`tenant_id`)
) ENGINE=InnoDB CHARSET=UTF8;
DROP TABLE IF EXISTS `groups_users`;
CREATE TABLE IF NOT EXISTS `groups_users` (
`id` int(11) NOT NULL auto_increment,
`group_id` int(11) NOT NULL,
`user_id` int(11) NOT NULL,
`tenant_id` BIGINT(20) NOT NULL,
PRIMARY KEY (`id`),
KEY `group_id` (`group_id`),
INDEX(`tenant_id`)
) ENGINE=InnoDB CHARSET=UTF8;
DROP TABLE IF EXISTS `audio_files`;
CREATE TABLE IF NOT EXISTS `audio_files` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`label` varchar(255) DEFAULT NULL,
`user_id` int(11) NOT NULL,
`url` varchar(255) DEFAULT NULL,
`recording_call_sid` varchar(100) DEFAULT NULL,
`tag` varchar(100) DEFAULT NULL,
`cancelled` TINYINT DEFAULT 0,
`created` datetime DEFAULT NULL,
`updated` datetime DEFAULT NULL,
`tenant_id` BIGINT(20) NOT NULL,
PRIMARY KEY (`id`),
INDEX(`user_id`),
INDEX(`url`),
INDEX(`recording_call_sid`),
INDEX(`tag`),
INDEX(`tenant_id`)
) ENGINE=InnoDB DEFAULT CHARSET=UTF8;
DROP TABLE IF EXISTS `messages`;
CREATE TABLE IF NOT EXISTS `messages` (
`id` int(11) NOT NULL auto_increment,
`created` datetime default NULL,
`updated` datetime default NULL,
`read` datetime default NULL,
`call_sid` varchar(40) default NULL,
`caller` varchar(20) default NULL,
`called` varchar(20) default NULL,
`type` varchar(10) default NULL,
`status` varchar(10) default NULL,
`content_url` varchar(255) default NULL,
`content_text` varchar(5000) default NULL,
`notes` varchar(5000) default NULL,
`size` smallint(6) default NULL,
`assigned_to` BIGINT NULL,
`archived` TINYINT NOT NULL DEFAULT 0,
`ticket_status` ENUM('open', 'closed', 'pending') NOT NULL DEFAULT 'open',
`tenant_id` BIGINT(20) NOT NULL,
PRIMARY KEY (`id`),
KEY `call_sid` (`call_sid`),
INDEX(`tenant_id`)
) ENGINE=InnoDB CHARSET=UTF8;
DROP TABLE IF EXISTS `numbers`;
CREATE TABLE IF NOT EXISTS `numbers` (
`id` int(11) NOT NULL auto_increment,
`user_id` int(11) NOT NULL,
`name` varchar(100) default NULL,
`value` TEXT NOT NULL,
`is_active` tinyint(1) default 1,
`sms` tinyint(1) default 0,
`sequence` smallint(6) default NULL,
`tenant_id` BIGINT(20) NOT NULL,
PRIMARY KEY (`id`),
KEY `user_id` (`user_id`),
INDEX(`tenant_id`)
) ENGINE=InnoDB CHARSET=UTF8;
DROP TABLE IF EXISTS `users`;
CREATE TABLE IF NOT EXISTS `users` (
`id` int(11) NOT NULL auto_increment,
`is_admin` tinyint(1) default NULL,
`is_active` tinyint(1) default 1,
`first_name` varchar(100) default NULL,
`last_name` varchar(100) default NULL,
`password` varchar(40) default NULL,
`invite_code` varchar(32) NULL,
`email` varchar(200) default NULL,
`pin` varchar(40) default NULL,
`notification` varchar(20) default NULL,
`auth_type` TINYINT NOT NULL default 1,
`voicemail` TEXT NOT NULL,
`tenant_id` BIGINT(20) NOT NULL,
`last_seen` datetime DEFAULT NULL,
`last_login` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `email` (`email`, `tenant_id`),
INDEX(`tenant_id`)
) ENGINE=InnoDB CHARSET=UTF8;
DROP TABLE IF EXISTS `auth_types`;
CREATE TABLE IF NOT EXISTS `auth_types` (
`id` tinyint NOT NULL AUTO_INCREMENT,
`description` VARCHAR(255) NOT NULL,
`tenant_id` BIGINT(20) NOT NULL,
PRIMARY KEY (`id`),
INDEX(`tenant_id`)
) ENGINE=InnoDB CHARSET=UTF8;
DROP TABLE IF EXISTS `rest_access`;
CREATE TABLE IF NOT EXISTS `rest_access` (
`key` VARCHAR(32) NOT NULL,
`locked` TINYINT NOT NULL DEFAULT 0,
`created` DATETIME NOT NULL,
`user_id` INT NOT NULL,
`tenant_id` BIGINT(20) NOT NULL,
PRIMARY KEY (`key`),
INDEX(`tenant_id`)
) ENGINE=InnoDB CHARSET=UTF8;
DROP TABLE IF EXISTS `user_messages`;
CREATE TABLE IF NOT EXISTS `user_messages` (
user_id INT(11) NOT NULL,
message_id INT(11) NOT NULL,
`tenant_id` BIGINT(20) NOT NULL,
PRIMARY KEY(user_id, message_id),
INDEX(`tenant_id`)
) ENGINE=InnoDB CHARSET=UTF8;
CREATE TABLE IF NOT EXISTS `group_messages` (
group_id INT(11) NOT NULL,
message_id INT(11) NOT NULL,
`tenant_id` BIGINT(20) NOT NULL,
PRIMARY KEY(group_id, message_id),
INDEX(`tenant_id`)
) ENGINE=InnoDB CHARSET=UTF8;
DROP TABLE IF EXISTS `user_annotations`;
CREATE TABLE IF NOT EXISTS `user_annotations` (
user_id INT(11) NOT NULL,
annotation_id BIGINT NOT NULL,
`tenant_id` BIGINT(20) NOT NULL,
PRIMARY KEY(user_id, annotation_id),
INDEX(`tenant_id`)
) ENGINE=InnoDB CHARSET=UTF8;
DROP TABLE IF EXISTS `group_annotations`;
CREATE TABLE IF NOT EXISTS `group_annotations` (
group_id INT(11) NOT NULL,
annotation_id BIGINT NOT NULL,
`tenant_id` BIGINT(20) NOT NULL,
PRIMARY KEY(group_id, annotation_id),
INDEX(`tenant_id`)
) ENGINE=InnoDB CHARSET=UTF8;
DROP TABLE IF EXISTS `annotations`;
CREATE TABLE IF NOT EXISTS `annotations` (
`id` bigint(20) NOT NULL auto_increment,
`annotation_type` tinyint(4) NOT NULL,
`message_id` bigint(20) NOT NULL,
`user_id` int(11) NOT NULL,
`description` text character set latin1 NOT NULL,
`created` datetime NOT NULL,
`tenant_id` BIGINT(20) NOT NULL,
PRIMARY KEY (`id`),
KEY `annotation_type_message_id` (`annotation_type`,`message_id`,`created`),
KEY `created` (`created`),
INDEX(`tenant_id`)
) ENGINE=InnoDB CHARSET=UTF8;
DROP TABLE IF EXISTS `annotation_types`;
CREATE TABLE IF NOT EXISTS `annotation_types` (
id TINYINT NOT NULL AUTO_INCREMENT,
description VARCHAR(32) NOT NULL,
`tenant_id` BIGINT(20) NOT NULL,
PRIMARY KEY(id),
INDEX(`tenant_id`)
) ENGINE=InnoDB CHARSET=UTF8;
DROP TABLE IF EXISTS `tenants`;
CREATE TABLE IF NOT EXISTS `tenants` (
id BIGINT AUTO_INCREMENT,
name VARCHAR(255) NOT NULL,
url_prefix VARCHAR(255) NOT NULL,
local_prefix VARCHAR(1000) NOT NULL,
active TINYINT NOT NULL DEFAULT 1,
PRIMARY KEY(id),
INDEX(name),
INDEX url_prefix (url_prefix)
) ENGINE=InnoDB CHARSET=UTF8;
DROP TABLE IF EXISTS `settings`;
CREATE TABLE IF NOT EXISTS `settings` (
id BIGINT AUTO_INCREMENT,
tenant_id BIGINT NOT NULL,
name VARCHAR(32) NOT NULL,
value VARCHAR(255) NOT NULL,
PRIMARY KEY(id),
INDEX(name),
INDEX(tenant_id, name)
) ENGINE=InnoDB CHARSET=UTF8;
DROP TABLE IF EXISTS `flow_store`;
CREATE TABLE IF NOT EXISTS `flow_store` (
`key` varchar(255) NOT NULL,
`value` TEXT NULL,
`flow_id` int(11) NOT NULL,
`tenant_id` BIGINT(20) NOT NULL,
UNIQUE KEY `key_flow` (`key`, `flow_id`),
INDEX(`key`, `flow_id`),
INDEX(`tenant_id`)
) ENGINE=InnoDB CHARSET=UTF8;
DROP TABLE IF EXISTS `plugin_store`;
CREATE TABLE IF NOT EXISTS `plugin_store` (
`key` varchar(255) NOT NULL,
`value` TEXT NULL,
`plugin_id` varchar(34) NOT NULL,
`tenant_id` BIGINT(20) NOT NULL,
UNIQUE KEY `key_plugin` (`key`, `plugin_id`, `tenant_id`),
INDEX(`key`, `plugin_id`),
INDEX(`tenant_id`)
) ENGINE=InnoDB CHARSET=UTF8;
ALTER TABLE settings ADD FOREIGN KEY(tenant_id) REFERENCES tenants(id);
ALTER TABLE user_messages ADD FOREIGN KEY(user_id) REFERENCES users(id);
ALTER TABLE user_messages ADD FOREIGN KEY(message_id) REFERENCES messages(id);
ALTER TABLE group_messages ADD FOREIGN KEY(group_id) REFERENCES groups(id);
ALTER TABLE group_messages ADD FOREIGN KEY(message_id) REFERENCES messages(id);
ALTER TABLE numbers ADD FOREIGN KEY(user_id) REFERENCES users(id);
ALTER TABLE flows ADD FOREIGN KEY(user_id) REFERENCES users(id);
ALTER TABLE users ADD FOREIGN KEY(auth_type) REFERENCES auth_types(id);
ALTER TABLE groups_users ADD FOREIGN KEY(user_id) REFERENCES users(id);
ALTER TABLE groups_users ADD FOREIGN KEY(group_id) REFERENCES groups(id);
ALTER TABLE flows ADD FOREIGN KEY(tenant_id) REFERENCES tenants(id);
ALTER TABLE groups ADD FOREIGN KEY(tenant_id) REFERENCES tenants(id);
ALTER TABLE groups_users ADD FOREIGN KEY(tenant_id) REFERENCES tenants(id);
ALTER TABLE audio_files ADD FOREIGN KEY(tenant_id) REFERENCES tenants(id);
ALTER TABLE messages ADD FOREIGN KEY(tenant_id) REFERENCES tenants(id);
ALTER TABLE numbers ADD FOREIGN KEY(tenant_id) REFERENCES tenants(id);
ALTER TABLE users ADD FOREIGN KEY(tenant_id) REFERENCES tenants(id);
ALTER TABLE auth_types ADD FOREIGN KEY(tenant_id) REFERENCES tenants(id);
ALTER TABLE rest_access ADD FOREIGN KEY(tenant_id) REFERENCES tenants(id);
ALTER TABLE user_messages ADD FOREIGN KEY(tenant_id) REFERENCES tenants(id);
ALTER TABLE group_messages ADD FOREIGN KEY(tenant_id) REFERENCES tenants(id);
ALTER TABLE user_annotations ADD FOREIGN KEY(tenant_id) REFERENCES tenants(id);
ALTER TABLE group_annotations ADD FOREIGN KEY(tenant_id) REFERENCES tenants(id);
ALTER TABLE annotations ADD FOREIGN KEY(tenant_id) REFERENCES tenants(id);
ALTER TABLE annotation_types ADD FOREIGN KEY(tenant_id) REFERENCES tenants(id);
ALTER TABLE flow_store ADD FOREIGN KEY(tenant_id) REFERENCES tenants(id);
ALTER TABLE plugin_store ADD FOREIGN KEY(tenant_id) REFERENCES tenants(id);
INSERT INTO tenants
(name, url_prefix, local_prefix)
VALUES
('default', '', '');
INSERT INTO annotation_types (description, tenant_id)
VALUES
('called', 1),
('read', 1),
('noted', 1),
('changed', 1),
('labeled', 1),
('sms', 1);
INSERT INTO auth_types (description, tenant_id)
VALUES
('openvbx', 1),
('google', 1);
INSERT INTO settings
(name, value, tenant_id)
VALUES
('dash_rss', '', 1),
('theme', '', 1),
('version', '0.90', 1),
('iphone_theme', '', 1),
('enable_sandbox_number', 1, 1),
('twilio_endpoint', 'https://api.twilio.com/2010-04-01', 1),
('recording_host','',1);
INSERT INTO groups
(name, is_active, tenant_id)
VALUES
('Sales', 1, 1),
('Support', 1, 1);