ajout d'un super admin par défaut
This commit is contained in:
parent
7e91af7724
commit
2d5b886b7d
@ -13,7 +13,6 @@ services:
|
|||||||
- "5433:5432"
|
- "5433:5432"
|
||||||
volumes:
|
volumes:
|
||||||
- ./migrations/01_init.sql:/docker-entrypoint-initdb.d/01_init.sql
|
- ./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
|
- postgres_data:/var/lib/postgresql/data
|
||||||
|
|
||||||
pgadmin:
|
pgadmin:
|
||||||
|
|||||||
@ -217,3 +217,51 @@ CREATE TABLE validations (
|
|||||||
cree_le TIMESTAMP DEFAULT now(),
|
cree_le TIMESTAMP DEFAULT now(),
|
||||||
modifie_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;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user