-
-
Notifications
You must be signed in to change notification settings - Fork 150
/
messenger.sql
309 lines (257 loc) · 8.76 KB
/
messenger.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
-- MySQL Script generated by MySQL Workbench
-- Sat Jan 11 19:40:52 2020
-- Model: New Model Version: 1.0
-- MySQL Workbench Forward Engineering
SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';
-- -----------------------------------------------------
-- Schema messenger
-- -----------------------------------------------------
DROP SCHEMA IF EXISTS `messenger` ;
-- -----------------------------------------------------
-- Schema messenger
-- -----------------------------------------------------
CREATE SCHEMA IF NOT EXISTS `messenger` DEFAULT CHARACTER SET utf8 ;
SHOW WARNINGS;
USE `messenger` ;
-- -----------------------------------------------------
-- Table `users`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `users` ;
SHOW WARNINGS;
CREATE TABLE IF NOT EXISTS `users` (
`id` INT NOT NULL AUTO_INCREMENT,
`phone` VARCHAR(16) NOT NULL,
`email` VARCHAR(255) NOT NULL,
`password` VARCHAR(40) NOT NULL,
`first_name` VARCHAR(20) NOT NULL DEFAULT '',
`last_name` VARCHAR(20) NOT NULL DEFAULT '',
`middle_name` VARCHAR(20) NOT NULL DEFAULT '',
`is_active` TINYINT(1) NOT NULL DEFAULT 0,
`is_reported` TINYINT(1) NOT NULL DEFAULT 0,
`is_blocked` TINYINT(1) NOT NULL DEFAULT 0,
`preferences` TEXT NOT NULL DEFAULT '',
`created_at` DATETIME NOT NULL,
`updated_at` DATETIME NOT NULL,
PRIMARY KEY (`id`))
ENGINE = InnoDB;
SHOW WARNINGS;
CREATE UNIQUE INDEX `phone_UNIQUE` ON `users` (`phone` ASC) VISIBLE;
SHOW WARNINGS;
CREATE UNIQUE INDEX `email_UNIQUE` ON `users` (`email` ASC) VISIBLE;
SHOW WARNINGS;
-- -----------------------------------------------------
-- Table `contacts`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `contacts` ;
SHOW WARNINGS;
CREATE TABLE IF NOT EXISTS `contacts` (
`id` INT NOT NULL COMMENT 'Sync the contacts to this table',
`first_name` VARCHAR(20) NOT NULL DEFAULT '',
`middle_name` VARCHAR(20) NOT NULL DEFAULT '',
`last_name` VARCHAR(20) NOT NULL DEFAULT '',
`phone` VARCHAR(14) NOT NULL,
`email` VARCHAR(255) NOT NULL,
`created_at` VARCHAR(45) NOT NULL,
PRIMARY KEY (`id`))
ENGINE = InnoDB;
SHOW WARNINGS;
-- -----------------------------------------------------
-- Table `conversation`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `conversation` ;
SHOW WARNINGS;
CREATE TABLE IF NOT EXISTS `conversation` (
`id` INT NOT NULL AUTO_INCREMENT,
`title` VARCHAR(40) NOT NULL,
`creator_id` INT NOT NULL,
`channel_id` VARCHAR(45) NOT NULL,
`created_at` DATETIME NOT NULL,
`updated_at` DATETIME NOT NULL,
`deleted_at` DATETIME NOT NULL,
PRIMARY KEY (`id`))
ENGINE = InnoDB;
SHOW WARNINGS;
-- -----------------------------------------------------
-- Table `messages`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `messages` ;
SHOW WARNINGS;
CREATE TABLE IF NOT EXISTS `messages` (
`id` INT NOT NULL,
`guid` VARCHAR(100) NOT NULL,
`conversation_id` INT NOT NULL,
`sender_id` INT NOT NULL,
`message_type` ENUM('text', 'image', 'vedio', 'audio') NOT NULL,
`message` VARCHAR(255) NOT NULL DEFAULT '',
`created_at` DATETIME NOT NULL,
`deleted_at` DATETIME NOT NULL,
PRIMARY KEY (`id`))
ENGINE = InnoDB;
SHOW WARNINGS;
-- -----------------------------------------------------
-- Table `participants`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `participants` ;
SHOW WARNINGS;
CREATE TABLE IF NOT EXISTS `participants` (
`id` INT NOT NULL AUTO_INCREMENT,
`conversation_id` INT NOT NULL,
`users_id` INT NOT NULL,
`type` ENUM('single', 'group') NOT NULL,
`created_at` DATETIME NOT NULL,
`updated_at` DATETIME NOT NULL,
PRIMARY KEY (`id`))
ENGINE = InnoDB;
SHOW WARNINGS;
CREATE UNIQUE INDEX `participants_UNIQUE` ON `participants` (
`conversation_id`, `users_id`) VISIBLE;
SHOW WARNINGS;
-- -----------------------------------------------------
-- Table `reports`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `reports` ;
SHOW WARNINGS;
CREATE TABLE IF NOT EXISTS `reports` (
`id` INT NOT NULL AUTO_INCREMENT,
`users_id` INT NOT NULL,
`participants_id` INT NOT NULL,
`report_type` VARCHAR(45) NOT NULL,
`notes` TEXT NOT NULL,
`status` ENUM('pending', 'resolved') NOT NULL DEFAULT 'pending',
`created_at` DATETIME NOT NULL,
PRIMARY KEY (`id`))
ENGINE = InnoDB;
SHOW WARNINGS;
-- -----------------------------------------------------
-- Table `block_list`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `block_list` ;
SHOW WARNINGS;
CREATE TABLE IF NOT EXISTS `block_list` (
`id` INT NOT NULL AUTO_INCREMENT,
`users_id` INT NOT NULL,
`participants_id` INT NOT NULL,
`created_at` DATETIME NOT NULL,
PRIMARY KEY (`id`))
ENGINE = InnoDB;
SHOW WARNINGS;
-- -----------------------------------------------------
-- Table `deleted_conversations`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `deleted_conversations` ;
SHOW WARNINGS;
CREATE TABLE IF NOT EXISTS `deleted_conversations` (
`id` INT NOT NULL,
`conversation_id` INT NOT NULL,
`users_id` INT NOT NULL,
`created_at` DATETIME NOT NULL,
PRIMARY KEY (`id`))
ENGINE = InnoDB;
SHOW WARNINGS;
-- -----------------------------------------------------
-- Table `devices`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `devices` ;
SHOW WARNINGS;
CREATE TABLE IF NOT EXISTS `devices` (
`id` INT NOT NULL AUTO_INCREMENT,
`users_id` INT NOT NULL,
`device_id` VARCHAR(120) NOT NULL,
`type` ENUM('APPLE') NOT NULL,
`device_token` VARCHAR(120) NOT NULL,
`created_at` DATETIME NOT NULL,
`updated_at` DATETIME NOT NULL,
PRIMARY KEY (`id`))
ENGINE = InnoDB;
SHOW WARNINGS;
-- -----------------------------------------------------
-- Table `access`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `access` ;
SHOW WARNINGS;
CREATE TABLE IF NOT EXISTS `access` (
`id` INT NOT NULL,
`users_id` INT NOT NULL,
`devices_id` INT NOT NULL,
`token` VARCHAR(60) NOT NULL,
`created_at` DATETIME NOT NULL,
`deleted_at` DATETIME NOT NULL,
PRIMARY KEY (`id`))
ENGINE = InnoDB;
SHOW WARNINGS;
-- -----------------------------------------------------
-- Table `deleted_messages`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `deleted_messages` ;
SHOW WARNINGS;
CREATE TABLE IF NOT EXISTS `deleted_messages` (
`id` INT NOT NULL AUTO_INCREMENT,
`messages_id` INT NOT NULL,
`users_id` INT NOT NULL,
`created_at` DATETIME NOT NULL,
`updated_at` DATETIME NOT NULL,
PRIMARY KEY (`id`))
ENGINE = InnoDB;
SHOW WARNINGS;
-- -----------------------------------------------------
-- Table `user_contact`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `user_contact` ;
SHOW WARNINGS;
CREATE TABLE IF NOT EXISTS `user_contact` (
`user_id` INT NOT NULL,
`contact_id` INT NOT NULL,
`first_name` VARCHAR(45) NOT NULL DEFAULT '',
`last_name` VARCHAR(45) NOT NULL DEFAULT '',
`created_at` DATETIME NOT NULL,
`updated_at` DATETIME NOT NULL,
PRIMARY KEY (`user_id`, `contact_id`))
ENGINE = InnoDB;
SHOW WARNINGS;
-- -----------------------------------------------------
-- Table `activities`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `activities` ;
SHOW WARNINGS;
CREATE TABLE IF NOT EXISTS `activities` (
`id` INT NOT NULL,
`activity_type` VARCHAR(45) NOT NULL,
`activity_id` INT NOT NULL,
`title` VARCHAR(45) NOT NULL,
`detail` TEXT NOT NULL,
`created_at` DATETIME NOT NULL,
`updated_at` DATETIME NOT NULL,
PRIMARY KEY (`id`))
ENGINE = InnoDB;
SHOW WARNINGS;
-- -----------------------------------------------------
-- Table `user_verification`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `user_verification` ;
SHOW WARNINGS;
CREATE TABLE IF NOT EXISTS `user_verification` (
`users_id` INT NOT NULL,
`verification_code` VARCHAR(45) NOT NULL,
`created_at` VARCHAR(45) NOT NULL)
ENGINE = InnoDB;
SHOW WARNINGS;
-- -----------------------------------------------------
-- Table `attachments`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `attachments` ;
SHOW WARNINGS;
CREATE TABLE IF NOT EXISTS `attachments` (
`id` INT NOT NULL,
`messages_id` INT NOT NULL,
`thumb_url` VARCHAR(45) NOT NULL,
`file_url` VARCHAR(45) NOT NULL,
`created_at` TIMESTAMP NOT NULL,
`updated_at` DATETIME NULL,
PRIMARY KEY (`id`))
ENGINE = InnoDB;
SHOW WARNINGS;
SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;