Init
This commit is contained in:
8
prisma/schema.prisma
Normal file
8
prisma/schema.prisma
Normal file
@@ -0,0 +1,8 @@
|
||||
generator client {
|
||||
provider = "prisma-client"
|
||||
output = "../src/generated/prisma"
|
||||
}
|
||||
|
||||
datasource db {
|
||||
provider = "postgresql"
|
||||
}
|
||||
36
prisma/seed.ts
Normal file
36
prisma/seed.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
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()
|
||||
})
|
||||
Reference in New Issue
Block a user