Files
msgapp/prisma/seed.js

64 lines
1.4 KiB
JavaScript
Raw Normal View History

2025-10-08 23:04:12 +09:00
const { PrismaClient } = require("@prisma/client");
const prisma = new PrismaClient();
async function main() {
2025-10-08 23:44:21 +09:00
const user = await prisma.user.upsert({
where: { nickname: "tester" },
2025-10-08 23:04:12 +09:00
update: {},
create: {
2025-10-08 23:44:21 +09:00
nickname: "tester",
2025-10-08 23:04:12 +09:00
name: "Tester",
2025-10-08 23:44:21 +09:00
birth: new Date("1990-01-01"),
phone: "010-0000-0000",
agreementTermsAt: new Date()
2025-10-08 23:04:12 +09:00
}
});
2025-10-08 23:44:21 +09:00
const board = await prisma.board.upsert({
where: { slug: "general" },
update: {},
create: {
name: "General",
slug: "general",
description: "일반 게시판",
sortOrder: 0
}
});
const post = await prisma.post.create({
data: {
boardId: board.id,
authorId: user.userId,
title: "첫 글",
content: "Hello SQLite + Prisma",
isPinned: false,
status: "published"
}
});
await prisma.boardModerator.upsert({
where: { boardId_userId: { boardId: board.id, userId: user.userId } },
update: {},
create: { boardId: board.id, userId: user.userId, role: "MODERATOR" }
});
await prisma.comment.createMany({
data: [
{ postId: post.id, authorId: user.userId, content: "첫 댓글" },
{ postId: post.id, authorId: user.userId, content: "두번째 댓글" }
]
});
2025-10-08 23:04:12 +09:00
}
main()
.catch((e) => {
console.error(e);
process.exit(1);
})
.finally(async () => {
await prisma.$disconnect();
});