🚑 hotfix: move id assign only in create

This commit is contained in:
Rafi Arrafif
2026-01-29 02:47:43 +07:00
parent 5bfb376e88
commit 467faedf28
2 changed files with 13 additions and 11 deletions

View File

@ -6,7 +6,6 @@ export const userRoleSeed = async () => {
console.log("🔃 Seeding user roles...", SystemAccountId); console.log("🔃 Seeding user roles...", SystemAccountId);
const roles = [ const roles = [
{ {
id: generateUUIDv7(),
name: "ADMIN", name: "ADMIN",
description: "Administrator with full access", description: "Administrator with full access",
isSuperadmin: true, isSuperadmin: true,
@ -23,7 +22,6 @@ export const userRoleSeed = async () => {
createdBy: SystemAccountId, createdBy: SystemAccountId,
}, },
{ {
id: generateUUIDv7(),
name: "USER", name: "USER",
description: "Regular user with limited access", description: "Regular user with limited access",
isSuperadmin: false, isSuperadmin: false,
@ -48,7 +46,10 @@ export const userRoleSeed = async () => {
await tx.userRole.upsert({ await tx.userRole.upsert({
where: { name: role.name }, where: { name: role.name },
update: role, update: role,
create: role, create: {
id: generateUUIDv7(),
...role,
},
}), }),
), ),
); );

View File

@ -1,22 +1,23 @@
import { generateUUIDv7 } from "../../src/helpers/databases/uuidv7"; import { generateUUIDv7 } from "../../src/helpers/databases/uuidv7";
import { createFile } from "../../src/helpers/files/createFile"; import { createFile } from "../../src/helpers/files/createFile";
import { hashPassword } from "../../src/helpers/security/password/hash";
import { prisma } from "../../src/utils/databases/prisma/connection"; import { prisma } from "../../src/utils/databases/prisma/connection";
export const userSystemSeed = async () => { export const userSystemSeed = async () => {
const payload = { const payload = {
id: generateUUIDv7(),
name: "SYSTEM", name: "SYSTEM",
username: process.env.DEFAULT_ADMIN_USERNAME || "system", username: process.env.DEFAULT_ADMIN_USERNAME!,
email: process.env.DEFAULT_ADMIN_EMAIL || "system@example.com", email: process.env.DEFAULT_ADMIN_EMAIL!,
password: password: await hashPassword(process.env.DEFAULT_ADMIN_PASSWORD!),
process.env.DEFAULT_ADMIN_PASSWORD ||
"$2a$12$ynOrzVCvRdejGp/7KJW4lOAwRzFYhSHDE.Dp3Fqh3sXAq1BIwfwc6",
}; };
const insertedUserSystem = await prisma.user.upsert({ const insertedUserSystem = await prisma.user.upsert({
where: { username: payload.username }, where: { username: payload.username },
update: {}, update: payload,
create: payload, create: {
id: generateUUIDv7(),
...payload,
},
select: { id: true }, select: { id: true },
}); });
await createFile( await createFile(