2019-10-29 14:57:13 +01:00
|
|
|
#Ce fichier contient la base de données à créer
|
|
|
|
|
|
|
|
CREATE DATABASE IF NOT EXISTS raspisms;
|
|
|
|
USE raspisms;
|
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS setting
|
|
|
|
(
|
|
|
|
id INT NOT NULL AUTO_INCREMENT,
|
2019-11-08 18:06:18 +01:00
|
|
|
id_user INT NOT NULL,
|
2019-10-29 14:57:13 +01:00
|
|
|
name VARCHAR(50) NOT NULL,
|
|
|
|
value VARCHAR(1000) NOT NULL,
|
|
|
|
PRIMARY KEY (id),
|
2019-11-08 18:06:18 +01:00
|
|
|
FOREIGN KEY (id_user) REFERENCES user (id) ON DELETE CASCADE ON UPDATE CASCADE,
|
2019-10-29 14:57:13 +01:00
|
|
|
UNIQUE (name)
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS scheduled
|
|
|
|
(
|
|
|
|
id INT NOT NULL AUTO_INCREMENT,
|
2019-11-08 18:06:18 +01:00
|
|
|
id_user INT NOT NULL,
|
|
|
|
send_by VARCHAR(25) DEFAULT NULL,
|
2019-10-29 14:57:13 +01:00
|
|
|
at DATETIME NOT NULL,
|
|
|
|
text VARCHAR(1000) NOT NULL,
|
|
|
|
flash BOOLEAN NOT NULL DEFAULT 0,
|
2019-11-08 18:06:18 +01:00
|
|
|
FOREIGN KEY (id_user) REFERENCES user (id) ON DELETE CASCADE ON UPDATE CASCADE,
|
2019-10-29 14:57:13 +01:00
|
|
|
PRIMARY KEY (id)
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS received
|
|
|
|
(
|
|
|
|
id INT NOT NULL AUTO_INCREMENT,
|
|
|
|
at DATETIME NOT NULL,
|
|
|
|
text VARCHAR(1000) NOT NULL,
|
|
|
|
origin VARCHAR(20) NOT NULL,
|
|
|
|
destination VARCHAR(20),
|
|
|
|
command BOOLEAN NOT NULL DEFAULT 0,
|
|
|
|
PRIMARY KEY (id)
|
|
|
|
);
|
|
|
|
|
2019-11-08 18:06:18 +01:00
|
|
|
CREATE TABLE IF NOT EXISTS sended
|
2019-10-29 14:57:13 +01:00
|
|
|
(
|
|
|
|
id INT NOT NULL AUTO_INCREMENT,
|
|
|
|
at DATETIME NOT NULL,
|
|
|
|
text VARCHAR(1000) NOT NULL,
|
|
|
|
origin VARCHAR(20) NOT NULL,
|
|
|
|
destination VARCHAR(20),
|
|
|
|
flash BOOLEAN NOT NULL DEFAULT 0,
|
|
|
|
PRIMARY KEY (id)
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS contact
|
|
|
|
(
|
|
|
|
id INT NOT NULL AUTO_INCREMENT,
|
2019-11-08 18:06:18 +01:00
|
|
|
id_user INT NOT NULL,
|
2019-10-29 14:57:13 +01:00
|
|
|
name VARCHAR(100) NOT NULL,
|
|
|
|
number VARCHAR(20) NOT NULL,
|
|
|
|
PRIMARY KEY (id),
|
2019-11-08 18:06:18 +01:00
|
|
|
FOREIGN KEY (id_user) REFERENCES user (id) ON DELETE CASCADE ON UPDATE CASCADE,
|
2019-10-29 14:57:13 +01:00
|
|
|
UNIQUE (name)
|
|
|
|
);
|
|
|
|
|
2019-11-08 18:21:34 +01:00
|
|
|
CREATE TABLE IF NOT EXISTS `group`
|
2019-10-29 14:57:13 +01:00
|
|
|
(
|
|
|
|
id INT NOT NULL AUTO_INCREMENT,
|
2019-11-08 18:06:18 +01:00
|
|
|
id_user INT NOT NULL,
|
2019-10-29 14:57:13 +01:00
|
|
|
name VARCHAR(100) NOT NULL,
|
|
|
|
PRIMARY KEY (id),
|
2019-11-08 18:06:18 +01:00
|
|
|
FOREIGN KEY (id_user) REFERENCES user (id) ON DELETE CASCADE ON UPDATE CASCADE,
|
2019-10-29 14:57:13 +01:00
|
|
|
UNIQUE (name)
|
|
|
|
);
|
|
|
|
|
2019-11-08 18:06:18 +01:00
|
|
|
CREATE TABLE IF NOT EXISTS group_contact
|
2019-10-29 14:57:13 +01:00
|
|
|
(
|
|
|
|
id INT NOT NULL AUTO_INCREMENT,
|
2019-11-08 18:06:18 +01:00
|
|
|
id_group INT NOT NULL,
|
2019-10-29 14:57:13 +01:00
|
|
|
id_contact INT NOT NULL,
|
|
|
|
PRIMARY KEY (id),
|
2019-11-08 18:21:34 +01:00
|
|
|
FOREIGN KEY (id_group) REFERENCES `group` (id) ON DELETE CASCADE ON UPDATE CASCADE,
|
2019-10-29 14:57:13 +01:00
|
|
|
FOREIGN KEY (id_contact) REFERENCES contact (id) ON DELETE CASCADE ON UPDATE CASCADE
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS scheduled_contact
|
|
|
|
(
|
|
|
|
id INT NOT NULL AUTO_INCREMENT,
|
|
|
|
id_scheduled INT NOT NULL,
|
|
|
|
id_contact INT NOT NULL,
|
|
|
|
PRIMARY KEY (id),
|
|
|
|
FOREIGN KEY (id_scheduled) REFERENCES scheduled (id) ON DELETE CASCADE ON UPDATE CASCADE,
|
|
|
|
FOREIGN KEY (id_contact) REFERENCES contact (id) ON DELETE CASCADE ON UPDATE CASCADE
|
|
|
|
);
|
|
|
|
|
2019-11-08 18:06:18 +01:00
|
|
|
CREATE TABLE IF NOT EXISTS scheduled_group
|
2019-10-29 14:57:13 +01:00
|
|
|
(
|
|
|
|
id INT NOT NULL AUTO_INCREMENT,
|
|
|
|
id_scheduled INT NOT NULL,
|
2019-11-08 18:06:18 +01:00
|
|
|
id_group INT NOT NULL,
|
2019-10-29 14:57:13 +01:00
|
|
|
PRIMARY KEY (id),
|
|
|
|
FOREIGN KEY (id_scheduled) REFERENCES scheduled (id) ON DELETE CASCADE ON UPDATE CASCADE,
|
2019-11-08 18:21:34 +01:00
|
|
|
FOREIGN KEY (id_group) REFERENCES `group` (id) ON DELETE CASCADE ON UPDATE CASCADE
|
2019-10-29 14:57:13 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS scheduled_number
|
|
|
|
(
|
|
|
|
id INT NOT NULL AUTO_INCREMENT,
|
|
|
|
id_scheduled INT NOT NULL,
|
|
|
|
number VARCHAR(20) NOT NULL,
|
|
|
|
PRIMARY KEY (id),
|
|
|
|
FOREIGN KEY (id_scheduled) REFERENCES scheduled (id) ON DELETE CASCADE ON UPDATE CASCADE
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS command
|
|
|
|
(
|
|
|
|
id INT NOT NULL AUTO_INCREMENT,
|
2019-11-08 18:06:18 +01:00
|
|
|
id_user INT NOT NULL,
|
2019-10-29 14:57:13 +01:00
|
|
|
name VARCHAR(25) NOT NULL,
|
|
|
|
script VARCHAR(100) NOT NULL,
|
|
|
|
admin BOOLEAN NOT NULL,
|
|
|
|
PRIMARY KEY (id),
|
2019-11-08 18:06:18 +01:00
|
|
|
FOREIGN KEY (id_user) REFERENCES user (id) ON DELETE CASCADE ON UPDATE CASCADE,
|
2019-10-29 14:57:13 +01:00
|
|
|
UNIQUE (name)
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS event
|
|
|
|
(
|
|
|
|
id INT NOT NULL AUTO_INCREMENT,
|
2019-11-08 18:06:18 +01:00
|
|
|
id_user INT NOT NULL,
|
2019-10-29 14:57:13 +01:00
|
|
|
type VARCHAR(25) NOT NULL,
|
|
|
|
at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
|
|
text VARCHAR(255) NOT NULL,
|
2019-11-08 18:06:18 +01:00
|
|
|
FOREIGN KEY (id_user) REFERENCES user (id) ON DELETE CASCADE ON UPDATE CASCADE,
|
2019-10-29 14:57:13 +01:00
|
|
|
PRIMARY KEY (id)
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS user
|
|
|
|
(
|
|
|
|
id INT NOT NULL AUTO_INCREMENT,
|
|
|
|
email VARCHAR(150) NOT NULL,
|
|
|
|
password VARCHAR(255) NOT NULL,
|
|
|
|
admin BOOLEAN NOT NULL DEFAULT FALSE,
|
|
|
|
transfer BOOLEAN NOT NULL DEFAULT FALSE,
|
|
|
|
PRIMARY KEY (id),
|
|
|
|
UNIQUE (email)
|
|
|
|
);
|
|
|
|
|
2019-11-08 18:06:18 +01:00
|
|
|
CREATE TABLE IF NOT EXISTS user_number
|
|
|
|
(
|
|
|
|
id INT NOT NULL AUTO_INCREMENT,
|
|
|
|
id_user INT NOT NULL,
|
|
|
|
phone_number VARCHAR(25) NOT NULL,
|
|
|
|
platform VARCHAR(100) NOT NULL,
|
|
|
|
platform_datas JSON NOT NULL,
|
|
|
|
CHECK (JSON_VALID(platform_datas)),
|
|
|
|
PRIMARY KEY (id),
|
|
|
|
FOREIGN KEY (id_user) REFERENCES user (id) ON DELETE CASCADE ON UPDATE CASCADE
|
|
|
|
);
|
|
|
|
|
|
|
|
#Table to ensure external validation process by mailing or other
|
|
|
|
CREATE TABLE IF NOT EXISTS validation
|
|
|
|
(
|
|
|
|
id INT NOT NULL AUTO_INCREMENT,
|
|
|
|
token VARCHAR(200) NOT NULL,
|
|
|
|
random VARCHAR(32) NOT NULL,
|
|
|
|
action VARCHAR(200) NOT NULL,
|
|
|
|
datas JSON NOT NULL,
|
|
|
|
CHECK (JSON_VALID(datas)),
|
|
|
|
PRIMARY KEY (id),
|
|
|
|
UNIQUE(token)
|
|
|
|
);
|
|
|
|
|
2019-10-29 14:57:13 +01:00
|
|
|
CREATE TABLE IF NOT EXISTS transfer
|
|
|
|
(
|
|
|
|
id INT NOT NULL AUTO_INCREMENT,
|
|
|
|
id_received INT NOT NULL,
|
|
|
|
PRIMARY KEY (id),
|
|
|
|
FOREIGN KEY (id_received) REFERENCES received (id) ON DELETE CASCADE ON UPDATE CASCADE
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS smsstop
|
|
|
|
(
|
|
|
|
id INT NOT NULL AUTO_INCREMENT,
|
2019-11-08 18:06:18 +01:00
|
|
|
id_user INT NOT NULL,
|
2019-10-29 14:57:13 +01:00
|
|
|
number VARCHAR(20) NOT NULL,
|
|
|
|
PRIMARY KEY (id),
|
2019-11-08 18:06:18 +01:00
|
|
|
FOREIGN KEY (id_user) REFERENCES user (id) ON DELETE CASCADE ON UPDATE CASCADE,
|
2019-10-29 14:57:13 +01:00
|
|
|
UNIQUE (number)
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS webhook
|
|
|
|
(
|
|
|
|
id INT NOT NULL AUTO_INCREMENT,
|
2019-11-08 18:06:18 +01:00
|
|
|
id_user INT NOT NULL,
|
2019-10-29 14:57:13 +01:00
|
|
|
url VARCHAR(250) NOT NULL,
|
|
|
|
type INT NOT NULL,
|
2019-11-08 18:06:18 +01:00
|
|
|
FOREIGN KEY (id_user) REFERENCES user (id) ON DELETE CASCADE ON UPDATE CASCADE,
|
2019-10-29 14:57:13 +01:00
|
|
|
PRIMARY KEY (id)
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS webhook_querie
|
|
|
|
(
|
|
|
|
id INT NOT NULL AUTO_INCREMENT,
|
|
|
|
url VARCHAR(250) NOT NULL,
|
|
|
|
datas VARCHAR(10000) NOT NULL,
|
|
|
|
PRIMARY KEY (id)
|
|
|
|
);
|