fix: remove all unessecary seeding

This commit is contained in:
2026-06-27 21:00:00 +07:00
parent 9de535f541
commit dcfa4350d6
4 changed files with 2 additions and 113 deletions

View File

@ -1,15 +1,11 @@
import { prisma } from "../../src/utils/databases/prisma/connection"; import { prisma } from "../../src/utils/databases/prisma/connection";
import { systemPreferenceSeed } from "./systemPreference.seed";
import { userRoleSeed } from "./userRole.seed";
import { userSystemSeed } from "./userSystem.seed"; import { userSystemSeed } from "./userSystem.seed";
async function main() { async function main() {
console.log("🌱 Running all seeds..."); console.log("🌱 Running all seeds...");
console.log("🔌 Connecting to database..."); console.log("🔌 Connecting to database...");
const userSystemSeedResult = await userSystemSeed(); await userSystemSeed();
await userRoleSeed(userSystemSeedResult.id);
await systemPreferenceSeed();
console.log("🌳 All seeds completed"); console.log("🌳 All seeds completed");
} }

View File

@ -1,35 +0,0 @@
import { Prisma } from "@prisma/client";
import { generateUUIDv7 } from "../../src/helpers/databases/uuidv7";
import { prisma } from "../../src/utils/databases/prisma/connection";
export const systemPreferenceSeed = async () => {
const preferences: Prisma.SystemPreferenceUpsertArgs["create"][] = [
{
id: generateUUIDv7(),
key: "REGISTRATION_ENABLED",
value: process.env.ENABLE_REGISTRATION === "true" ? "true" : "false",
description: "Enable or disable user registration",
},
{
id: generateUUIDv7(),
key: "HERO_BANNER_ENABLED",
value: process.env.ENABLE_HERO_BANNER === "true" ? "true" : "false",
description: "Enable or disable hero banner feature",
},
];
await prisma.$transaction(async (tx) => {
return await Promise.all(
preferences.map(
async (pref) =>
await tx.systemPreference.upsert({
where: {
key: pref.key,
},
update: pref,
create: pref,
}),
),
);
});
};

View File

@ -1,73 +0,0 @@
import { generateUUIDv7 } from "../../src/helpers/databases/uuidv7";
import { prisma } from "../../src/utils/databases/prisma/connection";
export const userRoleSeed = async (SystemAccountId: string) => {
console.log("🔃 Seeding user roles...");
const roles = [
{
name: "ADMIN",
description: "Administrator with full access",
isSuperadmin: true,
canEditMedia: true,
canManageMedia: true,
canEditEpisodes: true,
canManageEpisodes: true,
canEditComment: true,
canManageComment: true,
canEditUser: true,
canManageUser: true,
canEditSystem: true,
canManageSystem: true,
createdBy: SystemAccountId,
},
{
name: "USER",
description: "Regular user with limited access",
isSuperadmin: false,
canEditMedia: false,
canManageMedia: false,
canEditEpisodes: false,
canManageEpisodes: false,
canEditComment: false,
canManageComment: false,
canEditUser: false,
canManageUser: false,
canEditSystem: false,
canManageSystem: false,
createdBy: SystemAccountId,
},
];
await prisma.$transaction(async (tx) => {
const createdRoles = await Promise.all(
roles.map(
async (role) =>
await tx.userRole.upsert({
where: { name: role.name },
update: role,
create: {
id: generateUUIDv7(),
...role,
},
}),
),
);
await tx.userRoleAssignment.upsert({
where: {
userId_roleId: {
userId: SystemAccountId,
roleId: createdRoles.find((r) => r.name === "ADMIN")!.id,
},
},
create: {
userId: SystemAccountId,
roleId: createdRoles.find((r) => r.name === "ADMIN")!.id,
},
update: {
userId: SystemAccountId,
roleId: createdRoles.find((r) => r.name === "ADMIN")!.id,
},
});
});
};

View File

@ -9,6 +9,7 @@ export const userSystemSeed = async () => {
fullname: "SYSTEM", fullname: "SYSTEM",
email: process.env.DEFAULT_ADMIN_EMAIL!, email: process.env.DEFAULT_ADMIN_EMAIL!,
password: await hashPassword(process.env.DEFAULT_ADMIN_PASSWORD!), password: await hashPassword(process.env.DEFAULT_ADMIN_PASSWORD!),
role: "admin"
} as Prisma.UserCreateInput; } as Prisma.UserCreateInput;
const insertedUserSystem = await prisma.user.upsert({ const insertedUserSystem = await prisma.user.upsert({