Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 29 additions & 4 deletions services/driver-ms/init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,37 @@ for each row execute function set_updated_at();
-- =========================
-- Datos iniciales para testing

-- Insertar conductores (user_id debe coincidir con users-srv)
-- NOTA IMPORTANTE: Los user_id deben corresponder ÚNICAMENTE a usuarios con rol DRIVER en users-srv.
-- Según users-srv/db/init.sql, los drivers son:
-- - dylan_driver (username = 'dylan_driver')
-- - john_driver (username = 'john_driver')
-- - mary_driver (username = 'mary_driver')
--
-- Para verificar los user_id correctos, ejecutar en la BD de users-srv:
-- SELECT u.user_id, u.username, u.first_name, r.name as role
-- FROM users u
-- JOIN user_roles ur ON u.user_id = ur.user_id
-- JOIN roles r ON ur.role_id = r.role_id
-- WHERE r.name = 'DRIVER'
-- ORDER BY u.user_id;
--
-- Basado en el orden de inserción en users-srv:
-- 1. Alice (Admin)
-- 2. Sam (Supervisor)
-- 3. Dylan (Driver) ← user_id = 3
-- 4. Bruce (Admin)
-- 5. Carol (Admin)
-- 6. Mark (Supervisor)
-- 7. Lisa (Supervisor)
-- 8. John (Driver) ← user_id = 8
-- 9. Mary (Driver) ← user_id = 9

-- Insertar conductores usando los user_id correctos de los DRIVERS
insert into drivers(user_id, availability)
values
(3, 'AVAILABLE'),
(8, 'AVAILABLE'),
(9, 'AVAILABLE')
(3, 'AVAILABLE'), -- dylan_driver
(8, 'AVAILABLE'), -- john_driver
(9, 'AVAILABLE') -- mary_driver
on conflict (user_id) do nothing;

-- Insertar tipos de licencia comunes
Expand Down
82 changes: 47 additions & 35 deletions services/users-srv/prisma/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,28 @@ async function main() {
console.log('✅ Roles created');

// 2. Crear Usuarios con contraseñas hasheadas
// 2. Crear Usuarios en el MISMO ORDEN que init.sql para mantener consistencia de IDs
// ORDEN EXACTO del init.sql:
// 1. Alice (Admin)
// 2. Sam (Supervisor)
// 3. Dylan (Driver)
// 4. Bruce (Admin)
// 5. Carol (Admin)
// 6. Mark (Supervisor)
// 7. Lisa (Supervisor)
// 8. John (Driver)
// 9. Mary (Driver)

const [
aliceAdmin,
bruceAdmin,
carolAdmin,
samSupervisor,
markSupervisor,
lisaSupervisor,
dylanDriver,
johnDriver,
maryDriver,
aliceAdmin, // ID 1
samSupervisor, // ID 2
dylanDriver, // ID 3
bruceAdmin, // ID 4
carolAdmin, // ID 5
markSupervisor, // ID 6
lisaSupervisor, // ID 7
johnDriver, // ID 8
maryDriver, // ID 9
] = await Promise.all([
prisma.user.upsert({
where: { username: 'alice_admin' },
Expand All @@ -61,6 +73,32 @@ async function main() {
status: 'ACTIVE',
},
}),
prisma.user.upsert({
where: { username: 'sam_supervisor' },
update: {},
create: {
firstName: 'Sam',
lastName: 'Supervisor',
email: 'samsupervisor@gmail.com',
phone: '+51 444 555 666',
username: 'sam_supervisor',
passwordHash: await bcrypt.hash('supervisor123', 10),
status: 'ACTIVE',
},
}),
prisma.user.upsert({
where: { username: 'dylan_driver' },
update: {},
create: {
firstName: 'Dylan',
lastName: 'Driver',
email: 'dylandriver@gmail.com',
phone: '+51 777 888 999',
username: 'dylan_driver',
passwordHash: await bcrypt.hash('driver123', 10),
status: 'ACTIVE',
},
}),
prisma.user.upsert({
where: { username: 'bruce_admin' },
update: {},
Expand All @@ -87,19 +125,6 @@ async function main() {
status: 'ACTIVE',
},
}),
prisma.user.upsert({
where: { username: 'sam_supervisor' },
update: {},
create: {
firstName: 'Sam',
lastName: 'Supervisor',
email: 'sam.supervisor@example.com',
phone: '+51 444 555 666',
username: 'sam_supervisor',
passwordHash: await bcrypt.hash('supervisor123', 10),
status: 'ACTIVE',
},
}),
prisma.user.upsert({
where: { username: 'mark_supervisor' },
update: {},
Expand All @@ -126,19 +151,6 @@ async function main() {
status: 'ACTIVE',
},
}),
prisma.user.upsert({
where: { username: 'dylan_driver' },
update: {},
create: {
firstName: 'Dylan',
lastName: 'Driver',
email: 'dylan.driver@example.com',
phone: '+51 777 888 999',
username: 'dylan_driver',
passwordHash: await bcrypt.hash('driver123', 10),
status: 'ACTIVE',
},
}),
prisma.user.upsert({
where: { username: 'john_driver' },
update: {},
Expand Down