Skip to content

Commit

Permalink
Adding sql set up script for
Browse files Browse the repository at this point in the history
  • Loading branch information
hannaeko committed Jan 14, 2018
1 parent a5518bb commit 90df935
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/main/resources/Exercice.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
DROP TABLE IF EXISTS EXERCICE_GROUP;
DROP TABLE IF EXISTS EXERCICE;
create table EXERCICE (
id INT NOT NULL auto_increment,
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/Group.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
DROP TABLE IF EXISTS EXERCICE_GROUP;
DROP TABLE IF EXISTS `GROUP`;
create table `GROUP` (
id INT NOT NULL auto_increment,
Expand Down
120 changes: 120 additions & 0 deletions src/main/resources/SetUp.sql
Original file line number Diff line number Diff line change
@@ -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
);
1 change: 1 addition & 0 deletions src/main/resources/Tag.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
DROP TABLE IF EXISTS TAG_EXERCICE;
DROP TABLE IF EXISTS TAG;
create table TAG (
id INT NOT NULL auto_increment,
Expand Down

0 comments on commit 90df935

Please sign in to comment.