From 2d5b886b7dcce69b738af06829f2474425d3b299 Mon Sep 17 00:00:00 2001 From: 951095 Date: Wed, 20 Aug 2025 13:57:53 +0200 Subject: [PATCH] =?UTF-8?q?ajout=20d'un=20super=20admin=20par=20d=C3=A9fau?= =?UTF-8?q?t?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker-compose.yml | 1 - migrations/01_init.sql | 48 ++++++++++++++++++++++++++++++++++++++++++ migrations/02_seed.sql | 0 3 files changed, 48 insertions(+), 1 deletion(-) delete mode 100644 migrations/02_seed.sql diff --git a/docker-compose.yml b/docker-compose.yml index 2220e70..1ac5688 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -13,7 +13,6 @@ services: - "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: diff --git a/migrations/01_init.sql b/migrations/01_init.sql index c2a49d3..20cb26e 100644 --- a/migrations/01_init.sql +++ b/migrations/01_init.sql @@ -217,3 +217,51 @@ CREATE TABLE validations ( cree_le TIMESTAMP DEFAULT now(), modifie_le TIMESTAMP 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, + mot_de_passe_hash, + prenom, + nom, + role, + statut, + cree_le, + modifie_le +) +VALUES ( + gen_random_uuid(), + 'admin@ptitspas.com', + 'motdepasse_hashé', -- à remplacer par le hash réel du mot de passe + 'Admin', + 'PtitsPas', + 'super_admin', + 'actif', + now(), + 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; diff --git a/migrations/02_seed.sql b/migrations/02_seed.sql deleted file mode 100644 index e69de29..0000000