forked from RaspbianFrance/raspisms
-
Notifications
You must be signed in to change notification settings - Fork 1
/
createDatabase.sql
executable file
·174 lines (155 loc) · 4.16 KB
/
createDatabase.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
#Ce fichier contient la base de données à créer
CREATE DATABASE IF NOT EXISTS raspisms;
USE raspisms;
CREATE TABLE IF NOT EXISTS settings
(
id INT NOT NULL AUTO_INCREMENT,
name VARCHAR(50) NOT NULL,
value VARCHAR(1000) NOT NULL,
PRIMARY KEY (id),
UNIQUE (name)
);
CREATE TABLE IF NOT EXISTS receiveds
(
id INT NOT NULL AUTO_INCREMENT,
at DATETIME NOT NULL,
send_by VARCHAR(20) NOT NULL,
content VARCHAR(1000) NOT NULL,
is_command BOOLEAN NOT NULL,
PRIMARY KEY (id)
);
CREATE TABLE IF NOT EXISTS sendeds
(
id INT NOT NULL AUTO_INCREMENT,
at DATETIME NOT NULL,
target VARCHAR(20) NOT NULL,
content VARCHAR(1000) NOT NULL,
before_delivered INT NOT NULL,
delivered BOOLEAN NOT NULL DEFAULT FALSE,
failed BOOLEAN NOT NULL DEFAULT FALSE,
PRIMARY KEY (id)
);
CREATE TABLE IF NOT EXISTS scheduleds
(
id INT NOT NULL AUTO_INCREMENT,
at DATETIME NOT NULL,
content VARCHAR(1000) NOT NULL,
flash BOOLEAN NOT NULL DEFAULT 0,
progress BOOLEAN NOT NULL DEFAULT 0,
PRIMARY KEY (id)
);
CREATE TABLE IF NOT EXISTS contacts
(
id INT NOT NULL AUTO_INCREMENT,
name VARCHAR(100) NOT NULL,
number VARCHAR(20) NOT NULL,
PRIMARY KEY (id),
UNIQUE (name)
);
CREATE TABLE IF NOT EXISTS groups
(
id INT NOT NULL AUTO_INCREMENT,
name VARCHAR(100) NOT NULL,
PRIMARY KEY (id),
UNIQUE (name)
);
CREATE TABLE IF NOT EXISTS 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 IF NOT EXISTS 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 IF NOT EXISTS 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 IF NOT EXISTS scheduleds_numbers
(
id INT NOT NULL AUTO_INCREMENT,
id_scheduled INT NOT NULL,
number VARCHAR(20) NOT NULL,
PRIMARY KEY (id),
FOREIGN KEY (id_scheduled) REFERENCES scheduleds (id) ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE TABLE IF NOT EXISTS 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 IF NOT EXISTS 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 IF NOT EXISTS users
(
id INT NOT NULL AUTO_INCREMENT,
email VARCHAR(255) NOT NULL,
password VARCHAR(255) NOT NULL,
admin BOOLEAN NOT NULL DEFAULT FALSE,
transfer BOOLEAN NOT NULL DEFAULT FALSE,
PRIMARY KEY (id),
UNIQUE (email)
);
CREATE TABLE IF NOT EXISTS transfers
(
id INT NOT NULL AUTO_INCREMENT,
id_received INT NOT NULL,
progress BOOLEAN NOT NULL DEFAULT 0,
PRIMARY KEY (id),
FOREIGN KEY (id_received) REFERENCES receiveds (id) ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE TABLE IF NOT EXISTS sms_stop
(
id INT NOT NULL AUTO_INCREMENT,
number VARCHAR(20) NOT NULL,
PRIMARY KEY (id),
UNIQUE (number)
);
CREATE TABLE IF NOT EXISTS contacts_infos
(
id INT NOT NULL AUTO_INCREMENT,
id_contact INT NOT NULL,
civility INT NOT NULL,
first_name VARCHAR(100),
last_name VARCHAR(100) NOT NULL,
birthday DATE,
love_situation INT,
PRIMARY KEY (id),
FOREIGN KEY (id_contact) REFERENCES contacts (id) ON DELETE CASCADE ON UPDATE CASCADE,
UNIQUE (first_name, last_name)
);
#On insert les données par défaut dans les settings
INSERT INTO settings (name, value)
VALUES ('transfer', '1'),
('sms_stop', '1'),
('detect_url', '1'),
('default_phone_country', 'fr'),
('preferred_phone_country', 'fr,be,ca'),
('sms_flash', '0'),
('sms_reception_sound', '1'),
('extended_contacts_infos', '0');