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

View File

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