fix: remove all unessecary seeding
This commit is contained in:
@ -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");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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,
|
|
||||||
}),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
@ -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,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
|
||||||
@ -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({
|
||||||
|
|||||||
Reference in New Issue
Block a user