diff --git a/README.md b/README.md index f1e4c82..c7036e1 100644 --- a/README.md +++ b/README.md @@ -15,3 +15,4 @@ Dans /conteneur *applicatif: a faire *CPU, RAM... donc on renvoie les metrics avec node exporter +et │ └── supervisord.conf # Mis à jour ? diff --git a/centre_observabilite/loki-chunks/ZmFrZS84YjExMGExMjYyMzFjNjcwOjE5YjRiMDdjNzM0OjE5YjRiMDdjYjIwOjE0ZjhiN2Ux b/centre_observabilite/loki-chunks/ZmFrZS84YjExMGExMjYyMzFjNjcwOjE5YjRiMDdjNzM0OjE5YjRiMDdjYjIwOjE0ZjhiN2Ux new file mode 100644 index 0000000..fc309fa Binary files /dev/null and b/centre_observabilite/loki-chunks/ZmFrZS84YjExMGExMjYyMzFjNjcwOjE5YjRiMDdjNzM0OjE5YjRiMDdjYjIwOjE0ZjhiN2Ux differ diff --git a/centre_observabilite/loki-chunks/ZmFrZS84YjExMGExMjYyMzFjNjcwOjE5YjRiMTBlZjYzOjE5YjRiMTBlZjY0OmU3NjA3ODFi b/centre_observabilite/loki-chunks/ZmFrZS84YjExMGExMjYyMzFjNjcwOjE5YjRiMTBlZjYzOjE5YjRiMTBlZjY0OmU3NjA3ODFi new file mode 100644 index 0000000..f57a699 Binary files /dev/null and b/centre_observabilite/loki-chunks/ZmFrZS84YjExMGExMjYyMzFjNjcwOjE5YjRiMTBlZjYzOjE5YjRiMTBlZjY0OmU3NjA3ODFi differ diff --git a/centre_observabilite/loki-chunks/ZmFrZS84YjExMGExMjYyMzFjNjcwOjE5YjRiMWExNjhjOjE5YjRiMWI5NTc4OmFjM2Y5OTg1 b/centre_observabilite/loki-chunks/ZmFrZS84YjExMGExMjYyMzFjNjcwOjE5YjRiMWExNjhjOjE5YjRiMWI5NTc4OmFjM2Y5OTg1 new file mode 100644 index 0000000..a5ca7dc Binary files /dev/null and b/centre_observabilite/loki-chunks/ZmFrZS84YjExMGExMjYyMzFjNjcwOjE5YjRiMWExNjhjOjE5YjRiMWI5NTc4OmFjM2Y5OTg1 differ diff --git a/centre_observabilite/loki-chunks/ZmFrZS84YjExMGExMjYyMzFjNjcwOjE5YjRiMjMzZjJhOjE5YjRiMjMzZjJiOjY3ZTgyOGI5 b/centre_observabilite/loki-chunks/ZmFrZS84YjExMGExMjYyMzFjNjcwOjE5YjRiMjMzZjJhOjE5YjRiMjMzZjJiOjY3ZTgyOGI5 new file mode 100644 index 0000000..662aa9f Binary files /dev/null and b/centre_observabilite/loki-chunks/ZmFrZS84YjExMGExMjYyMzFjNjcwOjE5YjRiMjMzZjJhOjE5YjRiMjMzZjJiOjY3ZTgyOGI5 differ diff --git a/centre_observabilite/loki-chunks/index/index_20445/compactor-1766490438.gz b/centre_observabilite/loki-chunks/index/index_20445/compactor-1766490438.gz deleted file mode 100644 index 86c1d06..0000000 Binary files a/centre_observabilite/loki-chunks/index/index_20445/compactor-1766490438.gz and /dev/null differ diff --git a/centre_observabilite/loki-chunks/index/index_20445/compactor-1766492238.gz b/centre_observabilite/loki-chunks/index/index_20445/compactor-1766492238.gz new file mode 100644 index 0000000..aad5998 Binary files /dev/null and b/centre_observabilite/loki-chunks/index/index_20445/compactor-1766492238.gz differ diff --git a/centre_observabilite/loki-index/index_20445/1766490418758646762.temp b/centre_observabilite/loki-index/index_20445/1766490418758646762.temp deleted file mode 100644 index 5243edc..0000000 Binary files a/centre_observabilite/loki-index/index_20445/1766490418758646762.temp and /dev/null differ diff --git a/centre_observabilite/loki-index/index_20445/1766491200 b/centre_observabilite/loki-index/index_20445/1766491200 new file mode 100644 index 0000000..0d1f72d Binary files /dev/null and b/centre_observabilite/loki-index/index_20445/1766491200 differ diff --git a/centre_observabilite/loki-index/index_20445/1766492100 b/centre_observabilite/loki-index/index_20445/1766492100 new file mode 100644 index 0000000..201531d Binary files /dev/null and b/centre_observabilite/loki-index/index_20445/1766492100 differ diff --git a/centre_observabilite/loki-index/index_20445/1766492100.snapshot b/centre_observabilite/loki-index/index_20445/1766492100.snapshot new file mode 100644 index 0000000..a767940 Binary files /dev/null and b/centre_observabilite/loki-index/index_20445/1766492100.snapshot differ diff --git a/centre_observabilite/loki-index/index_20445/1766492218757756986.temp b/centre_observabilite/loki-index/index_20445/1766492218757756986.temp new file mode 100644 index 0000000..60294e7 Binary files /dev/null and b/centre_observabilite/loki-index/index_20445/1766492218757756986.temp differ diff --git a/centre_observabilite/loki-index/index_20445/1766489863 b/centre_observabilite/loki-index/index_20445/compactor-1766492238 similarity index 53% rename from centre_observabilite/loki-index/index_20445/1766489863 rename to centre_observabilite/loki-index/index_20445/compactor-1766492238 index 168d655..3959e4c 100644 Binary files a/centre_observabilite/loki-index/index_20445/1766489863 and b/centre_observabilite/loki-index/index_20445/compactor-1766492238 differ diff --git a/centre_observabilite/loki-wal/00000101 b/centre_observabilite/loki-wal/00000101 deleted file mode 100644 index bb42e8d..0000000 Binary files a/centre_observabilite/loki-wal/00000101 and /dev/null differ diff --git a/centre_observabilite/loki-wal/00000102 b/centre_observabilite/loki-wal/00000102 deleted file mode 100644 index 6d15d7d..0000000 Binary files a/centre_observabilite/loki-wal/00000102 and /dev/null differ diff --git a/centre_observabilite/loki-wal/00000109 b/centre_observabilite/loki-wal/00000109 new file mode 100644 index 0000000..7f63d4a Binary files /dev/null and b/centre_observabilite/loki-wal/00000109 differ diff --git a/centre_observabilite/loki-wal/00000110 b/centre_observabilite/loki-wal/00000110 new file mode 100644 index 0000000..99df8b6 Binary files /dev/null and b/centre_observabilite/loki-wal/00000110 differ diff --git a/centre_observabilite/loki-wal/checkpoint.000100/00000000 b/centre_observabilite/loki-wal/checkpoint.000100/00000000 deleted file mode 100644 index 9b39788..0000000 Binary files a/centre_observabilite/loki-wal/checkpoint.000100/00000000 and /dev/null differ diff --git a/centre_observabilite/loki-wal/checkpoint.000108/00000000 b/centre_observabilite/loki-wal/checkpoint.000108/00000000 new file mode 100644 index 0000000..c263206 Binary files /dev/null and b/centre_observabilite/loki-wal/checkpoint.000108/00000000 differ diff --git a/centre_observabilite/loki-wal/checkpoint.000101.tmp/00000000 b/centre_observabilite/loki-wal/checkpoint.000109.tmp/00000000 similarity index 100% rename from centre_observabilite/loki-wal/checkpoint.000101.tmp/00000000 rename to centre_observabilite/loki-wal/checkpoint.000109.tmp/00000000 diff --git a/conteneur/Dockerfile b/conteneur/Dockerfile index e9b26f6..f4aac4f 100644 --- a/conteneur/Dockerfile +++ b/conteneur/Dockerfile @@ -1,14 +1,30 @@ FROM debian:bullseye-slim -# Installation des dépendances +# Installation des dépendances de base RUN apt-get update && apt-get install -y \ apache2 \ supervisor \ wget \ curl \ unzip \ + gnupg \ + lsb-release \ + openjdk-17-jdk \ && rm -rf /var/lib/apt/lists/* +# Installation de Tomcat 10 +RUN cd /opt && \ + wget https://archive.apache.org/dist/tomcat/tomcat-10/v10.1.47/bin/apache-tomcat-10.1.47.tar.gz && \ + tar -xzf apache-tomcat-10.1.47.tar.gz && \ + mv apache-tomcat-10.1.47 tomcat && \ + rm apache-tomcat-10.1.47.tar.gz && \ + chmod +x /opt/tomcat/bin/*.sh + +# Variables d'environnement Tomcat +ENV CATALINA_HOME=/opt/tomcat +ENV JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64 +ENV PATH=$PATH:$CATALINA_HOME/bin + # Installation Apache Exporter RUN wget https://github.com/Lusitaniae/apache_exporter/releases/download/v1.0.10/apache_exporter-1.0.10.linux-amd64.tar.gz \ && tar xzf apache_exporter-1.0.10.linux-amd64.tar.gz \ @@ -39,11 +55,23 @@ RUN echo '\n\ Require all granted\n\ ' > /etc/apache2/conf-available/server-status.conf \ && a2enconf server-status \ - && a2enmod status + && a2enmod status \ + && a2enmod proxy \ + && a2enmod proxy_http + +# Configuration du proxy Apache vers Tomcat +RUN echo '\n\ + ProxyPreserveHost On\n\ + ProxyPass /api http://localhost:8080/api\n\ + ProxyPassReverse /api http://localhost:8080/api\n\ +' > /etc/apache2/sites-available/000-default.conf # Création des répertoires de logs -RUN mkdir -p /var/log/apache2 /var/log/promtail +RUN mkdir -p /var/log/apache2 /var/log/promtail /opt/tomcat/logs -EXPOSE 80 9100 9117 9080 +# Copie du WAR (à placer dans le contexte de build) +COPY archiweb-api-1.0.0.war /opt/tomcat/webapps/api.war + +EXPOSE 80 8080 9100 9117 9080 CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"] diff --git a/conteneur/configs/promtail/config.yaml b/conteneur/configs/promtail/config.yaml index fcfb2a7..704d06e 100644 --- a/conteneur/configs/promtail/config.yaml +++ b/conteneur/configs/promtail/config.yaml @@ -14,7 +14,7 @@ scrape_configs: - targets: [localhost] labels: job: apache_access - host: apache_all_in_one + host: archiweb_app __path__: /var/log/apache2/access.log - job_name: apache_error @@ -22,5 +22,41 @@ scrape_configs: - targets: [localhost] labels: job: apache_error - host: apache_all_in_one + host: archiweb_app __path__: /var/log/apache2/error.log + + - job_name: tomcat_catalina + static_configs: + - targets: [localhost] + labels: + job: tomcat + host: archiweb_app + type: catalina + __path__: /opt/tomcat/logs/catalina*.log + + - job_name: tomcat_localhost + static_configs: + - targets: [localhost] + labels: + job: tomcat + host: archiweb_app + type: localhost + __path__: /opt/tomcat/logs/localhost*.log + + - job_name: tomcat_access + static_configs: + - targets: [localhost] + labels: + job: tomcat + host: archiweb_app + type: access + __path__: /opt/tomcat/logs/localhost_access_log*.txt + + - job_name: tomcat_out + static_configs: + - targets: [localhost] + labels: + job: tomcat + host: archiweb_app + type: out + __path__: /opt/tomcat/logs/catalina.out diff --git a/conteneur/database/data.sql b/conteneur/database/data.sql new file mode 100644 index 0000000..3078e49 --- /dev/null +++ b/conteneur/database/data.sql @@ -0,0 +1,111 @@ +-- Ajout des rôles +INSERT INTO role (nom) +VALUES ('Administrateur'), + ('Enseignant'), + ('Étudiant'); + +-- Ajout des utilisateurs +INSERT INTO utilisateur (login, mot_de_passe, nom, prenom, email) +VALUES ('jlpicar', 'password', 'Picard', 'Jean-Luc', 'jean-luc.picard@starfleet.com'), + ('kjaneway', 'password', 'Janeway', 'Kathryn', 'kathryn.janeway@starfleet.com'), + ('spock', 'password', '', 'Spock', 'spock@starfleet.com'), + ('wriker', 'password', 'Riker', 'William', 'william.riker@starfleet.com'), + ('data', 'password', '', 'Data', 'data@starfleet.com'), + ('glaforge', 'password', 'LaForge', 'Geordi', 'geordi.laforge@starfleet.com'), + ('tuvok', 'password', 'Tuvok', '', 'tuvok@starfleet.com'), + ('wcrusher', 'password', 'Crusher', 'Wesley', 'wesley.crusher@starfleet.com'), + ('tparis', 'password', 'Paris', 'Tom', 'tom.paris@starfleet.com'), + ('hkim', 'password', 'Kim', 'Harry', 'harry.kim@starfleet.com'), + ('jsisko', 'password', 'Sisko', 'Jake', 'jake.sisko@starfleet.com'), + ('nog', 'password', '', 'Nog', 'nog@starfleet.com'), + ('bmariner', 'password', 'Mariner', 'Beckett', 'beckett.mariner@starfleet.com'), + ('bboimler', 'password', 'Boimler', 'Brad', 'brad.boimler@starfleet.com'), + ('dvtendi', 'password', 'Tendi', 'D''Vana', 'd-vana.tendi@starfleet.com'), + ('srutherf', 'password', 'Rutherford', 'Sam', 'sam.rutherford@starfleet.com'), + ('drel', 'password', 'R''El', 'Dal', 'dal.r-el@starfleet.com'), + ('gwyndala', 'password', '', 'Gwyndala', 'gwyndala@starfleet.com'), + ('roktahk', 'password', '', 'Rok-Tahk', 'rok-takh@starfleet.com'), + ('zero', 'password', 'Zero', '', 'zero@starfleet.com'), + ('jpog', 'password', 'Pog', 'Jankom', 'jankom.pog@starfleet.com'), + ('murf', 'password', '', 'Murf', 'murf@starfleet.com'); + +-- Ajout des rôles aux utilisateurs +INSERT INTO utilisateur_role (utilisateur_id, role_id) +VALUES ((select id from utilisateur where login = 'jlpicar'), 1), -- Picard as Administrator + ((select id from utilisateur where login = 'kjaneway'), 1), -- Janeway as Administrator + ((select id from utilisateur where login = 'spock'), 2), -- Spock as Teacher + ((select id from utilisateur where login = 'wriker'), 2), -- Riker as Teacher + ((select id from utilisateur where login = 'data'), 2), -- Data as Teacher + ((select id from utilisateur where login = 'glaforge'), 2), -- LaForge as Teacher + ((select id from utilisateur where login = 'tuvok'), 2), -- Tuvok as Teacher + ((select id from utilisateur where login = 'wcrusher'), 3), -- Crusher as Student + ((select id from utilisateur where login = 'tparis'), 3), -- Paris as Student + ((select id from utilisateur where login = 'hkim'), 3), -- Kim as Student + ((select id from utilisateur where login = 'jsisko'), 3), -- Sisko as Student + ((select id from utilisateur where login = 'nog'), 3), -- Nog as Student + ((select id from utilisateur where login = 'bmariner'), 3), -- Mariner as Student + ((select id from utilisateur where login = 'bboimler'), 3), -- Boimler as Student + ((select id from utilisateur where login = 'dvtendi'), 3), -- Tendi as Student + ((select id from utilisateur where login = 'srutherf'), 3), -- Rutherford as Student + ((select id from utilisateur where login = 'drel'), 3), -- R'El as Student + ((select id from utilisateur where login = 'gwyndala'), 3), -- Gwyndala as Student + ((select id from utilisateur where login = 'roktahk'), 3), -- Rok-Tahk as Student + ((select id from utilisateur where login = 'zero'), 3), -- Zero as Student + ((select id from utilisateur where login = 'jpog'), 3), -- Pog as Student + ((select id from utilisateur where login = 'murf'), 3); +-- Murf as Student + +-- Ajout des cours +INSERT INTO cours (nom, date_debut) +VALUES ('Starship Command', '2023-01-01'), + ('Warp Theory', '2023-02-01'), + ('Federation Ethics', '2023-03-01'); + +-- Ajout des enseignements +INSERT INTO enseignement (utilisateur_id, cours_id) +VALUES ((select id from utilisateur where login = 'spock'), 1), -- Spock teaches Starship Command + ((select id from utilisateur where login = 'wriker'), 1), -- Riker teaches Starship Command + ((select id from utilisateur where login = 'data'), 2), -- Data teaches Warp Theory + ((select id from utilisateur where login = 'glaforge'), 2), -- LaForge teaches Warp Theory + ((select id from utilisateur where login = 'tuvok'), 3); +-- Tuvok teaches Federation Ethics + +-- Ajout des inscriptions +INSERT INTO inscription (utilisateur_id, cours_id) +VALUES ((select id from utilisateur where login = 'wcrusher'), 1), -- Crusher enrolls in Starship Command + ((select id from utilisateur where login = 'wcrusher'), 2), -- Crusher enrolls in Warp Theory + ((select id from utilisateur where login = 'tparis'), 1), -- Paris enrolls in Starship Command + ((select id from utilisateur where login = 'hkim'), 1), -- Kim enrolls in Starship Command + ((select id from utilisateur where login = 'jsisko'), 3), -- Sisko enrolls in Federation Ethics + ((select id from utilisateur where login = 'nog'), 1), -- Nog enrolls in Starship Command + ((select id from utilisateur where login = 'nog'), 3), -- Nog enrolls in Federation Ethics + ((select id from utilisateur where login = 'bboimler'), 1), -- Boimler enrolls in Starship Command + ((select id from utilisateur where login = 'dvtendi'), 2), -- Tendi enrolls in Warp Theory + ((select id from utilisateur where login = 'srutherf'), 2), -- Rutherford enrolls in Warp Theory + ((select id from utilisateur where login = 'drel'), 1), -- R'El enrolls in Starship Command + ((select id from utilisateur where login = 'gwyndala'), 1), -- Gwyndala enrolls in Starship Command + ((select id from utilisateur where login = 'gwyndala'), 3), -- Gwyndala enrolls in Federation Ethics + ((select id from utilisateur where login = 'roktahk'), 2), -- Rok-Tahk enrolls in Warp Theory + ((select id from utilisateur where login = 'zero'), 3), -- Zero enrolls in Federation Ethics + ((select id from utilisateur where login = 'jpog'), 2); +-- Pog enrolls in Warp Theory + +-- Ajout des contenus de cours +INSERT INTO contenu_cours (cours_id, titre, description) +VALUES (1, 'Bridge Operations', 'Learn how to manage starship operations.'), + (1, 'Tactical Maneuvers', 'Advanced starship tactics.'), + (1, 'Command Decision Making', 'Develop leadership skills for commanding a starship.'), + (2, 'Warp Core Mechanics', 'Understand the inner workings of warp cores.'), + (2, 'Dilithium Crystals', 'Study the properties of dilithium crystals.'), + (2, 'Warp Field Theory', 'Explore the physics behind warp travel.'), + (3, 'Prime Directive', 'Ethical dilemmas in space exploration.'), + (3, 'Cultural Sensitivity', 'Learn how to interact with alien civilizations.'), + (3, 'Federation Law', 'Understand the legal framework of the Federation.'); + +-- Ajout des devoirs +INSERT INTO devoir (cours_id, titre, description, date_debut, date_fin) +VALUES (1, 'Bridge Simulation', 'Participate in a simulated bridge operation.', '2023-01-15', '2023-01-30'), + (1, 'Tactical Exercise', 'Plan and execute tactical maneuvers.', '2023-01-20', '2023-02-05'), + (2, 'Warp Core Analysis', 'Analyze the efficiency of a warp core.', '2023-02-10', '2023-02-25'), + (2, 'Crystal Experiment', 'Experiment with dilithium crystals.', '2023-02-15', '2023-03-01'), + (3, 'Prime Directive Case Study', 'Discuss ethical dilemmas.', '2023-03-10', '2023-03-25'); diff --git a/conteneur/database/schema.sql b/conteneur/database/schema.sql new file mode 100644 index 0000000..65aa308 --- /dev/null +++ b/conteneur/database/schema.sql @@ -0,0 +1,136 @@ +-- Drop tables if they exist +DROP TABLE IF EXISTS note; +DROP TABLE IF EXISTS rendu_devoir; +DROP TABLE IF EXISTS devoir; +DROP TABLE IF EXISTS contenu_cours; +DROP TABLE IF EXISTS inscription; +DROP TABLE IF EXISTS enseignement; +DROP TABLE IF EXISTS cours; +DROP TABLE IF EXISTS utilisateur_role; +DROP TABLE IF EXISTS role; +DROP TABLE IF EXISTS utilisateur; + +-- Table utilisateur : représente un utilisateur de l'application +CREATE TABLE utilisateur +( + id BIGSERIAL NOT NULL, + login VARCHAR(8) NOT NULL, + mot_de_passe VARCHAR(255) NOT NULL, + nom VARCHAR(100), + prenom VARCHAR(100), + email VARCHAR(255), + PRIMARY KEY (id), + CONSTRAINT ux_u_login UNIQUE (login), + CONSTRAINT ux_u_email UNIQUE (email) +); +CREATE INDEX ix_u_login ON utilisateur (login); + +-- Table role : représente un rôle d'utilisateur +CREATE TABLE role +( + id BIGSERIAL NOT NULL, + nom VARCHAR(100) NOT NULL, + PRIMARY KEY (id), + CONSTRAINT ux_r_nom UNIQUE (nom) +); +CREATE INDEX ix_r_nom ON role (nom); + +-- Table utilisateur_role : association entre utilisateurs et rôles +CREATE TABLE utilisateur_role +( + utilisateur_id BIGINT NOT NULL, + role_id BIGINT NOT NULL, + PRIMARY KEY (utilisateur_id, role_id), + CONSTRAINT fk_ur_utilisateur_id FOREIGN KEY (utilisateur_id) REFERENCES utilisateur (id) ON DELETE CASCADE, + CONSTRAINT fk_ur_role_id FOREIGN KEY (role_id) REFERENCES role (id) ON DELETE CASCADE +); +CREATE INDEX ix_ur_utilisateur_id ON utilisateur_role (utilisateur_id); +CREATE INDEX ix_ur_role_id ON utilisateur_role (role_id); + +-- Table cours : représente un cours +CREATE TABLE cours +( + id BIGSERIAL NOT NULL, + nom VARCHAR(100) NOT NULL, + date_debut DATE NOT NULL, + PRIMARY KEY (id) +); +CREATE INDEX ix_c_nom ON cours (nom); + +-- Table enseignement : association entre utilisateurs et cours +CREATE TABLE enseignement +( + utilisateur_id BIGINT NOT NULL, + cours_id BIGINT NOT NULL, + PRIMARY KEY (utilisateur_id, cours_id), + CONSTRAINT fk_e_utilisateur_id FOREIGN KEY (utilisateur_id) REFERENCES utilisateur (id) ON DELETE CASCADE, + CONSTRAINT fk_e_cours_id FOREIGN KEY (cours_id) REFERENCES cours (id) ON DELETE CASCADE +); +CREATE INDEX ix_e_utilisateur_id ON enseignement (utilisateur_id); +CREATE INDEX ix_e_cours_id ON enseignement (cours_id); + +-- Table inscription : association entre utilisateurs et cours +CREATE TABLE inscription +( + utilisateur_id BIGINT NOT NULL, + cours_id BIGINT NOT NULL, + date_inscription TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + PRIMARY KEY (utilisateur_id, cours_id), + CONSTRAINT fk_i_utilisateur_id FOREIGN KEY (utilisateur_id) REFERENCES utilisateur (id) ON DELETE CASCADE, + CONSTRAINT fk_i_cours_id FOREIGN KEY (cours_id) REFERENCES cours (id) ON DELETE CASCADE +); +CREATE INDEX ix_i_utilisateur_id ON inscription (utilisateur_id); +CREATE INDEX ix_i_cours_id ON inscription (cours_id); + +-- Table contenu_cours : représente le contenu d'un cours +CREATE TABLE contenu_cours +( + id BIGSERIAL NOT NULL, + cours_id BIGINT NOT NULL, + titre VARCHAR(255) NOT NULL, + description TEXT, + PRIMARY KEY (id), + CONSTRAINT fk_cc_cours_id FOREIGN KEY (cours_id) REFERENCES cours (id) ON DELETE CASCADE +); +CREATE INDEX ix_cc_cours_id ON contenu_cours (cours_id); + +-- Table devoir : représente un devoir associé à un cours +CREATE TABLE devoir +( + id BIGSERIAL NOT NULL, + cours_id BIGINT NOT NULL, + titre VARCHAR(255) NOT NULL, + description TEXT, + date_debut TIMESTAMP NOT NULL, + date_fin TIMESTAMP NOT NULL, + PRIMARY KEY (id), + CONSTRAINT fk_d_cours_id FOREIGN KEY (cours_id) REFERENCES cours (id) ON DELETE CASCADE +); +CREATE INDEX ix_d_cours_id ON devoir (cours_id); + +-- Table rendu_devoir : représente le rendu d'un devoir par un utilisateur +CREATE TABLE rendu_devoir +( + id BIGSERIAL NOT NULL, + devoir_id BIGINT NOT NULL, + utilisateur_id BIGINT NOT NULL, + date_rendu TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + contenu TEXT, + PRIMARY KEY (id), + CONSTRAINT fk_rd_devoir_id FOREIGN KEY (devoir_id) REFERENCES devoir (id) ON DELETE CASCADE, + CONSTRAINT fk_rd_utilisateur_id FOREIGN KEY (utilisateur_id) REFERENCES utilisateur (id) ON DELETE CASCADE +); +CREATE INDEX ix_rd_devoir_id ON rendu_devoir (devoir_id); +CREATE INDEX ix_rd_utilisateur_id ON rendu_devoir (utilisateur_id); + +-- Table note : représente une note attribuée à un rendu de devoir +CREATE TABLE note +( + id BIGSERIAL NOT NULL, + rendu_devoir_id BIGINT NOT NULL, + valeur DECIMAL(5, 2) NOT NULL CHECK (valeur >= 0 AND valeur <= 20), + date_attribution TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + PRIMARY KEY (id), + CONSTRAINT fk_n_rendu_devoir_id FOREIGN KEY (rendu_devoir_id) REFERENCES rendu_devoir (id) ON DELETE CASCADE +); +CREATE INDEX ix_n_rendu_devoir_id ON note (rendu_devoir_id);