diff --git a/BDD.sql b/BDD.sql new file mode 100644 index 0000000..c2a49d3 --- /dev/null +++ b/BDD.sql @@ -0,0 +1,219 @@ +-- ========================================================== +-- Script de création BDD PostgreSQL - Sprint 1 +-- ========================================================== + +-- Extension UUID (si non déjà activée) +CREATE EXTENSION IF NOT EXISTS "pgcrypto"; + +-- ========================================================== +-- Table : utilisateurs +-- ========================================================== +CREATE TABLE utilisateurs ( + id UUID PRIMARY KEY DEFAULT gen_random_uuid(), + courriel VARCHAR NOT NULL UNIQUE, + mot_de_passe_hash TEXT NOT NULL, + prenom VARCHAR, + nom VARCHAR, + genre VARCHAR, + role VARCHAR, -- super_admin, gestionnaire, parent, assistante_maternelle + statut VARCHAR DEFAULT 'en_attente', + telephone VARCHAR, + adresse VARCHAR, + photo_url TEXT, + consentement_photo BOOLEAN, + date_consentement_photo TIMESTAMP, + changement_mdp_obligatoire BOOLEAN DEFAULT false, + cree_le TIMESTAMP DEFAULT now(), + modifie_le TIMESTAMP DEFAULT now() +); + +-- ========================================================== +-- Table : assistantes_maternelles +-- ========================================================== +CREATE TABLE assistantes_maternelles ( + id_utilisateur UUID PRIMARY KEY REFERENCES utilisateurs(id) ON DELETE CASCADE, + numero_agrement VARCHAR, + date_naissance DATE, + ville_naissance VARCHAR, + pays_naissance VARCHAR, + nir_chiffre TEXT, + nb_max_enfants INT, + biographie TEXT, + disponible BOOLEAN, + ville_residence VARCHAR +); + +-- ========================================================== +-- Table : parents +-- ========================================================== +CREATE TABLE parents ( + id_utilisateur UUID PRIMARY KEY REFERENCES utilisateurs(id) ON DELETE CASCADE, + id_co_parent UUID REFERENCES utilisateurs(id) +); + +-- ========================================================== +-- Table : enfants +-- ========================================================== +CREATE TABLE enfants ( + id UUID PRIMARY KEY DEFAULT gen_random_uuid(), + statut VARCHAR, -- a_naitre, actif, scolarise + prenom VARCHAR, + nom VARCHAR, + genre VARCHAR, + date_naissance DATE, + date_prevue_naissance DATE, + photo_url TEXT, + consentement_photo BOOLEAN, + date_consentement_photo TIMESTAMP, + est_multiple BOOLEAN +); + +-- ========================================================== +-- Table : enfants_parents +-- ========================================================== +CREATE TABLE enfants_parents ( + id_parent UUID REFERENCES parents(id_utilisateur) ON DELETE CASCADE, + id_enfant UUID REFERENCES enfants(id) ON DELETE CASCADE, + PRIMARY KEY (id_parent, id_enfant) +); + +-- ========================================================== +-- Table : dossiers +-- ========================================================== +CREATE TABLE dossiers ( + id UUID PRIMARY KEY DEFAULT gen_random_uuid(), + id_parent UUID REFERENCES parents(id_utilisateur) ON DELETE CASCADE, + id_enfant UUID REFERENCES enfants(id) ON DELETE CASCADE, + presentation TEXT, + type_contrat VARCHAR, + repas BOOLEAN, + budget DECIMAL, + planning_souhaite JSONB, + statut VARCHAR DEFAULT 'envoye', + cree_le TIMESTAMP DEFAULT now(), + modifie_le TIMESTAMP DEFAULT now() +); + +-- ========================================================== +-- Table : messages +-- ========================================================== +CREATE TABLE messages ( + id UUID PRIMARY KEY DEFAULT gen_random_uuid(), + id_dossier UUID REFERENCES dossiers(id) ON DELETE CASCADE, + id_expediteur UUID REFERENCES utilisateurs(id) ON DELETE CASCADE, + contenu TEXT, + re_redige_par_ia BOOLEAN, + cree_le TIMESTAMP DEFAULT now() +); + +-- ========================================================== +-- Table : contrats +-- ========================================================== +CREATE TABLE contrats ( + id UUID PRIMARY KEY DEFAULT gen_random_uuid(), + id_dossier UUID UNIQUE REFERENCES dossiers(id) ON DELETE CASCADE, + planning JSONB, + tarif_horaire DECIMAL, + indemnites_repas DECIMAL, + date_debut DATE, + statut VARCHAR DEFAULT 'brouillon', + signe_parent BOOLEAN, + signe_am BOOLEAN, + finalise_le TIMESTAMP, + cree_le TIMESTAMP DEFAULT now(), + modifie_le TIMESTAMP DEFAULT now() +); + +-- ========================================================== +-- Table : avenants_contrats +-- ========================================================== +CREATE TABLE avenants_contrats ( + id UUID PRIMARY KEY DEFAULT gen_random_uuid(), + id_contrat UUID REFERENCES contrats(id) ON DELETE CASCADE, + modifications JSONB, + initie_par UUID REFERENCES utilisateurs(id), + statut VARCHAR DEFAULT 'propose', + cree_le TIMESTAMP DEFAULT now(), + modifie_le TIMESTAMP DEFAULT now() +); + +-- ========================================================== +-- Table : evenements +-- ========================================================== +CREATE TABLE evenements ( + id UUID PRIMARY KEY DEFAULT gen_random_uuid(), + type VARCHAR, -- absence_enfant, conge_am, conge_parent, arret_maladie_am, evenement_rpe + id_enfant UUID REFERENCES enfants(id) ON DELETE CASCADE, + id_am UUID REFERENCES utilisateurs(id), + id_parent UUID REFERENCES parents(id_utilisateur), + cree_par UUID REFERENCES utilisateurs(id), + date_debut DATE, + date_fin DATE, + commentaires TEXT, + statut VARCHAR DEFAULT 'propose', + delai_grace DATE, + urgent BOOLEAN, + cree_le TIMESTAMP DEFAULT now(), + modifie_le TIMESTAMP DEFAULT now() +); + +-- ========================================================== +-- Table : signalements_bugs +-- ========================================================== +CREATE TABLE signalements_bugs ( + id UUID PRIMARY KEY DEFAULT gen_random_uuid(), + id_utilisateur UUID REFERENCES utilisateurs(id), + description TEXT, + cree_le TIMESTAMP DEFAULT now() +); + +-- ========================================================== +-- Table : roles +-- ========================================================== +CREATE TABLE roles ( + id UUID PRIMARY KEY DEFAULT gen_random_uuid(), + nom VARCHAR NOT NULL UNIQUE +); + +-- ========================================================== +-- Table : user_roles +-- ========================================================== +CREATE TABLE user_roles ( + id_utilisateur UUID REFERENCES utilisateurs(id) ON DELETE CASCADE, + id_role UUID REFERENCES roles(id) ON DELETE CASCADE, + PRIMARY KEY (id_utilisateur, id_role) +); + +-- ========================================================== +-- Table : uploads +-- ========================================================== +CREATE TABLE uploads ( + id UUID PRIMARY KEY DEFAULT gen_random_uuid(), + id_utilisateur UUID REFERENCES utilisateurs(id) ON DELETE SET NULL, + fichier_url TEXT NOT NULL, + type VARCHAR, + cree_le TIMESTAMP DEFAULT now() +); + +-- ========================================================== +-- Table : notifications +-- ========================================================== +CREATE TABLE notifications ( + id UUID PRIMARY KEY DEFAULT gen_random_uuid(), + id_utilisateur UUID REFERENCES utilisateurs(id) ON DELETE CASCADE, + contenu TEXT, + lu BOOLEAN DEFAULT false, + cree_le TIMESTAMP DEFAULT now() +); + +-- ========================================================== +-- Table : validations +-- ========================================================== +CREATE TABLE validations ( + id UUID PRIMARY KEY DEFAULT gen_random_uuid(), + id_utilisateur UUID REFERENCES utilisateurs(id), + type VARCHAR, + statut VARCHAR DEFAULT 'en_attente', + cree_le TIMESTAMP DEFAULT now(), + modifie_le TIMESTAMP DEFAULT now() +);