Db Seed
Generate database seed scripts with realistic sample data. Reads Drizzle schemas or SQL migrations, respects foreign key ordering, produces idempotent
Category: development Source: jezweb/claude-skills
Generate database seed scripts with realistic sample data. Reads Drizzle schemas or SQL migrations, respects foreign key ordering, produces idempotent
Category: development Source: jezweb/claude-skillssrc/db/schema.ts, src/schema/*.ts, or db/schema.ts - SQL migrations in drizzle/*.sql or migrations/*.sql - Raw SQL in schema.sql or db/*.sql - Prisma schema in prisma/schema.prisma 2. Invoke the Skill: Use trigger phrases such as “seed database,” “sample data,” or “generate fixtures” within your Claude Code environment. 3. Configure Parameters: Db Seed will prompt you for intent and scale, such as: - Purpose: (dev, demo, test) - Volume: Number of rows per table or total dataset size 4. Review and Run Generated Scripts: Db Seed produces idempotent TypeScript or SQL seed files. Review the output and run the scripts against your database. ### Example: Seeding a Simple User and Posts Schema Suppose you have the following Drizzle schema: typescript // src/db/schema.ts import { integer, text, pgTable } from "drizzle-orm/pg-core"; export const users = pgTable("users", { id: integer("id").primaryKey(), email: text("email").unique().notNull(), name: text("name"), }); export const posts = pgTable("posts", { id: integer("id").primaryKey(), userId: integer("user_id").references(() => users.id), title: text("title").notNull(), content: text("content"), }); Db Seed can generate a TypeScript seed file similar to: typescript await db.insert(users).values([ { id: 1, email: "alice@example.com", name: "Alice" }, { id: 2, email: "bob@example.com", name: "Bob" }, ]); await db.insert(posts).values([ { id: 1, userId: 1, title: "Hello World", content: "This is Alice's first post." }, { id: 2, userId: 2, title: "Greetings", content: "Bob says hello." }, ]); ## Key Features Db Seed offers several advanced capabilities tailored for modern development workflows: - Schema Awareness: Reads Drizzle TypeScript schemas, raw SQL files, and Prisma definitions to infer table structures, data types, relationships, and constraints. - Foreign Key Ordering: Automatically determines the correct order for inserting records, ensuring that parent records (e.g., users) are created before dependent records (e.g., posts). - Idempotent Scripts: Generates seed files that can be safely re-run without duplicating or corrupting data. - Constraint Handling: Respects UNIQUE, NOT NULL, DEFAULT, and foreign key constraints, avoiding common pitfalls in sample data generation. - Realistic Data: Fills tables with domain-appropriate fake data, rather than generic placeholders, enhancing the realism of dev and demo environments. - Batch and Limit Awareness: Handles D1 batch limits and other platform-specific constraints to avoid runtime errors during seeding. - Flexible Output: Produces TypeScript or SQL files, supporting a range of tech stacks and workflows. ## Best Practices To get the most out of Db Seed, consider the following best practices: - Keep Your Schema Up-to-Date: Ensure your schema files accurately reflect your production database. Outdated schemas can lead to invalid seed data. - Use for Dev, Demo, and Test Only: Seed data is intended for non-production use. Never seed real production databases with generated data. - Customize When Needed: While Db Seed generates realistic defaults, review and tweak the generated seed data for scenarios requiring specific edge cases. - Version Your Seed Scripts: Store generated scripts in version control to ensure consistent environments across teams. - Automate Seeding in CI: Integrate seed script execution into your CI/CD pipeline to set up test databases automatically. ## Important Notes