- Home
- Skills
- Cameronapak
- Bknd Skills
- Bknd Seed Data
bknd-seed-data_skill
2
GitHub Stars
1
Bundled Files
2 months ago
Catalog Refreshed
4 months ago
First Indexed
Readme & install
Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.
Installation
Preview and clipboard use veilstrat where the catalogue uses aiagentskills.
npx veilstrat add skill cameronapak/bknd-skills --skill bknd-seed-data- SKILL.md11.4 KB
Overview
This skill shows how to populate a Bknd database with initial, test, or demo data using the options.seed function. It documents using ctx.em.mutator() for insertOne/insertMany, conditional checks to avoid duplicates, environment-based seeding, and common patterns for dev/test fixtures. Follow the patterns to keep seeds idempotent and safe for production.
How this skill works
Add a seed async function under options in your Bknd config. Use ctx.em.mutator(entity).insertOne(...) or insertMany([...]) to create records server-side. Protect runs with repo queries (count or findOne) and environment checks so seeds are idempotent and avoid inserting duplicate or sensitive data on every startup.
When to use it
- Populate initial data on first startup or after schema sync
- Create test fixtures for development and CI runs
- Bootstrap admin users, roles, or required default records
- Generate demo data for presentations or local testing
- Load environment-specific datasets (dev vs production)
Best practices
- Always check for existing records (count or findOne) before inserting
- Insert parent entities before children to satisfy foreign keys
- Guard production with NODE_ENV and only insert essential data there
- Keep seed functions idempotent and log progress for debugging
- Avoid seeding sensitive credentials; use env vars for production admin
Example use cases
- Seed an admin user and default roles if no users exist
- Generate 50 test posts and 10 fake users for local development
- Create tags and link them to posts after inserting users
- Use factory functions or faker to create varied test fixtures
- Conditionally skip full dev seed when running in production
FAQ
Yes. The seed function runs on every startup and after schema sync, so add existence checks to avoid duplicates.
How do I avoid foreign key constraint errors?
Insert parent records first, capture their IDs, then insert child records referencing those IDs.
Can I run different seeds for dev and production?
Yes. Use process.env.NODE_ENV or another flag to guard dev-only test data and restrict production seeding to essential records.