From 90df9358dcd0f8e5851e54b0353994239b5b80ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20Berthaud-M=C3=BCller?= Date: Sun, 14 Jan 2018 14:29:17 +0100 Subject: [PATCH] Adding sql set up script for --- src/main/resources/Exercice.sql | 1 + src/main/resources/Group.sql | 1 + src/main/resources/SetUp.sql | 120 ++++++++++++++++++++++++++++++++ src/main/resources/Tag.sql | 1 + 4 files changed, 123 insertions(+) create mode 100644 src/main/resources/SetUp.sql diff --git a/src/main/resources/Exercice.sql b/src/main/resources/Exercice.sql index d6e4f83..691e41c 100644 --- a/src/main/resources/Exercice.sql +++ b/src/main/resources/Exercice.sql @@ -1,3 +1,4 @@ +DROP TABLE IF EXISTS EXERCICE_GROUP; DROP TABLE IF EXISTS EXERCICE; create table EXERCICE ( id INT NOT NULL auto_increment, diff --git a/src/main/resources/Group.sql b/src/main/resources/Group.sql index ba7531c..a3dce79 100644 --- a/src/main/resources/Group.sql +++ b/src/main/resources/Group.sql @@ -1,3 +1,4 @@ +DROP TABLE IF EXISTS EXERCICE_GROUP; DROP TABLE IF EXISTS `GROUP`; create table `GROUP` ( id INT NOT NULL auto_increment, diff --git a/src/main/resources/SetUp.sql b/src/main/resources/SetUp.sql new file mode 100644 index 0000000..aac007e --- /dev/null +++ b/src/main/resources/SetUp.sql @@ -0,0 +1,120 @@ +DROP TABLE IF EXISTS EXERCICE_GROUP; +DROP TABLE IF EXISTS TAG_EXERCICE; + +DROP TABLE IF EXISTS TOKEN; +DROP TABLE IF EXISTS JOB; +DROP TABLE IF EXISTS RESULT; +DROP TABLE IF EXISTS EXERCICE; +DROP TABLE IF EXISTS USER; +DROP TABLE IF EXISTS `GROUP`; +DROP TABLE IF EXISTS `JOB_INFO`; +DROP TABLE IF EXISTS TAG; +DROP TABLE IF EXISTS `UPLOAD`; + +create table EXERCICE ( + id INT NOT NULL auto_increment, + title VARCHAR(200) DEFAULT NULL, + description TEXT DEFAULT NULL, + inputFile TEXT DEFAULT NULL, + outputFile TEXT DEFAULT NULL, + points INT DEFAULT NULL, + creatingDate DATETIME DEFAULT CURRENT_TIMESTAMP, + PRIMARY KEY (id) +); + +CREATE TABLE USER ( + id INT NOT NULL AUTO_INCREMENT, + username VARCHAR(200) NOT NULL, + firstname VARCHAR(200) DEFAULT NULL, + surname VARCHAR(200) DEFAULT NULL, + + role VARCHAR(50) DEFAULT '', + + PRIMARY KEY (id) +); + +create table `GROUP` ( + id INT NOT NULL auto_increment, + name VARCHAR(200) DEFAULT NULL, + description TEXT DEFAULT NULL, + publicationDate DATETIME DEFAULT CURRENT_TIMESTAMP, + endDate DATETIME DEFAULT NULL, + points INT DEFAULT NULL, + imageUrl TEXT NOT NULL, + PRIMARY KEY (id) +); + + +CREATE TABLE `JOB_INFO` ( + id INT NOT NULL AUTO_INCREMENT, + uuid VARCHAR(36) NOT NULL, + execTime DATETIME DEFAULT CURRENT_TIMESTAMP, + msgType VARCHAR(20) NOT NULL, + msgInfo TEXT, + PRIMARY KEY (id) +); + +CREATE TABLE EXERCICE_GROUP ( + exercice_id INT NOT NULL, + group_id INT NOT NULL, + PRIMARY KEY (exercice_id, group_id), + FOREIGN KEY (exercice_id) REFERENCES EXERCICE (id) + ON DELETE CASCADE, + FOREIGN KEY (group_id) REFERENCES `GROUP` (id) + ON DELETE CASCADE +); + + +CREATE TABLE RESULT ( + id INT NOT NULL AUTO_INCREMENT, + point INT NOT NULL, + exercice_id INT NOT NULL, + PRIMARY KEY (id), + user_id INT NOT NULL, + FOREIGN KEY (exercice_id) REFERENCES EXERCICE (id) + ON DELETE CASCADE, + FOREIGN KEY (user_id) REFERENCES USER (id) + ON DELETE CASCADE +); + +create table TAG ( + id INT NOT NULL auto_increment, + color VARCHAR(6) DEFAULT NULL, + tag VARCHAR(50) DEFAULT NULL, + PRIMARY KEY (id) +); + +CREATE TABLE TAG_EXERCICE ( + tag_id INT NOT NULL, + exercice_id INT NOT NULL, + PRIMARY KEY (tag_id, exercice_id), + FOREIGN KEY (exercice_id) REFERENCES EXERCICE (id) + ON DELETE CASCADE, + FOREIGN KEY (tag_id) REFERENCES TAG (id) + ON DELETE CASCADE +); + +CREATE TABLE TOKEN ( + token VARCHAR(127) NOT NULL PRIMARY KEY, + accessToken VARCHAR(127) NOT NULL, + user_id INT NOT NULL, + FOREIGN KEY (user_id) REFERENCES USER(id) + ON DELETE CASCADE +); + +CREATE TABLE `UPLOAD` ( + id INT NOT NULL AUTO_INCREMENT, + filename VARCHAR(50) NOT NULL, + PRIMARY KEY (id) +); + +CREATE TABLE `JOB` ( + uuid VARCHAR(36) NOT NULL, + user_id INT NOT NULL, + exercice_id INT NOT NULL, + PRIMARY KEY (uuid), + FOREIGN KEY (exercice_id) REFERENCES EXERCICE (id) + ON DELETE CASCADE, + FOREIGN KEY (user_id) REFERENCES USER (id) + ON DELETE CASCADE +); \ No newline at end of file diff --git a/src/main/resources/Tag.sql b/src/main/resources/Tag.sql index 2847d5e..979fac3 100644 --- a/src/main/resources/Tag.sql +++ b/src/main/resources/Tag.sql @@ -1,3 +1,4 @@ +DROP TABLE IF EXISTS TAG_EXERCICE; DROP TABLE IF EXISTS TAG; create table TAG ( id INT NOT NULL auto_increment,