MAI CALL - step 2

This commit is contained in:
Pedro Gomes 2026-05-16 15:23:19 +01:00
parent 055d6e2a24
commit e249a6f0b2
2 changed files with 20 additions and 6 deletions

View File

@ -18,7 +18,8 @@
"PowerShell(corepack pnpm exec prisma migrate status --schema packages/db/prisma/schema.prisma 2>&1)",
"PowerShell($env:npm_config_verify_deps_before_run = \"false\"; corepack pnpm exec prisma migrate status --schema packages/db/prisma/schema.prisma 2>&1 | Select-Object -Last 25)",
"Bash(pnpm --filter @repo/db exec prisma migrate dev --name add_maintenance_request)",
"Bash(pnpm --filter @repo/db exec prisma db execute --schema=prisma/schema.prisma --stdin)"
"Bash(pnpm --filter @repo/db exec prisma db execute --schema=prisma/schema.prisma --stdin)",
"Bash(docker exec *)"
]
}
}

View File

@ -13,6 +13,14 @@ const prisma = new PrismaClient();
const DEMO_TENANT_NAME = 'Demo Factory';
const DEMO_ADMIN_EMAIL = 'admin@demo.local';
const OPERATOR_EMAILS = ['op1@demo.local', 'op2@demo.local', 'op3@demo.local'];
const WORKSTATIONS = [
{ code: 'CTR04', name: 'Controlo 04', area: 'Montagem' },
{ code: 'QVN_RTL_2', name: 'Retificação Visual 2', area: 'Qualidade' },
{ code: 'MTG_01', name: 'Montagem 01', area: 'Montagem' },
];
async function main() {
// Idempotent: if a prior run created the demo tenant, wipe it and recreate.
// Cascade deletes on the relations handle the children.
@ -33,15 +41,20 @@ async function main() {
},
});
await prisma.user.createMany({
data: OPERATOR_EMAILS.map((email) => ({
tenantId: tenant.id,
email,
role: UserRole.OPERATOR,
})),
});
await prisma.workstation.createMany({
data: [
{ tenantId: tenant.id, code: 'WS-001', name: 'Assembly A', area: 'Floor 1' },
{ tenantId: tenant.id, code: 'WS-002', name: 'Packaging B', area: 'Floor 2' },
],
data: WORKSTATIONS.map((ws) => ({ tenantId: tenant.id, ...ws })),
});
console.warn(
`Seed complete — tenant=${tenant.id} (${tenant.name}), admin=${DEMO_ADMIN_EMAIL}, workstations=2`,
`Seed complete — tenant=${tenant.id} (${tenant.name}), admin=${DEMO_ADMIN_EMAIL}, operators=${OPERATOR_EMAILS.length}, workstations=${WORKSTATIONS.length}`,
);
}