db-seed
Generate database seed scripts with realistic sample data. Reads Drizzle schemas or SQL migrations, respects foreign key ordering, produces idempotent TypeScript or SQL seed files. Handles D1 batch limits, unique constraints, and domain-appropriate data. Use when populating dev/demo/test databases. Triggers: 'seed database', 'seed data', 'sample data', 'populate database', 'db seed', 'test data', 'demo data', 'generate fixtures'.
What this skill does
# Database Seed Generator Generate seed scripts that populate databases with realistic, domain-appropriate sample data. Reads your schema and produces ready-to-run seed files. ## Workflow ### 1. Find the Schema Scan the project for schema definitions: | Source | Location pattern | |--------|-----------------| | Drizzle schema | `src/db/schema.ts`, `src/schema/*.ts`, `db/schema.ts` | | D1 migrations | `drizzle/*.sql`, `migrations/*.sql` | | Raw SQL | `schema.sql`, `db/*.sql` | | Prisma | `prisma/schema.prisma` | Read all schema files. Build a mental model of: - Tables and their columns - Data types and constraints (NOT NULL, UNIQUE, DEFAULT) - Foreign key relationships (which tables reference which) - JSON fields stored as TEXT (common in D1/SQLite) ### 2. Determine Seed Parameters Ask the user: | Parameter | Options | Default | |-----------|---------|---------| | Purpose | dev, demo, testing | dev | | Volume | small (5-10 rows/table), medium (20-50), large (100+) | small | | Domain context | "e-commerce store", "SaaS app", "blog", etc. | Infer from schema | | Output format | TypeScript (Drizzle), raw SQL, or both | Match project's ORM | **Purpose affects data quality**: - **dev**: Varied data, some edge cases (empty fields, long strings, unicode) - **demo**: Polished data that looks good in screenshots and presentations - **testing**: Systematic data covering boundary conditions, duplicates, special characters ### 3. Plan Insert Order Build a dependency graph from foreign keys. Insert parent tables before children. Example order for a blog schema: ``` 1. users (no dependencies) 2. categories (no dependencies) 3. posts (depends on users, categories) 4. comments (depends on users, posts) 5. tags (no dependencies) 6. post_tags (depends on posts, tags) ``` **Circular dependencies**: If table A references B and B references A, use nullable foreign keys and insert in two passes (insert with NULL, then UPDATE). ### 4. Generate Realistic Data **Do NOT use generic placeholders** like "test123", "[email protected]", or "Lorem ipsum". Generate data that matches the domain. #### Data Generation Patterns (no external libraries needed) **Names**: Use a hardcoded list of common names. Mix genders and cultural backgrounds. ```typescript const firstNames = ['Sarah', 'James', 'Priya', 'Mohammed', 'Emma', 'Wei', 'Carlos', 'Aisha']; const lastNames = ['Chen', 'Smith', 'Patel', 'Garcia', 'Kim', 'O\'Brien', 'Nguyen', 'Wilson']; ``` **Emails**: Derive from names — `[email protected]`. Use `example.com` domain (RFC 2606 reserved). **Dates**: Generate within a realistic range. Use ISO 8601 format for D1/SQLite. ```typescript const randomDate = (daysBack: number) => { const d = new Date(); d.setDate(d.getDate() - Math.floor(Math.random() * daysBack)); return d.toISOString(); }; ``` **IDs**: Use `crypto.randomUUID()` for UUIDs, or sequential integers if the schema uses auto-increment. **Deterministic seeding**: For reproducible data, use a seeded PRNG: ```typescript function seededRandom(seed: number) { return () => { seed = (seed * 16807) % 2147483647; return (seed - 1) / 2147483646; }; } const rand = seededRandom(42); // Same seed = same data every time ``` **Prices/amounts**: Use realistic ranges. `(rand() * 900 + 100).toFixed(2)` for $1-$10 range. **Descriptions/content**: Write 3-5 realistic variations per content type and cycle through them. Don't generate AI-sounding prose — write like real user data. ### 5. Output Format #### TypeScript (Drizzle ORM) ```typescript // scripts/seed.ts import { drizzle } from 'drizzle-orm/d1'; import * as schema from '../src/db/schema'; export async function seed(db: ReturnType<typeof drizzle>) { console.log('Seeding database...'); // Clear existing data (reverse dependency order) await db.delete(schema.comments); await db.delete(schema.posts); await db.delete(schema.users); // Insert users const users = [ { id: crypto.randomUUID(), name: 'Sarah Chen', email: '[email protected]', ... }, // ... ]; // D1 batch limit: 10 rows per INSERT for (let i = 0; i < users.length; i += 10) { await db.insert(schema.users).values(users.slice(i, i + 10)); } // Insert posts (references users) const posts = [ { id: crypto.randomUUID(), userId: users[0].id, title: '...', ... }, // ... ]; for (let i = 0; i < posts.length; i += 10) { await db.insert(schema.posts).values(posts.slice(i, i + 10)); } console.log(`Seeded: ${users.length} users, ${posts.length} posts`); } ``` Run with: `npx tsx scripts/seed.ts` For Cloudflare Workers, add a seed endpoint (remove before production): ```typescript app.post('/api/seed', async (c) => { const db = drizzle(c.env.DB); await seed(db); return c.json({ ok: true }); }); ``` #### Raw SQL (D1) ```sql -- seed.sql -- Run: npx wrangler d1 execute DB_NAME --local --file=./scripts/seed.sql -- Clear existing (reverse order) DELETE FROM comments; DELETE FROM posts; DELETE FROM users; -- Users INSERT INTO users (id, name, email, created_at) VALUES ('uuid-1', 'Sarah Chen', '[email protected]', '2025-01-15T10:30:00Z'), ('uuid-2', 'James Wilson', '[email protected]', '2025-02-01T14:22:00Z'); -- Posts (max 10 rows per INSERT for D1) INSERT INTO posts (id, user_id, title, body, created_at) VALUES ('post-1', 'uuid-1', 'Getting Started', 'Welcome to...', '2025-03-01T09:00:00Z'); ``` ### 6. Idempotency Seed scripts must be safe to re-run: ```typescript // Option A: Delete-then-insert (simple, loses data) await db.delete(schema.users); await db.insert(schema.users).values(seedUsers); // Option B: Upsert (preserves non-seed data) for (const user of seedUsers) { await db.insert(schema.users) .values(user) .onConflictDoUpdate({ target: schema.users.id, set: user }); } ``` Default to Option A for dev/testing, Option B for demo (where users may have added their own data). ## D1-Specific Gotchas | Gotcha | Solution | |--------|----------| | Max ~10 rows per INSERT | Batch inserts in chunks of 10 | | No native BOOLEAN | Use INTEGER (0/1) | | No native DATETIME | Use TEXT with ISO 8601 strings | | JSON stored as TEXT | `JSON.stringify()` before insert | | Foreign keys always enforced | Insert parent tables first | | 100 bound parameter limit | Keep batch size × columns < 100 | ## Quality Rules 1. **Match the domain** — an e-commerce seed has products with real-sounding names and prices, not "Product 1" 2. **Vary the data** — don't make every user "John Smith" or every price "$9.99" 3. **Include edge cases** (for testing seeds) — empty strings, very long text, special characters, maximum values 4. **Reference real IDs** — foreign keys must point to actually-inserted parent rows 5. **Print what was seeded** — always log counts so the user knows it worked 6. **Document the run command** — put it in a comment at the top of the file
Related in Backend & APIs
jfrog
IncludedInteract with the JFrog Platform via the JFrog CLI and REST/GraphQL APIs. Use this skill when the user wants to manage Artifactory repositories, upload or download artifacts, manage builds, configure permissions, manage users and groups, work with access tokens, configure JFrog CLI servers, search artifacts, manage properties, set up replication, manage JFrog Projects, run security audits or scans, look up CVE details, query exposures scan results from JFrog Advanced Security, manage release bundles and lifecycle operations, aggregate or export platform data, or perform any JFrog Platform administration task. Also use when the user mentions jf, jfrog, artifactory, xray, distribution, evidence, apptrust, onemodel, graphql, workers, mission control, curation, advanced security, exposures, or any JFrog product name.
cupynumeric-migration-readiness
IncludedPre-migration readiness assessor for porting NumPy to cuPyNumeric. Use BEFORE substantial porting work begins when the user asks whether code will scale on GPU, whether they should migrate to cuPyNumeric, which NumPy patterns transfer cleanly, what must be refactored before porting, or mentions pre-port assessment, scaling analysis, or refactor planning. Inspect the user's source code, look up NumPy usage, cross-reference the cuPyNumeric API support manifest, and distinguish distributed-scaling-friendly patterns from blockers such as unsupported APIs, scalar synchronization, host round-trips, Python/object-heavy control flow, shape/data-dependent branching, and in-place mutation hazards. Produce a verdict of READY, LIGHT REFACTOR, SIGNIFICANT REFACTOR, or NOT RECOMMENDED, with concrete refactor pointers.
alibabacloud-data-agent-skill
IncludedInvoke Alibaba Cloud Apsara Data Agent for Analytics via CLI to perform natural language-driven data analysis on enterprise databases. Data Agent for Analytics is an intelligent data analysis agent developed by Alibaba Cloud Database team for enterprise users. It automatically completes requirement analysis, data understanding, analysis insights, and report generation based on natural language descriptions. This tool supports: discovering data resources (instances/databases/tables) managed in DMS, initiating query or deep analysis sessions, real-time progress tracking, and retrieving analysis conclusions and generated reports. Use this Skill when users need to query databases, analyze data trends, generate data reports, ask questions in natural language, or mention "Data Agent", "data analysis", "database query", "SQL analysis", "data insights".
token-optimizer
IncludedReduce OpenClaw token usage and API costs through smart model routing, heartbeat optimization, budget tracking, and native 2026.2.15 features (session pruning, bootstrap size limits, cache TTL alignment). Use when token costs are high, API rate limits are being hit, or hosting multiple agents at scale. The 4 executable scripts (context_optimizer, model_router, heartbeat_optimizer, token_tracker) are local-only — no network requests, no subprocess calls, no system modifications. Reference files (PROVIDERS.md, config-patches.json) document optional multi-provider strategies that require external API keys and network access if you choose to use them. See SECURITY.md for full breakdown.
resend-cli
IncludedUse this skill when the task is specifically about operating Resend from an AI agent, terminal session, or CI job via the official resend CLI: installing/authenticating the CLI, sending/listing/updating/cancelling emails, batch sends, domains and DNS, webhooks and local listeners, inbound receiving, contacts, topics, segments, broadcasts, templates, API keys, profiles, or debugging Resend CLI/API failures. Trigger on mentions of Resend CLI, `resend`, `resend doctor`, `resend emails send`, `resend domains`, `resend webhooks listen`, `resend emails receiving`, or agent-friendly terminal automation.
alibabacloud-odps-maxframe-coding
IncludedUse this skill for MaxFrame SDK development and documentation navigation on Alibaba Cloud MaxCompute (ODPS). Helps answer MaxFrame API, concept, official example, and supported pandas API questions; create data processing programs; read/write MaxCompute tables; debug jobs (remote or local); and build custom DPE runtime images. Trigger when users mention MaxFrame, MaxCompute with MaxFrame, ODPS table processing, DPE runtime, MaxFrame docs/examples, DataFrame/Tensor operations, or GPU runtime setup. Works for both English and Chinese queries about Alibaba Cloud data processing with MaxFrame.