Initial commit
This commit is contained in:
+129
@@ -0,0 +1,129 @@
|
||||
// prisma/seed.ts
|
||||
import { PrismaClient } from "@prisma/client";
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
async function main() {
|
||||
console.log("🌱 Seeding database…");
|
||||
|
||||
// --- Create a test course ---
|
||||
const course = await prisma.course.upsert({
|
||||
where: { code: "ANIM101" },
|
||||
update: {},
|
||||
create: {
|
||||
code: "ANIM101",
|
||||
title: "3D Animation | Character Design",
|
||||
description: "Introductory course for animation students.",
|
||||
},
|
||||
});
|
||||
|
||||
// --- Create playlists for this course ---
|
||||
const playlist1 = await prisma.playlist.create({
|
||||
data: {
|
||||
title: "Introduction to Character Design",
|
||||
description: "Basic foundations and workflow.",
|
||||
sortOrder: 0,
|
||||
courseId: course.id,
|
||||
videos: {
|
||||
create: [
|
||||
{
|
||||
title: "Welcome + Overview",
|
||||
index: 0,
|
||||
durationSec: 300,
|
||||
url: "/videos/test.mp4",
|
||||
thumbnail: "/01.jpg",
|
||||
},
|
||||
{
|
||||
title: "Understanding Silhouette",
|
||||
index: 1,
|
||||
durationSec: 420,
|
||||
url: "/videos/test.mp4",
|
||||
thumbnail: "/01.jpg",
|
||||
},
|
||||
{
|
||||
title: "Gesture & Appeal",
|
||||
index: 2,
|
||||
durationSec: 380,
|
||||
url: "/videos/test.mp4",
|
||||
thumbnail: "/01.jpg",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
include: { videos: true },
|
||||
});
|
||||
|
||||
const playlist2 = await prisma.playlist.create({
|
||||
data: {
|
||||
title: "Advanced Character Techniques",
|
||||
description: "Secondary forms, expression & posing.",
|
||||
sortOrder: 1,
|
||||
courseId: course.id,
|
||||
videos: {
|
||||
create: [
|
||||
{
|
||||
title: "Secondary Motion",
|
||||
index: 0,
|
||||
durationSec: 400,
|
||||
url: "/videos/test.mp4",
|
||||
thumbnail: "/01.jpg",
|
||||
},
|
||||
{
|
||||
title: "Expressions & Acting Choices",
|
||||
index: 1,
|
||||
durationSec: 600,
|
||||
url: "/videos/test.mp4",
|
||||
thumbnail: "/01.jpg",
|
||||
locked: true,
|
||||
},
|
||||
{
|
||||
title: "Polish & Finishing",
|
||||
index: 2,
|
||||
durationSec: 500,
|
||||
url: "/videos/test.mp4",
|
||||
thumbnail: "/01.jpg",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
include: { videos: true },
|
||||
});
|
||||
|
||||
// --- Create a test user ---
|
||||
const user = await prisma.user.upsert({
|
||||
where: { email: "student@example.com" },
|
||||
update: {},
|
||||
create: {
|
||||
email: "student@example.com",
|
||||
name: "Test Student",
|
||||
image: null,
|
||||
},
|
||||
});
|
||||
|
||||
// --- Enroll test user into the course ---
|
||||
await prisma.enrollment.upsert({
|
||||
where: {
|
||||
userId_courseId: {
|
||||
userId: user.id,
|
||||
courseId: course.id,
|
||||
},
|
||||
},
|
||||
update: {},
|
||||
create: {
|
||||
userId: user.id,
|
||||
courseId: course.id,
|
||||
},
|
||||
});
|
||||
|
||||
console.log("🌱 Seed complete!");
|
||||
console.log("Test user:", user.email);
|
||||
console.log("Course created:", course.title);
|
||||
}
|
||||
|
||||
main()
|
||||
.catch((e) => {
|
||||
console.error(e);
|
||||
process.exit(1);
|
||||
})
|
||||
.finally(async () => {
|
||||
await prisma.$disconnect();
|
||||
});
|
||||
Reference in New Issue
Block a user