modification de la base de donnée
This commit is contained in:
parent
2d5b886b7d
commit
2662375771
179
BDD.sql
179
BDD.sql
@ -1,30 +1,62 @@
|
||||
-- ==========================================================
|
||||
-- Script de création BDD PostgreSQL - Sprint 1
|
||||
-- ==========================================================
|
||||
|
||||
-- Extension UUID (si non déjà activée)
|
||||
CREATE EXTENSION IF NOT EXISTS "pgcrypto";
|
||||
|
||||
-- ==========================================================
|
||||
-- ENUMS
|
||||
-- ==========================================================
|
||||
DO $$ BEGIN
|
||||
IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'role_type') THEN
|
||||
CREATE TYPE role_type AS ENUM ('parent', 'gestionnaire', 'super_admin', 'assistante_maternelle');
|
||||
END IF;
|
||||
IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'genre_type') THEN
|
||||
CREATE TYPE genre_type AS ENUM ('H', 'F', 'Autre');
|
||||
END IF;
|
||||
IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'statut_utilisateur_type') THEN
|
||||
CREATE TYPE statut_utilisateur_type AS ENUM ('en_attente','actif','suspendu');
|
||||
END IF;
|
||||
IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'statut_enfant_type') THEN
|
||||
CREATE TYPE statut_enfant_type AS ENUM ('a_naitre','actif','scolarise');
|
||||
END IF;
|
||||
IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'statut_dossier_type') THEN
|
||||
CREATE TYPE statut_dossier_type AS ENUM ('envoye','accepte','refuse');
|
||||
END IF;
|
||||
IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'statut_contrat_type') THEN
|
||||
CREATE TYPE statut_contrat_type AS ENUM ('brouillon','en_attente_signature','valide','resilie');
|
||||
END IF;
|
||||
IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'statut_avenant_type') THEN
|
||||
CREATE TYPE statut_avenant_type AS ENUM ('propose','accepte','refuse');
|
||||
END IF;
|
||||
IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'type_evenement_type') THEN
|
||||
CREATE TYPE type_evenement_type AS ENUM ('absence_enfant','conge_am','conge_parent','arret_maladie_am','evenement_rpe');
|
||||
END IF;
|
||||
IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'statut_evenement_type') THEN
|
||||
CREATE TYPE statut_evenement_type AS ENUM ('propose','valide','refuse');
|
||||
END IF;
|
||||
IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'statut_validation_type') THEN
|
||||
CREATE TYPE statut_validation_type AS ENUM ('en_attente','valide','refuse');
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
-- ==========================================================
|
||||
-- Table : utilisateurs
|
||||
-- ==========================================================
|
||||
CREATE TABLE utilisateurs (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
courriel VARCHAR NOT NULL UNIQUE,
|
||||
courriel VARCHAR(255) NOT NULL UNIQUE,
|
||||
CHECK (courriel ~* '^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$'),
|
||||
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,
|
||||
prenom VARCHAR(100),
|
||||
nom VARCHAR(100),
|
||||
genre genre_type,
|
||||
role role_type NOT NULL,
|
||||
statut statut_utilisateur_type DEFAULT 'en_attente',
|
||||
telephone VARCHAR(20),
|
||||
adresse TEXT,
|
||||
photo_url TEXT,
|
||||
consentement_photo BOOLEAN,
|
||||
date_consentement_photo TIMESTAMP,
|
||||
consentement_photo BOOLEAN DEFAULT false,
|
||||
date_consentement_photo TIMESTAMPTZ,
|
||||
changement_mdp_obligatoire BOOLEAN DEFAULT false,
|
||||
cree_le TIMESTAMP DEFAULT now(),
|
||||
modifie_le TIMESTAMP DEFAULT now()
|
||||
cree_le TIMESTAMPTZ DEFAULT now(),
|
||||
modifie_le TIMESTAMPTZ DEFAULT now()
|
||||
);
|
||||
|
||||
-- ==========================================================
|
||||
@ -32,15 +64,15 @@ CREATE TABLE utilisateurs (
|
||||
-- ==========================================================
|
||||
CREATE TABLE assistantes_maternelles (
|
||||
id_utilisateur UUID PRIMARY KEY REFERENCES utilisateurs(id) ON DELETE CASCADE,
|
||||
numero_agrement VARCHAR,
|
||||
numero_agrement VARCHAR(50),
|
||||
date_naissance DATE,
|
||||
ville_naissance VARCHAR,
|
||||
pays_naissance VARCHAR,
|
||||
nir_chiffre TEXT,
|
||||
ville_naissance VARCHAR(100),
|
||||
pays_naissance CHAR(2),
|
||||
nir_chiffre CHAR(15),
|
||||
nb_max_enfants INT,
|
||||
biographie TEXT,
|
||||
disponible BOOLEAN,
|
||||
ville_residence VARCHAR
|
||||
disponible BOOLEAN DEFAULT true,
|
||||
ville_residence VARCHAR(100)
|
||||
);
|
||||
|
||||
-- ==========================================================
|
||||
@ -56,16 +88,16 @@ CREATE TABLE parents (
|
||||
-- ==========================================================
|
||||
CREATE TABLE enfants (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
statut VARCHAR, -- a_naitre, actif, scolarise
|
||||
prenom VARCHAR,
|
||||
nom VARCHAR,
|
||||
genre VARCHAR,
|
||||
statut statut_enfant_type,
|
||||
prenom VARCHAR(100),
|
||||
nom VARCHAR(100),
|
||||
genre genre_type,
|
||||
date_naissance DATE,
|
||||
date_prevue_naissance DATE,
|
||||
photo_url TEXT,
|
||||
consentement_photo BOOLEAN,
|
||||
date_consentement_photo TIMESTAMP,
|
||||
est_multiple BOOLEAN
|
||||
consentement_photo BOOLEAN DEFAULT false,
|
||||
date_consentement_photo TIMESTAMPTZ,
|
||||
est_multiple BOOLEAN DEFAULT false
|
||||
);
|
||||
|
||||
-- ==========================================================
|
||||
@ -85,13 +117,13 @@ CREATE TABLE dossiers (
|
||||
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,
|
||||
type_contrat VARCHAR(50),
|
||||
repas BOOLEAN DEFAULT false,
|
||||
budget NUMERIC(10,2),
|
||||
planning_souhaite JSONB,
|
||||
statut VARCHAR DEFAULT 'envoye',
|
||||
cree_le TIMESTAMP DEFAULT now(),
|
||||
modifie_le TIMESTAMP DEFAULT now()
|
||||
statut statut_dossier_type DEFAULT 'envoye',
|
||||
cree_le TIMESTAMPTZ DEFAULT now(),
|
||||
modifie_le TIMESTAMPTZ DEFAULT now()
|
||||
);
|
||||
|
||||
-- ==========================================================
|
||||
@ -102,8 +134,8 @@ CREATE TABLE messages (
|
||||
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()
|
||||
re_redige_par_ia BOOLEAN DEFAULT false,
|
||||
cree_le TIMESTAMPTZ DEFAULT now()
|
||||
);
|
||||
|
||||
-- ==========================================================
|
||||
@ -113,15 +145,15 @@ 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,
|
||||
tarif_horaire NUMERIC(6,2),
|
||||
indemnites_repas NUMERIC(6,2),
|
||||
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()
|
||||
statut statut_contrat_type DEFAULT 'brouillon',
|
||||
signe_parent BOOLEAN DEFAULT false,
|
||||
signe_am BOOLEAN DEFAULT false,
|
||||
finalise_le TIMESTAMPTZ,
|
||||
cree_le TIMESTAMPTZ DEFAULT now(),
|
||||
modifie_le TIMESTAMPTZ DEFAULT now()
|
||||
);
|
||||
|
||||
-- ==========================================================
|
||||
@ -132,9 +164,9 @@ CREATE TABLE avenants_contrats (
|
||||
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()
|
||||
statut statut_avenant_type DEFAULT 'propose',
|
||||
cree_le TIMESTAMPTZ DEFAULT now(),
|
||||
modifie_le TIMESTAMPTZ DEFAULT now()
|
||||
);
|
||||
|
||||
-- ==========================================================
|
||||
@ -142,19 +174,19 @@ CREATE TABLE avenants_contrats (
|
||||
-- ==========================================================
|
||||
CREATE TABLE evenements (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
type VARCHAR, -- absence_enfant, conge_am, conge_parent, arret_maladie_am, evenement_rpe
|
||||
type type_evenement_type,
|
||||
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,
|
||||
date_debut TIMESTAMPTZ,
|
||||
date_fin TIMESTAMPTZ,
|
||||
commentaires TEXT,
|
||||
statut VARCHAR DEFAULT 'propose',
|
||||
delai_grace DATE,
|
||||
urgent BOOLEAN,
|
||||
cree_le TIMESTAMP DEFAULT now(),
|
||||
modifie_le TIMESTAMP DEFAULT now()
|
||||
statut statut_evenement_type DEFAULT 'propose',
|
||||
delai_grace TIMESTAMPTZ,
|
||||
urgent BOOLEAN DEFAULT false,
|
||||
cree_le TIMESTAMPTZ DEFAULT now(),
|
||||
modifie_le TIMESTAMPTZ DEFAULT now()
|
||||
);
|
||||
|
||||
-- ==========================================================
|
||||
@ -164,24 +196,7 @@ 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)
|
||||
cree_le TIMESTAMPTZ DEFAULT now()
|
||||
);
|
||||
|
||||
-- ==========================================================
|
||||
@ -191,8 +206,8 @@ 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()
|
||||
type VARCHAR(50),
|
||||
cree_le TIMESTAMPTZ DEFAULT now()
|
||||
);
|
||||
|
||||
-- ==========================================================
|
||||
@ -203,7 +218,7 @@ CREATE TABLE notifications (
|
||||
id_utilisateur UUID REFERENCES utilisateurs(id) ON DELETE CASCADE,
|
||||
contenu TEXT,
|
||||
lu BOOLEAN DEFAULT false,
|
||||
cree_le TIMESTAMP DEFAULT now()
|
||||
cree_le TIMESTAMPTZ DEFAULT now()
|
||||
);
|
||||
|
||||
-- ==========================================================
|
||||
@ -212,8 +227,8 @@ CREATE TABLE notifications (
|
||||
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()
|
||||
type VARCHAR(50),
|
||||
statut statut_validation_type DEFAULT 'en_attente',
|
||||
cree_le TIMESTAMPTZ DEFAULT now(),
|
||||
modifie_le TIMESTAMPTZ DEFAULT now()
|
||||
);
|
||||
|
||||
@ -1,30 +1,62 @@
|
||||
-- ==========================================================
|
||||
-- Script de création BDD PostgreSQL - Sprint 1
|
||||
-- ==========================================================
|
||||
|
||||
-- Extension UUID (si non déjà activée)
|
||||
CREATE EXTENSION IF NOT EXISTS "pgcrypto";
|
||||
|
||||
-- ==========================================================
|
||||
-- ENUMS
|
||||
-- ==========================================================
|
||||
DO $$ BEGIN
|
||||
IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'role_type') THEN
|
||||
CREATE TYPE role_type AS ENUM ('parent', 'gestionnaire', 'super_admin', 'assistante_maternelle');
|
||||
END IF;
|
||||
IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'genre_type') THEN
|
||||
CREATE TYPE genre_type AS ENUM ('H', 'F', 'Autre');
|
||||
END IF;
|
||||
IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'statut_utilisateur_type') THEN
|
||||
CREATE TYPE statut_utilisateur_type AS ENUM ('en_attente','actif','suspendu');
|
||||
END IF;
|
||||
IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'statut_enfant_type') THEN
|
||||
CREATE TYPE statut_enfant_type AS ENUM ('a_naitre','actif','scolarise');
|
||||
END IF;
|
||||
IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'statut_dossier_type') THEN
|
||||
CREATE TYPE statut_dossier_type AS ENUM ('envoye','accepte','refuse');
|
||||
END IF;
|
||||
IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'statut_contrat_type') THEN
|
||||
CREATE TYPE statut_contrat_type AS ENUM ('brouillon','en_attente_signature','valide','resilie');
|
||||
END IF;
|
||||
IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'statut_avenant_type') THEN
|
||||
CREATE TYPE statut_avenant_type AS ENUM ('propose','accepte','refuse');
|
||||
END IF;
|
||||
IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'type_evenement_type') THEN
|
||||
CREATE TYPE type_evenement_type AS ENUM ('absence_enfant','conge_am','conge_parent','arret_maladie_am','evenement_rpe');
|
||||
END IF;
|
||||
IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'statut_evenement_type') THEN
|
||||
CREATE TYPE statut_evenement_type AS ENUM ('propose','valide','refuse');
|
||||
END IF;
|
||||
IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'statut_validation_type') THEN
|
||||
CREATE TYPE statut_validation_type AS ENUM ('en_attente','valide','refuse');
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
-- ==========================================================
|
||||
-- Table : utilisateurs
|
||||
-- ==========================================================
|
||||
CREATE TABLE utilisateurs (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
courriel VARCHAR NOT NULL UNIQUE,
|
||||
courriel VARCHAR(255) NOT NULL UNIQUE,
|
||||
CHECK (courriel ~* '^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$'),
|
||||
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,
|
||||
prenom VARCHAR(100),
|
||||
nom VARCHAR(100),
|
||||
genre genre_type,
|
||||
role role_type NOT NULL,
|
||||
statut statut_utilisateur_type DEFAULT 'en_attente',
|
||||
telephone VARCHAR(20),
|
||||
adresse TEXT,
|
||||
photo_url TEXT,
|
||||
consentement_photo BOOLEAN,
|
||||
date_consentement_photo TIMESTAMP,
|
||||
consentement_photo BOOLEAN DEFAULT false,
|
||||
date_consentement_photo TIMESTAMPTZ,
|
||||
changement_mdp_obligatoire BOOLEAN DEFAULT false,
|
||||
cree_le TIMESTAMP DEFAULT now(),
|
||||
modifie_le TIMESTAMP DEFAULT now()
|
||||
cree_le TIMESTAMPTZ DEFAULT now(),
|
||||
modifie_le TIMESTAMPTZ DEFAULT now()
|
||||
);
|
||||
|
||||
-- ==========================================================
|
||||
@ -32,15 +64,15 @@ CREATE TABLE utilisateurs (
|
||||
-- ==========================================================
|
||||
CREATE TABLE assistantes_maternelles (
|
||||
id_utilisateur UUID PRIMARY KEY REFERENCES utilisateurs(id) ON DELETE CASCADE,
|
||||
numero_agrement VARCHAR,
|
||||
numero_agrement VARCHAR(50),
|
||||
date_naissance DATE,
|
||||
ville_naissance VARCHAR,
|
||||
pays_naissance VARCHAR,
|
||||
nir_chiffre TEXT,
|
||||
ville_naissance VARCHAR(100),
|
||||
pays_naissance CHAR(2),
|
||||
nir_chiffre CHAR(15),
|
||||
nb_max_enfants INT,
|
||||
biographie TEXT,
|
||||
disponible BOOLEAN,
|
||||
ville_residence VARCHAR
|
||||
disponible BOOLEAN DEFAULT true,
|
||||
ville_residence VARCHAR(100)
|
||||
);
|
||||
|
||||
-- ==========================================================
|
||||
@ -56,16 +88,16 @@ CREATE TABLE parents (
|
||||
-- ==========================================================
|
||||
CREATE TABLE enfants (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
statut VARCHAR, -- a_naitre, actif, scolarise
|
||||
prenom VARCHAR,
|
||||
nom VARCHAR,
|
||||
genre VARCHAR,
|
||||
statut statut_enfant_type,
|
||||
prenom VARCHAR(100),
|
||||
nom VARCHAR(100),
|
||||
genre genre_type,
|
||||
date_naissance DATE,
|
||||
date_prevue_naissance DATE,
|
||||
photo_url TEXT,
|
||||
consentement_photo BOOLEAN,
|
||||
date_consentement_photo TIMESTAMP,
|
||||
est_multiple BOOLEAN
|
||||
consentement_photo BOOLEAN DEFAULT false,
|
||||
date_consentement_photo TIMESTAMPTZ,
|
||||
est_multiple BOOLEAN DEFAULT false
|
||||
);
|
||||
|
||||
-- ==========================================================
|
||||
@ -85,13 +117,13 @@ CREATE TABLE dossiers (
|
||||
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,
|
||||
type_contrat VARCHAR(50),
|
||||
repas BOOLEAN DEFAULT false,
|
||||
budget NUMERIC(10,2),
|
||||
planning_souhaite JSONB,
|
||||
statut VARCHAR DEFAULT 'envoye',
|
||||
cree_le TIMESTAMP DEFAULT now(),
|
||||
modifie_le TIMESTAMP DEFAULT now()
|
||||
statut statut_dossier_type DEFAULT 'envoye',
|
||||
cree_le TIMESTAMPTZ DEFAULT now(),
|
||||
modifie_le TIMESTAMPTZ DEFAULT now()
|
||||
);
|
||||
|
||||
-- ==========================================================
|
||||
@ -102,8 +134,8 @@ CREATE TABLE messages (
|
||||
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()
|
||||
re_redige_par_ia BOOLEAN DEFAULT false,
|
||||
cree_le TIMESTAMPTZ DEFAULT now()
|
||||
);
|
||||
|
||||
-- ==========================================================
|
||||
@ -113,15 +145,15 @@ 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,
|
||||
tarif_horaire NUMERIC(6,2),
|
||||
indemnites_repas NUMERIC(6,2),
|
||||
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()
|
||||
statut statut_contrat_type DEFAULT 'brouillon',
|
||||
signe_parent BOOLEAN DEFAULT false,
|
||||
signe_am BOOLEAN DEFAULT false,
|
||||
finalise_le TIMESTAMPTZ,
|
||||
cree_le TIMESTAMPTZ DEFAULT now(),
|
||||
modifie_le TIMESTAMPTZ DEFAULT now()
|
||||
);
|
||||
|
||||
-- ==========================================================
|
||||
@ -132,9 +164,9 @@ CREATE TABLE avenants_contrats (
|
||||
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()
|
||||
statut statut_avenant_type DEFAULT 'propose',
|
||||
cree_le TIMESTAMPTZ DEFAULT now(),
|
||||
modifie_le TIMESTAMPTZ DEFAULT now()
|
||||
);
|
||||
|
||||
-- ==========================================================
|
||||
@ -142,19 +174,19 @@ CREATE TABLE avenants_contrats (
|
||||
-- ==========================================================
|
||||
CREATE TABLE evenements (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
type VARCHAR, -- absence_enfant, conge_am, conge_parent, arret_maladie_am, evenement_rpe
|
||||
type type_evenement_type,
|
||||
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,
|
||||
date_debut TIMESTAMPTZ,
|
||||
date_fin TIMESTAMPTZ,
|
||||
commentaires TEXT,
|
||||
statut VARCHAR DEFAULT 'propose',
|
||||
delai_grace DATE,
|
||||
urgent BOOLEAN,
|
||||
cree_le TIMESTAMP DEFAULT now(),
|
||||
modifie_le TIMESTAMP DEFAULT now()
|
||||
statut statut_evenement_type DEFAULT 'propose',
|
||||
delai_grace TIMESTAMPTZ,
|
||||
urgent BOOLEAN DEFAULT false,
|
||||
cree_le TIMESTAMPTZ DEFAULT now(),
|
||||
modifie_le TIMESTAMPTZ DEFAULT now()
|
||||
);
|
||||
|
||||
-- ==========================================================
|
||||
@ -164,24 +196,7 @@ 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)
|
||||
cree_le TIMESTAMPTZ DEFAULT now()
|
||||
);
|
||||
|
||||
-- ==========================================================
|
||||
@ -191,8 +206,8 @@ 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()
|
||||
type VARCHAR(50),
|
||||
cree_le TIMESTAMPTZ DEFAULT now()
|
||||
);
|
||||
|
||||
-- ==========================================================
|
||||
@ -203,7 +218,7 @@ CREATE TABLE notifications (
|
||||
id_utilisateur UUID REFERENCES utilisateurs(id) ON DELETE CASCADE,
|
||||
contenu TEXT,
|
||||
lu BOOLEAN DEFAULT false,
|
||||
cree_le TIMESTAMP DEFAULT now()
|
||||
cree_le TIMESTAMPTZ DEFAULT now()
|
||||
);
|
||||
|
||||
-- ==========================================================
|
||||
@ -212,24 +227,17 @@ CREATE TABLE notifications (
|
||||
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()
|
||||
type VARCHAR(50),
|
||||
statut statut_validation_type DEFAULT 'en_attente',
|
||||
cree_le TIMESTAMPTZ DEFAULT now(),
|
||||
modifie_le TIMESTAMPTZ DEFAULT now()
|
||||
);
|
||||
|
||||
|
||||
|
||||
-- ==========================================================
|
||||
-- Initialisation d'un administrateur par défaut
|
||||
-- ==========================================================
|
||||
|
||||
-- Insertion du rôle super_admin si non existant
|
||||
INSERT INTO roles (id, nom)
|
||||
VALUES (gen_random_uuid(), 'super_admin')
|
||||
ON CONFLICT (nom) DO NOTHING;
|
||||
|
||||
-- Insertion de l'administrateur par défaut
|
||||
INSERT INTO utilisateurs (
|
||||
id,
|
||||
courriel,
|
||||
@ -244,7 +252,7 @@ INSERT INTO utilisateurs (
|
||||
VALUES (
|
||||
gen_random_uuid(),
|
||||
'admin@ptitspas.com',
|
||||
'motdepasse_hashé', -- à remplacer par le hash réel du mot de passe
|
||||
'motdepasse_hashé', -- ⚠️ à remplacer par le hash réel du mot de passe
|
||||
'Admin',
|
||||
'PtitsPas',
|
||||
'super_admin',
|
||||
@ -253,15 +261,3 @@ VALUES (
|
||||
now()
|
||||
)
|
||||
ON CONFLICT (courriel) DO NOTHING;
|
||||
|
||||
-- Récupération des IDs pour créer la liaison
|
||||
WITH admin_user AS (
|
||||
SELECT id FROM utilisateurs WHERE courriel = 'admin@ptitspas.com'
|
||||
),
|
||||
admin_role AS (
|
||||
SELECT id FROM roles WHERE nom = 'super_admin'
|
||||
)
|
||||
INSERT INTO user_roles (id_utilisateur, id_role)
|
||||
SELECT admin_user.id, admin_role.id
|
||||
FROM admin_user, admin_role
|
||||
ON CONFLICT DO NOTHING;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user