Files
petfeed/prisma/seed.ts
T
admin 69553b103b feat(01-03): extend pets router (update/delete/listSpecies/listBreeds) + breed seed
- Add assertPetOwnership helper (T-3-01: ownership check before every mutation)
- Add pets.update with Zod limits (name<=30, bio<=150, adoptionStory<=500)
- Add pets.delete with ownership assertion
- Add pets.listSpecies (protectedProcedure — T-3-04 scraping prevention)
- Add pets.listBreeds filtered by speciesId
- Extend seed with 45 breeds: 20 dog, 15 cat, 10 bird (idempotent upserts)
- Install react-hook-form + @hookform/resolvers for PetForm (Task 2)
2026-06-06 10:07:04 +02:00

117 lines
2.5 KiB
TypeScript

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) and Breed taxonomy idempotently.
* Uses upsert so it is safe to run multiple times.
*
* 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 });
const DOG_BREEDS = [
"Labrador Retriever",
"Golden Retriever",
"German Shepherd",
"French Bulldog",
"Bulldog",
"Poodle",
"Beagle",
"Rottweiler",
"German Shorthaired Pointer",
"Dachshund",
"Pembroke Welsh Corgi",
"Australian Shepherd",
"Yorkshire Terrier",
"Boxer",
"Cavalier King Charles Spaniel",
"Doberman Pinscher",
"Great Dane",
"Miniature Schnauzer",
"Siberian Husky",
"Border Collie",
];
const CAT_BREEDS = [
"Domestic Shorthair",
"Domestic Longhair",
"Maine Coon",
"Ragdoll",
"Siamese",
"Persian",
"Bengal",
"British Shorthair",
"Sphynx",
"Scottish Fold",
"American Shorthair",
"Abyssinian",
"Norwegian Forest Cat",
"Birman",
"Russian Blue",
];
const BIRD_BREEDS = [
"Budgerigar (Budgie)",
"Cockatiel",
"Lovebird",
"African Grey Parrot",
"Cockatoo",
"Conure",
"Macaw",
"Canary",
"Finch",
"Amazon Parrot",
];
async function main() {
console.log("Seeding species...");
const speciesData = [
{ name: "Dog", breeds: DOG_BREEDS },
{ name: "Cat", breeds: CAT_BREEDS },
{ name: "Bird", breeds: BIRD_BREEDS },
];
for (const s of speciesData) {
const species = await prisma.species.upsert({
where: { name: s.name },
update: {},
create: { name: s.name },
});
console.log(` Upserted species: ${species.name} (${species.id})`);
console.log(` Seeding ${s.breeds.length} breeds for ${species.name}...`);
for (const breedName of s.breeds) {
const breed = await prisma.breed.upsert({
where: { speciesId_name: { speciesId: species.id, name: breedName } },
update: {},
create: { speciesId: species.id, name: breedName },
});
console.log(` Upserted breed: ${breed.name}`);
}
}
console.log("Seeding complete.");
}
main()
.catch((e) => {
console.error(e);
process.exit(1);
})
.finally(async () => {
await prisma.$disconnect();
});