feat(schema): 게시판 대분류 BoardCategory 및 보드-카테고리 연동 추가\nchore(seed): 기본 카테고리 시드 및 보드 매핑 반영\ndocs(erd): ERD 업데이트

This commit is contained in:
mota
2025-10-13 06:29:33 +09:00
parent 173730a7c4
commit 17a071f125
4 changed files with 116 additions and 3 deletions

View File

@@ -2,6 +2,25 @@ const { PrismaClient } = require("@prisma/client");
const prisma = new PrismaClient();
async function upsertCategories() {
const categories = [
{ name: "운영", slug: "ops", sortOrder: 1, status: "active" },
{ name: "커뮤니티", slug: "community", sortOrder: 2, status: "active" },
{ name: "특수", slug: "special", sortOrder: 3, status: "active" },
{ name: "제휴", slug: "partners", sortOrder: 4, status: "active" },
];
const map = {};
for (const c of categories) {
const created = await prisma.boardCategory.upsert({
where: { slug: c.slug },
update: { name: c.name, sortOrder: c.sortOrder, status: c.status },
create: c,
});
map[c.slug] = created;
}
return map; // { slug: category }
}
async function upsertRoles() {
const roles = [
{ name: "admin", description: "관리자" },
@@ -85,7 +104,7 @@ async function upsertAdmin() {
return admin;
}
async function upsertBoards(admin) {
async function upsertBoards(admin, categoryMap) {
const boards = [
// 일반
{ name: "공지사항", slug: "notice", description: "공지", type: "general", sortOrder: 1, writeLevel: "moderator" },
@@ -111,6 +130,13 @@ async function upsertBoards(admin) {
const created = [];
for (const b of boards) {
// 카테고리 매핑 규칙
let categorySlug = "community";
if (["notice", "bug-report"].includes(b.slug)) categorySlug = "ops";
if (["attendance", "nearby-partners", "ranking", "free-coupons", "monthly-stats"].includes(b.slug)) categorySlug = "special";
if (["partners-photos"].includes(b.slug)) categorySlug = "partners";
const category = categoryMap[categorySlug];
const board = await prisma.board.upsert({
where: { slug: b.slug },
update: {
@@ -120,6 +146,7 @@ async function upsertBoards(admin) {
requiresApproval: !!b.requiresApproval,
allowAnonymousPost: !!b.allowAnonymousPost,
readLevel: b.readLevel || undefined,
categoryId: category ? category.id : undefined,
},
create: {
name: b.name,
@@ -130,6 +157,7 @@ async function upsertBoards(admin) {
requiresApproval: !!b.requiresApproval,
allowAnonymousPost: !!b.allowAnonymousPost,
readLevel: b.readLevel || undefined,
categoryId: category ? category.id : undefined,
},
});
created.push(board);
@@ -181,7 +209,8 @@ async function seedPolicies() {
async function main() {
await upsertRoles();
const admin = await upsertAdmin();
const boards = await upsertBoards(admin);
const categoryMap = await upsertCategories();
const boards = await upsertBoards(admin, categoryMap);
// 샘플 글 하나
const free = boards.find((b) => b.slug === "free") || boards[0];