37 lines
776 B
TypeScript
37 lines
776 B
TypeScript
import { PrismaClient } from '../src/generated/prisma/client.js'
|
|
|
|
import { PrismaPg } from '@prisma/adapter-pg'
|
|
|
|
const adapter = new PrismaPg({
|
|
connectionString: process.env.DATABASE_URL!,
|
|
})
|
|
|
|
const prisma = new PrismaClient({ adapter })
|
|
|
|
async function main() {
|
|
console.log('🌱 Seeding database...')
|
|
|
|
// Clear existing todos
|
|
await prisma.todo.deleteMany()
|
|
|
|
// Create example todos
|
|
const todos = await prisma.todo.createMany({
|
|
data: [
|
|
{ title: 'Buy groceries' },
|
|
{ title: 'Read a book' },
|
|
{ title: 'Workout' },
|
|
],
|
|
})
|
|
|
|
console.log(`✅ Created ${todos.count} todos`)
|
|
}
|
|
|
|
main()
|
|
.catch((e) => {
|
|
console.error('❌ Error seeding database:', e)
|
|
process.exit(1)
|
|
})
|
|
.finally(async () => {
|
|
await prisma.$disconnect()
|
|
})
|