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