import { PrismaClient } from "@prisma/client"; import { PrismaPg } from "@prisma/adapter-pg"; import { Pool } from "pg"; /** * Seed script for the OnlyPets database. * Seeds Species (Dog, Cat, Bird) idempotently. * Plan 03 will extend this with breed taxonomy data. * * Run: npx tsx prisma/seed.ts * Or: npx prisma db seed */ const databaseUrl = process.env.DATABASE_URL; if (!databaseUrl) { throw new Error( "DATABASE_URL is not set. Please add it to .env.local first." ); } const adapter = new PrismaPg(new Pool({ connectionString: databaseUrl })); const prisma = new PrismaClient({ adapter }); async function main() { console.log("Seeding species..."); const species = [ { name: "Dog" }, { name: "Cat" }, { name: "Bird" }, ]; for (const s of species) { const result = await prisma.species.upsert({ where: { name: s.name }, update: {}, create: { name: s.name }, }); console.log(` Upserted species: ${result.name} (${result.id})`); } console.log("Seeding complete."); } main() .catch((e) => { console.error(e); process.exit(1); }) .finally(async () => { await prisma.$disconnect(); });