diff --git a/Documentation/script_bdd.sql b/Documentation/script_bdd.sql index 6d0ec91..6f75065 100644 --- a/Documentation/script_bdd.sql +++ b/Documentation/script_bdd.sql @@ -1,148 +1,134 @@ -- Testé sous pgsql 15 -DROP TABLE IF EXISTS Reponse; - -DROP TABLE IF EXISTS Question; - -DROP TABLE IF EXISTS Admin; - -DROP TABLE IF EXISTS Partie; - -DROP TABLE IF EXISTS Jeu; - -DROP TABLE IF EXISTS Decouvrir; - -DROP TABLE IF EXISTS Utilisateur; - -DROP TABLE IF EXISTS Invite; - -DROP TABLE IF EXISTS Joueur; - -DROP TABLE IF EXISTS Indice; - -DROP TABLE IF EXISTS Scientifique; - -DROP TABLE IF EXISTS Thematique; - +DROP TABLE IF EXISTS Reponse CASCADE; +DROP TABLE IF EXISTS Question CASCADE; +DROP TABLE IF EXISTS Admin CASCADE; +DROP TABLE IF EXISTS Partie CASCADE; +DROP TABLE IF EXISTS Jeu CASCADE; +DROP TABLE IF EXISTS Decouvrir CASCADE; +DROP TABLE IF EXISTS Utilisateur CASCADE; +DROP TABLE IF EXISTS Invite CASCADE; +DROP TABLE IF EXISTS Joueur CASCADE; +DROP TABLE IF EXISTS Indice CASCADE; +DROP TABLE IF EXISTS Scientifique CASCADE; +DROP TABLE IF EXISTS Thematique CASCADE; DROP TABLE IF EXISTS Difficulte; -- THEMATIQUE CREATE TABLE Thematique( - id SERIAL PRIMARY KEY, - libelle varchar(128) NOT NULL UNIQUE + id SERIAL PRIMARY KEY, + libelle varchar(128) NOT NULL UNIQUE ); -- DIFFICULTE CREATE TABLE Difficulte( - id SERIAL PRIMARY KEY, - libelle varchar(128) NOT NULL UNIQUE + id SERIAL PRIMARY KEY, + libelle varchar(128) NOT NULL UNIQUE ); -- SCIENTIFIQUE CREATE TABLE Scientifique( - id SERIAL PRIMARY KEY, - nom varchar(128) NOT NULL, - prenom varchar(128) NOT NULL, - photo varchar(512) NOT NULL, - dateNaissance date NOT NULL, - descriptif text NOT NULL, - ratioTrouvee numeric(5,4), - sexe char(1) NOT NULL CHECK(sexe IN ('F', 'H')), - idThematique integer REFERENCES Thematique(id), - idDifficulte integer REFERENCES Difficulte(id), + id SERIAL PRIMARY KEY, + nom varchar(128) NOT NULL, + prenom varchar(128) NOT NULL, + photo varchar(512) NOT NULL, + dateNaissance date NOT NULL, + descriptif text NOT NULL, + ratioTrouvee numeric(5,4), + sexe char(1) NOT NULL CHECK(sexe IN ('F', 'H')), + idThematique integer REFERENCES Thematique(id), + idDifficulte integer REFERENCES Difficulte(id) ); -- INDICE CREATE TABLE Indice( - id SERIAL PRIMARY KEY, - libelle varchar(512) NOT NULL UNIQUE, - idScientifique integer REFERENCES Scientifique(id) + id SERIAL PRIMARY KEY, + libelle varchar(512) NOT NULL UNIQUE, + idScientifique integer REFERENCES Scientifique(id) ); -- QUESTION CREATE TABLE Question( - id SERIAL PRIMARY KEY, - question varchar(256) NOT NULL UNIQUE + id SERIAL PRIMARY KEY, + question varchar(256) NOT NULL UNIQUE ); -- REPONSE CREATE TABLE Reponse( - id SERIAL PRIMARY KEY, - reponse varchar(255) NOT NULL, - idQuestion integer REFERENCES Question(id), - idScientifique integer REFERENCES Scientifique(id) + id SERIAL PRIMARY KEY, + reponse varchar(255) NOT NULL, + idQuestion integer REFERENCES Question(id), + idScientifique integer REFERENCES Scientifique(id) ); -- ADMIN CREATE TABLE Admin( - id SERIAL PRIMARY KEY, - email varchar(255) NOT NULL UNIQUE, - password varchar(255) NOT NULL + id SERIAL PRIMARY KEY, + email varchar(255) NOT NULL UNIQUE, + password varchar(255) NOT NULL +); + +-- Jeu + +CREATE TABLE Jeu( + id SERIAL PRIMARY KEY, + nom varchar(128) NOT NULL UNIQUE, + nbrParties integer NOT NULL DEFAULT 0 ); +-- Partie + +CREATE TABLE Partie( + id SERIAL PRIMARY KEY, + codeInvitation varchar(10) NOT NULL UNIQUE, + idJeu integer REFERENCES Jeu(id) +); + -- JOUEUR CREATE TABLE Joueur( - id SERIAL PRIMARY KEY, - idPartie integer REFERENCES Partie(id), - pseudo varchar(255) NOT NULL UNIQUE + id SERIAL PRIMARY KEY, + idPartie integer REFERENCES Partie(id), + pseudo varchar(255) NOT NULL UNIQUE ); -- Invite CREATE TABLE Invite( - idJoueur integer PRIMARY KEY REFERENCES Joueur(id), + idJoueur integer PRIMARY KEY REFERENCES Joueur(id) ); -- Utilisateur CREATE TABLE Utilisateur( - idJoueur integer PRIMARY KEY REFERENCES Joueur(id), - email varchar(255) NOT NULL UNIQUE, - password varchar(255) NOT NULL + idJoueur integer PRIMARY KEY REFERENCES Joueur(id), + email varchar(255) NOT NULL UNIQUE, + password varchar(255) NOT NULL ); -- Decouvrir CREATE TABLE Decouvrir( - idUtilisateur integer REFERENCES Utilisateur(idJoueur), - idScientifique integer REFERENCES Scientifique(id), - PRIMARY KEY (idUtilisateur, idScientifique) -); - - --- Jeu - -CREATE TABLE Jeu( - id SERIAL PRIMARY KEY, - nom varchar(128) NOT NULL UNIQUE, - nbrParties integer NOT NULL DEFAULT 0 -); - - --- Partie - -CREATE TABLE Partie( - id SERIAL PRIMARY KEY, - codeInvitation varchar(10) NOT NULL UNIQUE, - idJeu integer REFERENCES Jeu(id) + idUtilisateur integer REFERENCES Utilisateur(idJoueur), + idScientifique integer REFERENCES Scientifique(id), + PRIMARY KEY (idUtilisateur, idScientifique) ); @@ -151,7 +137,7 @@ CREATE TABLE Partie( -- Scientifiques INSERT INTO Difficulte(libelle) VALUES ('Facile'),('Intermédiaire'),('Difficile'); INSERT INTO Thematique(libelle) VALUES ('Nucléaire'),('Mathématiques'); -INSERT INTO Scientifique(nom, prenom, photo, dateNaissance, descriptif, ratioTrouvee, idThematique, idDifficulte, idSexe) +INSERT INTO Scientifique(nom, prenom, photo, dateNaissance, descriptif, ratioTrouvee, idThematique, idDifficulte, sexe) VALUES ('Marie', 'Curie', '', CURRENT_DATE, 'desc', 0, 1, 1, 'F'), ('Albert', 'Einstein', '', CURRENT_DATE, 'desc', 0, 2, 1, 'H'),