|
|
/**
|
|
|
* 仅初始化登录账号。不再写入 M1–M5 / 样例邮件。
|
|
|
* Usage: pnpm db:seed
|
|
|
*/
|
|
|
import { createHash } from "crypto";
|
|
|
import { PrismaClient } from "@prisma/client";
|
|
|
|
|
|
const prisma = new PrismaClient();
|
|
|
|
|
|
function hashPassword(plain: string): string {
|
|
|
return createHash("sha256").update(plain).digest("hex");
|
|
|
}
|
|
|
|
|
|
async function main() {
|
|
|
const adminUser = process.env.APP_ADMIN_USER || "admin";
|
|
|
const adminPass = process.env.APP_ADMIN_PASS || "admin123";
|
|
|
const opsUser = process.env.APP_OPS_USER || "ops";
|
|
|
const opsPass = process.env.APP_OPS_PASS || "ops123";
|
|
|
|
|
|
await prisma.appUser.upsert({
|
|
|
where: { username: adminUser },
|
|
|
create: {
|
|
|
username: adminUser,
|
|
|
passwordHash: hashPassword(adminPass),
|
|
|
role: "admin",
|
|
|
},
|
|
|
update: { passwordHash: hashPassword(adminPass), role: "admin" },
|
|
|
});
|
|
|
await prisma.appUser.upsert({
|
|
|
where: { username: opsUser },
|
|
|
create: {
|
|
|
username: opsUser,
|
|
|
passwordHash: hashPassword(opsPass),
|
|
|
role: "ops",
|
|
|
},
|
|
|
update: { passwordHash: hashPassword(opsPass), role: "ops" },
|
|
|
});
|
|
|
|
|
|
const caps = [
|
|
|
{ id: "save_container", mode: "live", endpoint: "/Container/SaveContainer" },
|
|
|
{ id: "transfer", mode: "mock", endpoint: "/Container/TransferWarehouse" },
|
|
|
{ id: "hold_split", mode: "mock", endpoint: "/Container/HoldSplitInstruction" },
|
|
|
{ id: "label", mode: "mock", endpoint: "/Container/ApplyLabelInstruction" },
|
|
|
];
|
|
|
for (const c of caps) {
|
|
|
await prisma.ccWriteCapability.upsert({
|
|
|
where: { id: c.id },
|
|
|
create: c,
|
|
|
update: {},
|
|
|
});
|
|
|
}
|
|
|
|
|
|
console.log(`Seed users only: ${adminUser} (admin), ${opsUser} (ops); cc_write_capability seeded`);
|
|
|
}
|
|
|
|
|
|
main()
|
|
|
.catch((e) => {
|
|
|
console.error(e);
|
|
|
process.exit(1);
|
|
|
})
|
|
|
.finally(() => prisma.$disconnect());
|