From 5f170c44da659f9c842766d9e291c333755db1a2 Mon Sep 17 00:00:00 2001 From: Leni BEAULATON Date: Tue, 22 Oct 2024 09:12:23 +0200 Subject: [PATCH 1/3] =?UTF-8?q?Mise=20=C3=A0=20jour=20de=20'script.SQL'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- script.SQL | 132 +++++------------------------------------------------ 1 file changed, 12 insertions(+), 120 deletions(-) diff --git a/script.SQL b/script.SQL index caf80a3..ae23f3f 100644 --- a/script.SQL +++ b/script.SQL @@ -1,120 +1,12 @@ --- Suppression des tables -DROP TABLE IF EXISTS Commentary; -DROP TABLE IF EXISTS Favorite; -DROP TABLE IF EXISTS Quote; -DROP TABLE IF EXISTS Caracter; -DROP TABLE IF EXISTS Source; -DROP TABLE IF EXISTS Record_quiz; -DROP TABLE IF EXISTS Quiz_Question; -DROP TABLE IF EXISTS Quiz; -DROP TABLE IF EXISTS Question; -DROP TABLE IF EXISTS Admin; -DROP TABLE IF EXISTS Users; -DROP TABLE IF EXISTS Image; - --- Création des tables - -CREATE TABLE Image( - id_img SERIAL PRIMARY KEY, - imgPath varchar(100) NOT NULL UNIQUE -); - -CREATE TABLE Users( - id_user varchar(5) PRIMARY KEY, - username varchar(50) NOT NULL, - email varchar(50) NOT NULL, - pssword varchar(100) NOT NULL, - img SERIAL NOT NULL, - creation date NOT NULL, - CONSTRAINT unique_col UNIQUE (email), - CONSTRAINT fk_img FOREIGN KEY(img) REFERENCES Image(id_img) -); - -CREATE TABLE Admin( - users varchar(5) PRIMARY KEY, - CONSTRAINT fk_user FOREIGN KEY(users) REFERENCES Users(id_user) -); - -CREATE TABLE Question( - id_question SERIAL PRIMARY KEY, - texte text NOT NULL UNIQUE, - answerA varchar(30) NOT NULL, - answerB varchar(30) NOT NULL, - answerC varchar(30) NOT NULL, - answerD varchar(30) NOT NULL, - cAnswer varchar(30) NOT NULL, - CONSTRAINT check_cAnswer CHECK (cAnswer = answerA OR cAnswer = answerB OR cAnswer = answerC OR cAnswer = answerD) -); - -CREATE TABLE Quiz( - id_quiz SERIAL PRIMARY KEY, - levelQ numeric NOT NULL, - timer numeric NOT NULL -); - -CREATE TABLE Quiz_Question( - quiz SERIAL NOT NULL, - question SERIAL NOT NULL, - PRIMARY KEY (quiz, question), - CONSTRAINT fk_quiz FOREIGN KEY(quiz) REFERENCES Quiz(id_quiz), - CONSTRAINT fk_question FOREIGN KEY(question) REFERENCES Question(id_question) -); - -CREATE TABLE Record_quiz( - users varchar(5) NOT NULL, - quiz SERIAL NOT NULL, - nbPoint numeric DEFAULT '0', - timeQ numeric DEFAULT '0', - PRIMARY KEY (users, quiz), - CONSTRAINT fk_user FOREIGN KEY(users) REFERENCES Users(id_user), - CONSTRAINT fk_quiz FOREIGN KEY(quiz) REFERENCES Quiz(id_quiz), - CONSTRAINT err_nbPoint CHECK(nbPoint >= 0), - CONSTRAINT err_timeQ CHECK(timeQ >= 0) -); - -CREATE TABLE Source( - id_source SERIAL PRIMARY KEY, - title varchar(100) NOT NULL, - dateS date NOT NULL -); - -CREATE TABLE Caracter( - id_caracter SERIAL PRIMARY KEY, - caracter varchar(100) NOT NULL, - img_path varchar(100) NOT NULL -); - -CREATE TABLE Quote( - id_quote SERIAL PRIMARY KEY, - content text NOT NULL, - likes numeric DEFAULT '0', - langue char(2) NOT NULL, - isValide boolean NOT NULL DEFAULT 'false', - reason varchar(100) NOT NULL, - id_caracter SERIAL NOT NULL, - id_source SERIAL NOT NULL, - id_user_verif varchar(5) NOT NULL, - CONSTRAINT fk_caracter FOREIGN KEY(id_caracter) REFERENCES Caracter(id_caracter), - CONSTRAINT fk_source FOREIGN KEY(id_source) REFERENCES Source(id_source), - CONSTRAINT fk_userverif FOREIGN KEY(id_user_verif) REFERENCES Users(id_user), - CONSTRAINT err_nbLike CHECK (likes >= 0), - CONSTRAINT err_language CHECK (langue = 'fr' OR langue = 'en') -); - -CREATE TABLE Favorite( - users varchar(5) NOT NULL, - quote SERIAL NOT NULL, - PRIMARY KEY (users, quote), - CONSTRAINT fk_quote FOREIGN KEY(quote) REFERENCES Quote(id_quote), - CONSTRAINT fk_user FOREIGN KEY(users) REFERENCES Users(id_user) -); - -CREATE TABLE Commentary( - id_comment SERIAL PRIMARY KEY, - quote SERIAL NOT NULL, - users varchar(5) NOT NULL, - dateC date NOT NULL, - comment text NOT NULL, - CONSTRAINT fk_quote FOREIGN KEY(quote) REFERENCES Quote(id_quote), - CONSTRAINT fk_user FOREIGN KEY(users) REFERENCES Users(id_user) -); +INSERT INTO Commentary (id_comment, quote, users, dateC, comment) +VALUES +('CMT001', 'Q001', 'U001', '2024-10-01', 'This quote really resonates with me.'), +('CMT002', 'Q002', 'U002', '2024-10-02', 'A timeless piece of wisdom.'), +('CMT003', 'Q003', 'U003', '2024-10-03', 'I disagree with this viewpoint.'), +('CMT004', 'Q004', 'U001', '2024-10-04', 'Absolutely love this quote!'), +('CMT005', 'Q005', 'U004', '2024-10-05', 'Very motivational, thanks for sharing!'), +('CMT006', 'Q006', 'U005', '2024-10-06', 'This makes me reflect on life.'), +('CMT007', 'Q007', 'U006', '2024-10-07', 'I find this quote very inspiring.'), +('CMT008', 'Q008', 'U007', '2024-10-08', 'I think there’s more to this than meets the eye.'), +('CMT009', 'Q009', 'U008', '2024-10-09', 'Such a powerful statement!'), +('CMT010', 'Q010', 'U009', '2024-10-10', 'This is one of my favorites!'); From d21844dcc0ad6cadb8d866cfafcacb748ebf74bd Mon Sep 17 00:00:00 2001 From: Leni BEAULATON Date: Tue, 22 Oct 2024 09:12:56 +0200 Subject: [PATCH 2/3] =?UTF-8?q?Mise=20=C3=A0=20jour=20de=20'script.SQL'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- script.SQL | 132 ++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 120 insertions(+), 12 deletions(-) diff --git a/script.SQL b/script.SQL index ae23f3f..b91cc3e 100644 --- a/script.SQL +++ b/script.SQL @@ -1,12 +1,120 @@ -INSERT INTO Commentary (id_comment, quote, users, dateC, comment) -VALUES -('CMT001', 'Q001', 'U001', '2024-10-01', 'This quote really resonates with me.'), -('CMT002', 'Q002', 'U002', '2024-10-02', 'A timeless piece of wisdom.'), -('CMT003', 'Q003', 'U003', '2024-10-03', 'I disagree with this viewpoint.'), -('CMT004', 'Q004', 'U001', '2024-10-04', 'Absolutely love this quote!'), -('CMT005', 'Q005', 'U004', '2024-10-05', 'Very motivational, thanks for sharing!'), -('CMT006', 'Q006', 'U005', '2024-10-06', 'This makes me reflect on life.'), -('CMT007', 'Q007', 'U006', '2024-10-07', 'I find this quote very inspiring.'), -('CMT008', 'Q008', 'U007', '2024-10-08', 'I think there’s more to this than meets the eye.'), -('CMT009', 'Q009', 'U008', '2024-10-09', 'Such a powerful statement!'), -('CMT010', 'Q010', 'U009', '2024-10-10', 'This is one of my favorites!'); +-- Suppression des tables +DROP TABLE IF EXISTS Commentary; +DROP TABLE IF EXISTS Favorite; +DROP TABLE IF EXISTS Quote; +DROP TABLE IF EXISTS Caracter; +DROP TABLE IF EXISTS Source; +DROP TABLE IF EXISTS Record_quiz; +DROP TABLE IF EXISTS Quiz_Question; +DROP TABLE IF EXISTS Quiz; +DROP TABLE IF EXISTS Question; +DROP TABLE IF EXISTS Admin; +DROP TABLE IF EXISTS Users; +DROP TABLE IF EXISTS Image; + +-- Création des tables + +CREATE TABLE Image( + id_img SERIAL PRIMARY KEY, + imgPath varchar(100) NOT NULL UNIQUE +); + +CREATE TABLE Users( + id_user varchar(5) PRIMARY KEY, + username varchar(50) NOT NULL, + email varchar(50) NOT NULL, + pssword varchar(100) NOT NULL, + img SERIAL NOT NULL, + creation date NOT NULL, + CONSTRAINT unique_col UNIQUE (email), + CONSTRAINT fk_img FOREIGN KEY(img) REFERENCES Image(id_img) +); + +CREATE TABLE Admin( + users varchar(5) PRIMARY KEY, + CONSTRAINT fk_user FOREIGN KEY(users) REFERENCES Users(id_user) +); + +CREATE TABLE Question( + id_question SERIAL PRIMARY KEY, + texte text NOT NULL UNIQUE, + answerA varchar(30) NOT NULL, + answerB varchar(30) NOT NULL, + answerC varchar(30) NOT NULL, + answerD varchar(30) NOT NULL, + cAnswer varchar(30) NOT NULL, + CONSTRAINT check_cAnswer CHECK (cAnswer = answerA OR cAnswer = answerB OR cAnswer = answerC OR cAnswer = answerD) +); + +CREATE TABLE Quiz( + id_quiz SERIAL PRIMARY KEY, + levelQ numeric NOT NULL, + timer numeric NOT NULL +); + +CREATE TABLE Quiz_Question( + quiz SERIAL NOT NULL, + question SERIAL NOT NULL, + PRIMARY KEY (quiz, question), + CONSTRAINT fk_quiz FOREIGN KEY(quiz) REFERENCES Quiz(id_quiz), + CONSTRAINT fk_question FOREIGN KEY(question) REFERENCES Question(id_question) +); + +CREATE TABLE Record_quiz( + users varchar(5) NOT NULL, + quiz SERIAL NOT NULL, + nbPoint numeric DEFAULT '0', + timeQ numeric DEFAULT '0', + PRIMARY KEY (users, quiz), + CONSTRAINT fk_user FOREIGN KEY(users) REFERENCES Users(id_user), + CONSTRAINT fk_quiz FOREIGN KEY(quiz) REFERENCES Quiz(id_quiz), + CONSTRAINT err_nbPoint CHECK(nbPoint >= 0), + CONSTRAINT err_timeQ CHECK(timeQ >= 0) +); + +CREATE TABLE Source( + id_source SERIAL PRIMARY KEY, + title varchar(100) NOT NULL, + dateS date NOT NULL +); + +CREATE TABLE Caracter( + id_caracter SERIAL PRIMARY KEY, + caracter varchar(100) NOT NULL, + img_path varchar(100) NOT NULL +); + +CREATE TABLE Quote( + id_quote varchar(50) PRIMARY KEY, + content text NOT NULL, + likes numeric DEFAULT '0', + langue char(2) NOT NULL, + isValide boolean NOT NULL DEFAULT 'false', + reason varchar(100) NOT NULL, + id_caracter SERIAL NOT NULL, + id_source SERIAL NOT NULL, + id_user_verif varchar(5) NOT NULL, + CONSTRAINT fk_caracter FOREIGN KEY(id_caracter) REFERENCES Caracter(id_caracter), + CONSTRAINT fk_source FOREIGN KEY(id_source) REFERENCES Source(id_source), + CONSTRAINT fk_userverif FOREIGN KEY(id_user_verif) REFERENCES Users(id_user), + CONSTRAINT err_nbLike CHECK (likes >= 0), + CONSTRAINT err_language CHECK (langue = 'fr' OR langue = 'en') +); + +CREATE TABLE Favorite( + users varchar(5) NOT NULL, + quote varchar(50) NOT NULL, + PRIMARY KEY (users, quote), + CONSTRAINT fk_quote FOREIGN KEY(quote) REFERENCES Quote(id_quote), + CONSTRAINT fk_user FOREIGN KEY(users) REFERENCES Users(id_user) +); + +CREATE TABLE Commentary( + id_comment varchar(100) PRIMARY KEY, + quote varchar(50) NOT NULL, + users varchar(5) NOT NULL, + dateC date NOT NULL, + comment text NOT NULL, + CONSTRAINT fk_quote FOREIGN KEY(quote) REFERENCES Quote(id_quote), + CONSTRAINT fk_user FOREIGN KEY(users) REFERENCES Users(id_user) +); From d3d3fdc36ec30c1604f315719aecd0d27d652dc9 Mon Sep 17 00:00:00 2001 From: Leni BEAULATON Date: Tue, 22 Oct 2024 09:13:35 +0200 Subject: [PATCH 3/3] =?UTF-8?q?Mise=20=C3=A0=20jour=20de=20'insertion.sql'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- insertion.sql | 68 ++++++++++++++++++++++++++------------------------- 1 file changed, 35 insertions(+), 33 deletions(-) diff --git a/insertion.sql b/insertion.sql index f63bc34..16fb0ca 100644 --- a/insertion.sql +++ b/insertion.sql @@ -102,7 +102,7 @@ VALUES ('The Catcher in the Rye', '1951-07-16'), ('Moby Dick', '1851-10-18'), ('War and Peace', '1869-01-01'), -('The Odyssey', 'circa 8th century BC'), +('The Odyssey', '1320-01-01'), ('The Divine Comedy', '1320-01-01'), ('The Brothers Karamazov', '1880-11-01'); @@ -123,45 +123,47 @@ VALUES -- INSERTION TABLE Quote -INSERT INTO Quote (content, likes, langue, isValide, reason, id_caracter, id_source, id_user_verif) +INSERT INTO Quote (id_quote, content, likes, langue, isValide, reason, id_caracter, id_source, id_user_verif) VALUES -('Not all those who wander are lost.', 10, 'en', true, 'Inspirational quote', 1, 1, 'U001'), -('To be, or not to be, that is the question.', 15, 'en', true, 'Famous Shakespeare quote', 2, 2, 'U002'), -('C est la vie.', 5, 'fr', false, 'Incomplete context', 3, 3, 'U003'), -('All you need is love.', 20, 'en', true, 'Beatles quote', 4, 4, 'U004'), -('La vie est un défi, relève-le!', 8, 'fr', true, 'Motivational quote', 5, 5, 'U005'), -('To infinity and beyond!', 12, 'en', true, 'Toy Story quote', 6, 6, 'U006'), -('Veni, vidi, vici.', 18, 'fr', false, 'Historical reference', 7, 7, 'U007'), -('The only thing we have to fear is fear itself.', 25, 'en', true, 'Franklin D. Roosevelt', 8, 8, 'U008'), -('L imagination est plus importante que la connaissance.', 30, 'fr', true, 'Einstein quote', 9, 9, 'U009'), -('In three words I can sum up everything I ve learned about life: it goes on.', 22, 'en', true, 'Robert Frost', 10, 10, 'U010'); +('Q001', 'Not all those who wander are lost.', 10, 'en', true, 'Inspirational quote', 1, 1, 'U001'), +('Q002', 'To be, or not to be, that is the question.', 15, 'en', true, 'Famous Shakespeare quote', 2, 2, 'U002'), +('Q003', 'C est la vie.', 5, 'fr', false, 'Incomplete context', 3, 3, 'U003'), +('Q004', 'All you need is love.', 20, 'en', true, 'Beatles quote', 4, 4, 'U004'), +('Q005', 'La vie est un défi, relève-le!', 8, 'fr', true, 'Motivational quote', 5, 5, 'U005'), +('Q006', 'To infinity and beyond!', 12, 'en', true, 'Toy Story quote', 6, 6, 'U006'), +('Q007', 'Veni, vidi, vici.', 18, 'fr', false, 'Historical reference', 7, 7, 'U007'), +('Q008', 'The only thing we have to fear is fear itself.', 25, 'en', true, 'Franklin D. Roosevelt', 8, 8, 'U008'), +('Q009', 'L imagination est plus importante que la connaissance.', 30, 'fr', true, 'Einstein quote', 9, 9, 'U009'), +('Q010', 'In three words I can sum up everything I ve learned about life: it goes on.', 22, 'en', true, 'Robert Frost', 10, 10, 'U010'); -- INSERTION TABLE Favorite INSERT INTO Favorite (users, quote) VALUES -('U001', 1), -('U002', 2), -('U003', 3), -('U001', 4), -('U004', 1), -('U005', 5), -('U003', 2), -('U007', 7), -('U008', 8), -('U002', 9); +('U001', 'Q001'), -- User U001 favorites Quote Q001 +('U002', 'Q002'), -- User U002 favorites Quote Q002 +('U003', 'Q003'), -- User U003 favorites Quote Q003 +('U001', 'Q004'), -- User U001 also favorites Quote Q004 +('U004', 'Q001'), -- User U004 favorites Quote Q001 +('U005', 'Q005'), -- User U005 favorites Quote Q005 +('U006', 'Q002'), -- User U006 favorites Quote Q002 +('U007', 'Q007'), -- User U007 favorites Quote Q007 +('U008', 'Q008'), -- User U008 favorites Quote Q008 +('U009', 'Q009'); -- User U009 favorites Quote Q009 + -- INSERTION TABLE Commentary -INSERT INTO Commentary (quote, users, dateC, comment) +INSERT INTO Commentary (id_comment, quote, users, dateC, comment) VALUES -(1, 'U001', '2024-10-01', 'This quote really resonates with me.'), -(2, 'U002', '2024-10-02', 'A timeless piece of wisdom.'), -(3, 'U003', '2024-10-03', 'I disagree with this viewpoint.'), -(4, 'U001', '2024-10-04', 'Absolutely love this quote!'), -(5, 'U004', '2024-10-05', 'Very motivational, thanks for sharing!'), -(6, 'U005', '2024-10-06', 'This makes me reflect on life.'), -(7, 'U006', '2024-10-07', 'I find this quote very inspiring.'), -(8, 'U007', '2024-10-08', 'I think there’s more to this than meets the eye.'), -(9, 'U008', '2024-10-09', 'Such a powerful statement!'), -(10, 'U009', '2024-10-10', 'This is one of my favorites!'); +('C00001', 'Q001', 'U001', '2024-10-01', 'This quote really resonates with me.'), +('C00002', 'Q002', 'U002', '2024-10-02', 'A timeless piece of wisdom.'), +('C00003', 'Q003', 'U003', '2024-10-03', 'I disagree with this viewpoint.'), +('C00004', 'Q004', 'U001', '2024-10-04', 'Absolutely love this quote!'), +('C00005', 'Q005', 'U004', '2024-10-05', 'Very motivational, thanks for sharing!'), +('C00006', 'Q006', 'U005', '2024-10-06', 'This makes me reflect on life.'), +('C00007', 'Q007', 'U006', '2024-10-07', 'I find this quote very inspiring.'), +('C00008', 'Q008', 'U007', '2024-10-08', 'I think there’s more to this than meets the eye.'), +('C00009', 'Q009', 'U008', '2024-10-09', 'Such a powerful statement!'), +('C00010', 'Q010', 'U009', '2024-10-10', 'This is one of my favorites!'); +