53 lines
1.2 KiB
TypeScript
53 lines
1.2 KiB
TypeScript
import { PrismaClient } from "@prisma/client"
|
|
import { defaultCategories, defaultRootFolder } from "../lib/defaults"
|
|
|
|
const prisma = new PrismaClient()
|
|
|
|
async function main() {
|
|
console.log("Seeding database...")
|
|
|
|
// Create root folder if it doesn't exist
|
|
const rootFolder = await prisma.folder.upsert({
|
|
where: { id: defaultRootFolder.id },
|
|
update: {},
|
|
create: defaultRootFolder,
|
|
})
|
|
|
|
console.log("Root folder created:", rootFolder.name)
|
|
|
|
// Create default categories
|
|
for (const category of defaultCategories) {
|
|
const existing = await prisma.category.findFirst({
|
|
where: {
|
|
name: category.name,
|
|
parentId: category.parentId,
|
|
},
|
|
})
|
|
|
|
if (!existing) {
|
|
await prisma.category.create({
|
|
data: {
|
|
name: category.name,
|
|
color: category.color,
|
|
icon: category.icon,
|
|
keywords: JSON.stringify(category.keywords),
|
|
parentId: category.parentId,
|
|
},
|
|
})
|
|
console.log(`Created category: ${category.name}`)
|
|
}
|
|
}
|
|
|
|
console.log("Seeding completed!")
|
|
}
|
|
|
|
main()
|
|
.catch((e) => {
|
|
console.error(e)
|
|
process.exit(1)
|
|
})
|
|
.finally(async () => {
|
|
await prisma.$disconnect()
|
|
})
|
|
|