diff --git a/README.md b/README.md index dc7d1c2..05b07d4 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,62 @@ -# ptitspas-ynov-bdd -uniquement la bdd \ No newline at end of file +# PtitsPas Ynov - Base de Données + +Ce projet contient uniquement la **base de données** pour l'application PtitsPas. + +--- + +## Prérequis + +- Docker installé et à jour +- Docker Compose installé + +--- + +## Lancer la base de données + +Dans le terminal, depuis le dossier du projet, exécute : + +```bash +docker-compose up -d +```` + +Et pour arreter le container + +```bash +docker-compose down +```` + + +--- + +## Accéder à pgAdmin4 + +Ouvre ton navigateur et va sur : + +``` +http://localhost:8080 +``` + +### Connexion à pgAdmin4 + +* **Email** : `admin@bdd.com` +* **Mot de passe** : `admin123` + +--- + +### Ajouter le serveur PostgreSQL + +1. Clique sur **Add New Server** (ou **Register Server**) +2. Onglet **General** : + + * **Name** : `Postgres Docker` +3. Onglet **Connection** : + + * **Host name/address** : `postgres_bdd` + * **Port** : `5432` (ou `5433` si mappé dans Docker Compose) + * **Username** : `admin` + * **Password** : `admin123` +4. Clique sur **Save** + +--- + diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..2220e70 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,32 @@ +version: "3.9" + +services: + db: + image: postgres:17 + container_name: postgres_bdd + restart: always + environment: + POSTGRES_USER: admin + POSTGRES_PASSWORD: admin123 + POSTGRES_DB: ptitpas_db + ports: + - "5433:5432" + volumes: + - ./migrations/01_init.sql:/docker-entrypoint-initdb.d/01_init.sql + - ./migrations/02_seed.sql:/docker-entrypoint-initdb.d/02_seed.sql + - postgres_data:/var/lib/postgresql/data + + pgadmin: + image: dpage/pgadmin4 + container_name: pgadmin4_bdd + restart: always + environment: + PGADMIN_DEFAULT_EMAIL: admin@bdd.com + PGADMIN_DEFAULT_PASSWORD: admin123 + ports: + - "8080:80" + depends_on: + - db + +volumes: + postgres_data: diff --git a/migrations/01_init.sql b/migrations/01_init.sql new file mode 100644 index 0000000..c2a49d3 --- /dev/null +++ b/migrations/01_init.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() +); diff --git a/migrations/02_seed.sql b/migrations/02_seed.sql new file mode 100644 index 0000000..e69de29