|
1
|
use socle ;
|
|
2
|
/*** Solution Tables**/
|
|
3
|
-- Create languages table keep it
|
|
4
|
CREATE TABLE languages (
|
|
5
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
6
|
language VARCHAR(255) NOT NULL,
|
|
7
|
tag ENUM('en', 'fr', 'es', 'it') NOT NULL
|
|
8
|
);
|
|
9
|
-- Create solution_languages table keep it
|
|
10
|
CREATE TABLE solution_languages(
|
|
11
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
12
|
active ENUM('true', 'false') NOT NULL,
|
|
13
|
defaultLanguage BOOLEAN NOT NULL,
|
|
14
|
languagesId INT NOT NULL,
|
|
15
|
FOREIGN KEY (languagesId) REFERENCES languages(id) ON DELETE CASCADE ON UPDATE CASCADE
|
|
16
|
);
|
|
17
|
-- Create solution_entities table
|
|
18
|
CREATE TABLE solution_entities (
|
|
19
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
20
|
code VARCHAR(255) NOT NULL,
|
|
21
|
state boolean NULL,
|
|
22
|
level text NOT NULL,
|
|
23
|
title VARCHAR(255) NOT NULL,
|
|
24
|
parentId VARCHAR(255) NOT NULL
|
|
25
|
);
|
|
26
|
-- Create solution_menu table
|
|
27
|
CREATE TABLE solution_menu (
|
|
28
|
id INT AUTO_INCREMENT NOT NULL,
|
|
29
|
menuCode VARCHAR(255) NOT NULL,
|
|
30
|
menuLibelle TEXT NULL,
|
|
31
|
parentMenu VARCHAR(255) NULL,
|
|
32
|
type ENUM('menu', 'subMenu', 'widget', 'option') NULL,
|
|
33
|
PRIMARY KEY (menuCode),
|
|
34
|
UNIQUE (id)
|
|
35
|
);
|
|
36
|
|
|
37
|
-- Create company_solution_menu_droit table done
|
|
38
|
CREATE TABLE solution_menu_rights (
|
|
39
|
id INT AUTO_INCREMENT NOT NULL,
|
|
40
|
code VARCHAR(255) NOT NULL,
|
|
41
|
action VARCHAR(255) NOT NULL,
|
|
42
|
menuCode VARCHAR(255) NOT NULL,
|
|
43
|
PRIMARY KEY (code),
|
|
44
|
FOREIGN KEY (menuCode) REFERENCES solution_menu(menuCode) ON DELETE CASCADE,
|
|
45
|
UNIQUE (id)
|
|
46
|
);
|
|
47
|
|
|
48
|
|
|
49
|
-- Create solution_subscription table => split into two tables solution_subscription than solution_subscription_menu
|
|
50
|
CREATE TABLE solution_subscription (
|
|
51
|
id INT NOT NULL,
|
|
52
|
code VARCHAR(255) NOT NULL,
|
|
53
|
type ENUM('On The Menu', 'Essential','Advanced') NOT NULL,
|
|
54
|
PRIMARY KEY (code)
|
|
55
|
);
|
|
56
|
|
|
57
|
CREATE TABLE solution_subscription_menu (
|
|
58
|
id INT AUTO_INCREMENT NOT NULL,
|
|
59
|
subscriptionCode VARCHAR(255) NOT NULL,
|
|
60
|
menuCode VARCHAR(255) NOT NULL,
|
|
61
|
state BOOLEAN,
|
|
62
|
FOREIGN KEY (subscriptionCode) REFERENCES solution_subscription(code) ON DELETE CASCADE ON UPDATE CASCADE,
|
|
63
|
FOREIGN KEY (menuCode) REFERENCES solution_menu(menuCode) ON DELETE CASCADE ON UPDATE CASCADE,
|
|
64
|
PRIMARY KEY (subscriptionCode, menuCode),
|
|
65
|
UNIQUE (id)
|
|
66
|
);
|
|
67
|
|
|
68
|
-- Create solution_subscription_menu_rights with Composite foreign key referencing solution_subscription_menu (subscriptionCode, menuCode)
|
|
69
|
CREATE TABLE solution_subscription_menu_rights (
|
|
70
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
71
|
subscriptionCode VARCHAR(255) NOT NULL,
|
|
72
|
menuCode VARCHAR(255) NOT NULL,
|
|
73
|
solution_menu_rights_code VARCHAR(255) NOT NULL,
|
|
74
|
FOREIGN KEY (subscriptionCode, menuCode)
|
|
75
|
REFERENCES solution_subscription_menu(subscriptionCode, menuCode)
|
|
76
|
ON DELETE CASCADE ON UPDATE CASCADE,
|
|
77
|
FOREIGN KEY (solution_menu_rights_code)
|
|
78
|
REFERENCES solution_menu_rights(code)
|
|
79
|
ON DELETE CASCADE ON UPDATE CASCADE,
|
|
80
|
UNIQUE (id)
|
|
81
|
);
|
|
82
|
|
|
83
|
-- Create solution_setting table
|
|
84
|
CREATE TABLE solution_setting (
|
|
85
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
86
|
label TEXT NULL,
|
|
87
|
type ENUM('country', 'business_Sector', 'company_size', 'CA', 'geographic_extent', 'value_chain') NOT NULL
|
|
88
|
);
|
|
89
|
-- Create solution_setting_item table
|
|
90
|
CREATE TABLE solution_setting_item (
|
|
91
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
92
|
label TEXT NULL,
|
|
93
|
code TEXT NULL,
|
|
94
|
active boolean,
|
|
95
|
settingId INT NOT NULL,
|
|
96
|
FOREIGN KEY (settingId) REFERENCES solution_setting(id) ON DELETE CASCADE
|
|
97
|
);
|
|
98
|
-- Create solution_compensation table
|
|
99
|
CREATE TABLE solution_compensation (
|
|
100
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
101
|
column_code VARCHAR(50) NOT NULL,
|
|
102
|
column_label VARCHAR(255) NOT NULL,
|
|
103
|
description TEXT,
|
|
104
|
languageId INT NOT NULL,
|
|
105
|
FOREIGN KEY (languageId) REFERENCES languages(id) ON DELETE CASCADE ON UPDATE CASCADE
|
|
106
|
);
|
|
107
|
/*** Company Tables ***/
|
|
108
|
-- Create the company table
|
|
109
|
CREATE TABLE company (
|
|
110
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
111
|
raisonSociale VARCHAR(255) NOT NULL,
|
|
112
|
logo VARCHAR(255) NULL,
|
|
113
|
site VARCHAR(255) NULL,
|
|
114
|
address VARCHAR(255) NULL,
|
|
115
|
SIRET VARCHAR(255) NULL,
|
|
116
|
type ENUM('Solution','Customer') NULL,
|
|
117
|
parentId INT NOT NULL,
|
|
118
|
subscriptionType VARCHAR(255) NULL,
|
|
119
|
status VARCHAR(255),
|
|
120
|
createdAt TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
121
|
updatedAt TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
122
|
);
|
|
123
|
-- Create the company_setting table a a faire !!
|
|
124
|
CREATE TABLE company_setting (
|
|
125
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
126
|
companyId INT NOT NULL,
|
|
127
|
companySizeId INT,
|
|
128
|
valueChainId INT,
|
|
129
|
businessSectorId INT,
|
|
130
|
geographicExtentId INT,
|
|
131
|
cAId INT,
|
|
132
|
countryId INT,
|
|
133
|
FOREIGN KEY (companyId) REFERENCES company(id) ON DELETE CASCADE ON UPDATE CASCADE,
|
|
134
|
FOREIGN KEY (companySizeId) REFERENCES solution_setting_item(id) ON DELETE CASCADE ON UPDATE CASCADE,
|
|
135
|
FOREIGN KEY (valueChainId) REFERENCES solution_setting_item(id) ON DELETE CASCADE ON UPDATE CASCADE,
|
|
136
|
FOREIGN KEY (businessSectorId) REFERENCES solution_setting_item(id) ON DELETE CASCADE ON UPDATE CASCADE,
|
|
137
|
FOREIGN KEY (geographicExtentId) REFERENCES solution_setting_item(id) ON DELETE CASCADE ON UPDATE CASCADE,
|
|
138
|
FOREIGN KEY (cAId) REFERENCES solution_setting_item(id) ON DELETE CASCADE ON UPDATE CASCADE,
|
|
139
|
FOREIGN KEY (countryId) REFERENCES solution_setting_item(id) ON DELETE CASCADE ON UPDATE CASCADE,
|
|
140
|
createdAt TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
141
|
updatedAt TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
142
|
);
|
|
143
|
-- Create company_languages table
|
|
144
|
CREATE TABLE company_languages (
|
|
145
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
146
|
active ENUM('true', 'false') NOT NULL,
|
|
147
|
defaultLanguage BOOLEAN NOT NULL,
|
|
148
|
languagesId INT NOT NULL,
|
|
149
|
companyId INT NOT NULL,
|
|
150
|
FOREIGN KEY (languagesId) REFERENCES languages(id) ON DELETE CASCADE ON UPDATE CASCADE,
|
|
151
|
FOREIGN KEY (companyId) REFERENCES company(id) ON DELETE CASCADE ON UPDATE CASCADE
|
|
152
|
);
|
|
153
|
-- Create company_profile table
|
|
154
|
CREATE TABLE company_profile (
|
|
155
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
156
|
title VARCHAR(255) NOT NULL,
|
|
157
|
code VARCHAR(255) NOT NULL,
|
|
158
|
companyId INT NOT NULL,
|
|
159
|
FOREIGN KEY (companyId) REFERENCES company(id) ON DELETE CASCADE ON UPDATE CASCADE
|
|
160
|
);
|
|
161
|
-- Create company_users table
|
|
162
|
CREATE TABLE company_users (
|
|
163
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
164
|
firstName VARCHAR(255) NOT NULL,
|
|
165
|
lastName VARCHAR(255) NOT NULL,
|
|
166
|
email VARCHAR(255) NOT NULL UNIQUE,
|
|
167
|
password VARCHAR(255) NULL,
|
|
168
|
phone INT NULL,
|
|
169
|
avatar VARCHAR(255) NOT NULL,
|
|
170
|
resetToken VARCHAR(255) NULL,
|
|
171
|
companyId INT NOT NULL,
|
|
172
|
code VARCHAR(255) NULL,
|
|
173
|
actif boolean NULL,
|
|
174
|
FOREIGN KEY (companyId) REFERENCES company(id) ON DELETE CASCADE ON UPDATE CASCADE,
|
|
175
|
createdAt TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
176
|
updatedAt TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
177
|
);
|
|
178
|
-- Create company_entities table
|
|
179
|
CREATE TABLE company_entities (
|
|
180
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
181
|
code text NOT NULL,
|
|
182
|
title text NOT NULL,
|
|
183
|
state boolean NULL,
|
|
184
|
level text NOT NULL,
|
|
185
|
parentId VARCHAR(255) NOT NULL,
|
|
186
|
companyId INT NOT NULL,
|
|
187
|
FOREIGN KEY (companyId) REFERENCES company(id) ON DELETE CASCADE ON UPDATE CASCADE
|
|
188
|
);
|
|
189
|
-- Create company_user_profile table
|
|
190
|
CREATE TABLE company_user_profile (
|
|
191
|
id INT PRIMARY KEY AUTO_INCREMENT,
|
|
192
|
profileId INT NOT NULL,
|
|
193
|
usersId INT NOT NULL,
|
|
194
|
FOREIGN KEY (profileId) REFERENCES company_profile(id)ON DELETE CASCADE ON UPDATE CASCADE ,
|
|
195
|
FOREIGN KEY (usersId) REFERENCES company_users(id)ON DELETE CASCADE ON UPDATE CASCADE
|
|
196
|
);
|
|
197
|
-- Create company_user_profiles_entities table
|
|
198
|
CREATE TABLE company_user_profiles_entities(
|
|
199
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
200
|
entitiesCompanyId INT NOT NULL,
|
|
201
|
userProfileId INT NOT NULL,
|
|
202
|
state boolean NOT NULL,
|
|
203
|
CONSTRAINT FK_UserProfile FOREIGN KEY (userProfileId) REFERENCES company_user_profile (id) ON DELETE CASCADE ON UPDATE CASCADE,
|
|
204
|
CONSTRAINT FK_EntitiesCompany FOREIGN KEY (entitiesCompanyId) REFERENCES company_entities(id) ON DELETE CASCADE ON UPDATE CASCADE
|
|
205
|
);
|
|
206
|
-- Create company_solution_menu table
|
|
207
|
CREATE TABLE company_solution_menu (
|
|
208
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
209
|
state BOOLEAN NOT NULL,
|
|
210
|
companyId INT NOT NULL,
|
|
211
|
menuCode VARCHAR(255) NOT NULL,
|
|
212
|
FOREIGN KEY (menuCode) REFERENCES solution_menu(menuCode) ON DELETE CASCADE ON UPDATE CASCADE,
|
|
213
|
FOREIGN KEY (companyId) REFERENCES company(id) ON DELETE CASCADE ON UPDATE CASCADE
|
|
214
|
);
|
|
215
|
|
|
216
|
-- Create company_solution_menu_profils table
|
|
217
|
create table company_solution_menu_profils(
|
|
218
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
219
|
state boolean NOT NULL,
|
|
220
|
profileId INT NOT NULL,
|
|
221
|
menuSolutionCompanyId INT NOT NULL,
|
|
222
|
FOREIGN KEY (menuSolutionCompanyId) REFERENCES company_solution_menu(id) ON DELETE CASCADE ON UPDATE CASCADE,
|
|
223
|
FOREIGN KEY (profileId) REFERENCES company_profile(id) ON DELETE CASCADE ON UPDATE CASCADE
|
|
224
|
);
|
|
225
|
-- Create company_solution_menu_profils_droit table
|
|
226
|
CREATE TABLE company_solution_menu_profils_rights (
|
|
227
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
228
|
profileId INT,
|
|
229
|
droitId INT,
|
|
230
|
libelle VARCHAR(255) NOT NULL,
|
|
231
|
actif boolean null ,
|
|
232
|
FOREIGN KEY (droitId) REFERENCES solution_subscription_menu_rights(id) ON DELETE CASCADE,
|
|
233
|
FOREIGN KEY (profileId) REFERENCES company_profile(id) ON DELETE CASCADE
|
|
234
|
);
|
|
235
|
-- Create company_files table
|
|
236
|
CREATE TABLE company_files (
|
|
237
|
id INT(11) AUTO_INCREMENT PRIMARY KEY,
|
|
238
|
description TEXT,
|
|
239
|
pathFile VARCHAR(255),
|
|
240
|
extension VARCHAR(255),
|
|
241
|
size VARCHAR(255),
|
|
242
|
type VARCHAR(255),
|
|
243
|
createdAt DATETIME NULL,
|
|
244
|
updatedAt DATETIME NULL
|
|
245
|
);
|
|
246
|
-- Create company_profile_columns_configuration table
|
|
247
|
CREATE TABLE company_profile_columns_configuration (
|
|
248
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
249
|
userProfileId INT NOT NULL,
|
|
250
|
type ENUM('compensation', 'rapport') NOT NULL,
|
|
251
|
selectedColumns TEXT,
|
|
252
|
CONSTRAINT userProfileId FOREIGN KEY (userProfileId) REFERENCES company_user_profile(id) ON DELETE CASCADE
|
|
253
|
);
|
|
254
|
-- Create prospecting_company table
|
|
255
|
CREATE TABLE prospecting_company (
|
|
256
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
257
|
firstName VARCHAR(255) NOT NULL,
|
|
258
|
lastName VARCHAR(255) NOT NULL,
|
|
259
|
email VARCHAR(255) NOT NULL,
|
|
260
|
phone INT NULL,
|
|
261
|
raisonSociale VARCHAR(255),
|
|
262
|
businessSector VARCHAR(255) NOT NULL,
|
|
263
|
country VARCHAR(255) NOT NULL,
|
|
264
|
createdAt TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
265
|
updatedAt TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
|
266
|
);
|
|
267
|
-- Create demonstration_company_comments table
|
|
268
|
CREATE TABLE prospecting_company_comments (
|
|
269
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
270
|
description VARCHAR(255),
|
|
271
|
userId INT NOT NULL,
|
|
272
|
prospectingId INT NOT NULL,
|
|
273
|
createdAt TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
274
|
FOREIGN KEY (userId) REFERENCES company_users(id) ON DELETE CASCADE ON UPDATE CASCADE,
|
|
275
|
FOREIGN KEY (prospectingId) REFERENCES prospecting_company(id) ON DELETE CASCADE ON UPDATE CASCADE
|
|
276
|
);
|
|
277
|
-- Create table company_activities
|
|
278
|
CREATE TABLE company_activities (
|
|
279
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
280
|
description VARCHAR(255),
|
|
281
|
action ENUM('create', 'update', 'delete', 'validate', 'send email') NULL,
|
|
282
|
type ENUM('company', 'user', 'email', 'company_compensation') NULL,
|
|
283
|
createdAt TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
284
|
userId INT NULL,
|
|
285
|
companyId INT NULL,
|
|
286
|
FOREIGN KEY (companyId) REFERENCES company(id) ON DELETE CASCADE ON UPDATE CASCADE,
|
|
287
|
FOREIGN KEY (userId) REFERENCES company_users(id) ON DELETE CASCADE ON UPDATE CASCADE
|
|
288
|
);
|
|
289
|
-- create notification table
|
|
290
|
CREATE TABLE company_notification (
|
|
291
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
292
|
icon VARCHAR(255) DEFAULT NULL,
|
|
293
|
image VARCHAR(255) DEFAULT NULL,
|
|
294
|
title VARCHAR(255) DEFAULT NULL,
|
|
295
|
description TEXT DEFAULT NULL,
|
|
296
|
time DATETIME NOT NULL,
|
|
297
|
link VARCHAR(255) DEFAULT NULL,
|
|
298
|
useRouter BOOLEAN DEFAULT TRUE,
|
|
299
|
seen BOOLEAN DEFAULT FALSE,
|
|
300
|
idSource INT NOT NULL,
|
|
301
|
idReceiver INT NOT NULL
|
|
302
|
);
|
|
303
|
-- Create company_meetings table
|
|
304
|
CREATE TABLE company_meetings (
|
|
305
|
id int NOT NULL AUTO_INCREMENT,
|
|
306
|
title varchar(255) NOT NULL,
|
|
307
|
startDate datetime NOT NULL,
|
|
308
|
endDate datetime NOT NULL,
|
|
309
|
createdBy int NOT NULL,
|
|
310
|
link varchar(255) NOT NULL,
|
|
311
|
description text NOT NULL,
|
|
312
|
createdAt datetime NOT NULL,
|
|
313
|
updatedAt datetime NOT NULL,
|
|
314
|
PRIMARY KEY (id)
|
|
315
|
);
|
|
316
|
-- Create company_user_meeting table
|
|
317
|
CREATE TABLE company_user_meeting (
|
|
318
|
user_id int NOT NULL,
|
|
319
|
meeting_id int NOT NULL,
|
|
320
|
PRIMARY KEY (user_id, meeting_id),
|
|
321
|
FOREIGN KEY (user_id) REFERENCES company_users (id) ON DELETE CASCADE ON UPDATE CASCADE,
|
|
322
|
FOREIGN KEY (meeting_id) REFERENCES company_meetings (id) ON DELETE CASCADE ON UPDATE CASCADE
|
|
323
|
);
|
|
324
|
-- Create company_chats table
|
|
325
|
CREATE TABLE company_chats (
|
|
326
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
327
|
idSource int(11),
|
|
328
|
isGroup BOOLEAN
|
|
329
|
);
|
|
330
|
-- Create company_chat_messages table
|
|
331
|
CREATE TABLE company_chat_messages (
|
|
332
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
333
|
chatId int(11),
|
|
334
|
idSource int(11),
|
|
335
|
isMine BOOLEAN,
|
|
336
|
seen BOOLEAN,
|
|
337
|
value TEXT,
|
|
338
|
createdAt DATETIME,
|
|
339
|
FOREIGN KEY (chatId) REFERENCES company_chats(id) ON DELETE CASCADE ON UPDATE CASCADE
|
|
340
|
);
|
|
341
|
-- Create company_chat_messages_file table
|
|
342
|
CREATE TABLE company_chat_messages_file (
|
|
343
|
message_id INT,
|
|
344
|
files_id INT,
|
|
345
|
PRIMARY KEY (message_id, files_id),
|
|
346
|
FOREIGN KEY (message_id) REFERENCES company_chat_messages(id) ON DELETE CASCADE ON UPDATE CASCADE,
|
|
347
|
FOREIGN KEY (files_id) REFERENCES company_files(id) ON DELETE CASCADE ON UPDATE CASCADE
|
|
348
|
);
|
|
349
|
-- Create company_chat_group table
|
|
350
|
CREATE TABLE company_chat_group (
|
|
351
|
chat_id INT,
|
|
352
|
user_id INT,
|
|
353
|
PRIMARY KEY (chat_id, user_id),
|
|
354
|
FOREIGN KEY (chat_id) REFERENCES company_chats(id),
|
|
355
|
FOREIGN KEY (user_id) REFERENCES company_users(id)
|
|
356
|
);
|