120 lines
2.6 KiB
SQL
Executable File
120 lines
2.6 KiB
SQL
Executable File
#Ce fichier contient la base de données à créer
|
|
|
|
CREATE DATABASE IF NOT EXISTS raspisms;
|
|
USE raspisms;
|
|
|
|
CREATE TABLE receiveds
|
|
(
|
|
id INT NOT NULL AUTO_INCREMENT,
|
|
at DATETIME NOT NULL,
|
|
send_by VARCHAR(12) NOT NULL,
|
|
content VARCHAR(1000) NOT NULL,
|
|
is_command BOOLEAN NOT NULL,
|
|
PRIMARY KEY (id)
|
|
);
|
|
|
|
CREATE TABLE sendeds
|
|
(
|
|
id INT NOT NULL AUTO_INCREMENT,
|
|
at DATETIME NOT NULL,
|
|
target VARCHAR(12) NOT NULL,
|
|
content VARCHAR(1000) NOT NULL,
|
|
PRIMARY KEY (id)
|
|
);
|
|
|
|
CREATE TABLE scheduleds
|
|
(
|
|
id INT NOT NULL AUTO_INCREMENT,
|
|
at DATETIME NOT NULL,
|
|
content VARCHAR(1000) NOT NULL,
|
|
progress BOOLEAN NOT NULL DEFAULT 0,
|
|
PRIMARY KEY (id)
|
|
);
|
|
|
|
CREATE TABLE contacts
|
|
(
|
|
|
|
id INT NOT NULL AUTO_INCREMENT,
|
|
name VARCHAR(100) NOT NULL,
|
|
number VARCHAR(12) NOT NULL,
|
|
PRIMARY KEY (id),
|
|
UNIQUE (name)
|
|
);
|
|
|
|
CREATE TABLE groups
|
|
(
|
|
id INT NOT NULL AUTO_INCREMENT,
|
|
name VARCHAR(100) NOT NULL,
|
|
PRIMARY KEY (id),
|
|
UNIQUE (name)
|
|
);
|
|
|
|
CREATE TABLE groups_contacts
|
|
(
|
|
id INT NOT NULL AUTO_INCREMENT,
|
|
id_group INT NOT NULL,
|
|
id_contact INT NOT NULL,
|
|
PRIMARY KEY (id),
|
|
FOREIGN KEY (id_group) REFERENCES groups (id) ON DELETE CASCADE ON UPDATE CASCADE,
|
|
FOREIGN KEY (id_contact) REFERENCES contacts (id) ON DELETE CASCADE ON UPDATE CASCADE
|
|
);
|
|
|
|
CREATE TABLE scheduleds_contacts
|
|
(
|
|
id INT NOT NULL AUTO_INCREMENT,
|
|
id_scheduled INT NOT NULL,
|
|
id_contact INT NOT NULL,
|
|
PRIMARY KEY (id),
|
|
FOREIGN KEY (id_scheduled) REFERENCES scheduleds (id) ON DELETE CASCADE ON UPDATE CASCADE,
|
|
FOREIGN KEY (id_contact) REFERENCES contacts (id) ON DELETE CASCADE ON UPDATE CASCADE
|
|
);
|
|
|
|
CREATE TABLE scheduleds_groups
|
|
(
|
|
id INT NOT NULL AUTO_INCREMENT,
|
|
id_scheduled INT NOT NULL,
|
|
id_group INT NOT NULL,
|
|
PRIMARY KEY (id),
|
|
FOREIGN KEY (id_scheduled) REFERENCES scheduleds (id) ON DELETE CASCADE ON UPDATE CASCADE,
|
|
FOREIGN KEY (id_group) REFERENCES groups (id) ON DELETE CASCADE ON UPDATE CASCADE
|
|
);
|
|
|
|
CREATE TABLE scheduleds_numbers
|
|
(
|
|
id INT NOT NULL AUTO_INCREMENT,
|
|
id_scheduled INT NOT NULL,
|
|
number VARCHAR(12) NOT NULL,
|
|
PRIMARY KEY (id),
|
|
FOREIGN KEY (id_scheduled) REFERENCES scheduleds (id) ON DELETE CASCADE ON UPDATE CASCADE
|
|
);
|
|
|
|
CREATE TABLE commands
|
|
(
|
|
id INT NOT NULL AUTO_INCREMENT,
|
|
name VARCHAR(25) NOT NULL,
|
|
script VARCHAR(100) NOT NULL,
|
|
admin BOOLEAN NOT NULL,
|
|
PRIMARY KEY (id),
|
|
UNIQUE (name)
|
|
);
|
|
|
|
CREATE TABLE events
|
|
(
|
|
id INT NOT NULL AUTO_INCREMENT,
|
|
type VARCHAR(25) NOT NULL,
|
|
at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
text VARCHAR(255) NOT NULL,
|
|
PRIMARY KEY (id)
|
|
);
|
|
|
|
CREATE TABLE users
|
|
(
|
|
id INT NOT NULL AUTO_INCREMENT,
|
|
email VARCHAR(255) NOT NULL,
|
|
password VARCHAR(255) NOT NULL,
|
|
admin BOOLEAN NOT NULL,
|
|
PRIMARY KEY (id),
|
|
UNIQUE (email)
|
|
);
|
|
|