xiaohongshu
xiaohongshu
db-seeder
This skill should be used when seeding databases with realistic fake data for development, testing, or staging environments. Supports PostgreSQL, MySQL, SQLite, MongoDB with ORM-based seeding (SQLAlchemy, Django, Prisma) and Faker library for generating realistic test data. Use when the user need...
Full skill instructions
Seed any database with realistic fake data using ORM patterns and the Faker library. This skill provides scripts, references, and templates for efficiently populating databases with test data for development, testing, and staging environments.
Use this skill when:
The skill automatically detects database configuration from:
DATABASE_URL, DB_TYPE, etc.).env, settings.py, config.yaml)alembic.ini)Before seeding, detect the database configuration automatically:
python scripts/detect_db_config.py
The detection script will:
DATABASE_URL, DB_TYPE, etc.).env, settings.py, alembic.ini)NEW: Automatically inspect your database schema to generate factories and fixtures:
# Inspect schema and print summary
python scripts/inspect_schema.py \
--db postgresql \
--connection "postgresql://user:pass@localhost/mydb"
# Generate factory functions for all tables
python scripts/inspect_schema.py \
--db postgresql \
--connection "postgresql://user:pass@localhost/mydb" \
--generate-factories
# Generate JSON fixture templates
python scripts/inspect_schema.py \
--db postgresql \
--connection "postgresql://user:pass@localhost/mydb" \
--generate-fixtures \
--fixture-count 5
# Both
python scripts/inspect_schema.py \
--db postgresql \
--connection "postgresql://user:pass@localhost/mydb" \
--generate-factories \
--generate-fixtures
What it does:
generated_factories.py)generated_fixtures.json)Works with ANY schema - No hardcoded assumptions!
Manual Configuration: If auto-detection fails, specify database details manually:
# PostgreSQL
python scripts/seed_database.py \
--db postgresql \
--connection "postgresql://user:pass@localhost:5432/mydb" \
--count 100
# SQLite
python scripts/seed_database.py \
--db sqlite \
--connection "sqlite:///./test.db" \
--count 50
# MongoDB
python scripts/seed_database.py \
--db mongodb \
--connection "mongodb://admin:pass@localhost:27017/mydb" \
--count 100
Configuration Files Reference:
For detailed database connection patterns and configuration examples, refer to:
references/database-configs.md
Three primary approaches are available:
Generate reusable JSON fixtures that can be version-controlled and shared:
# Generate using predefined templates
python scripts/generate_fixtures.py \
--template elios-interview \
--output fixtures/elios_data.json \
--pretty
# Generate specific models
python scripts/generate_fixtures.py \
--models User:100,Post:500,Candidate:50 \
--output fixtures/test_data.json \
--pretty
# Seed database from fixtures
python scripts/seed_database.py \
--fixtures fixtures/test_data.json \
--db postgresql \
--connection "postgresql://user:pass@localhost/db"
Benefits:
Create Python factory functions and seed directly:
# Create seeding script: scripts/seed_elios.py
from seed_database import DatabaseSeeder, create_seeder
def candidate_factory(fake, index):
return {
'full_name': fake.name(),
'email': fake.email(),
'years_of_experience': fake.random_int(min=0, max=15),
'skills': fake.random_elements(
['Python', 'JavaScript', 'SQL', 'React'],
length=fake.random_int(min=2, max=6),
unique=True
),
'status': fake.random_element(['pending', 'interviewed', 'hired']),
}
# Run seeding
seeder = create_seeder('postgresql', 'postgresql://user:pass@localhost/db')
seeder.seed_model(Candidate, count=50, factory_func=candidate_factory)
Benefits:
Use YAML configuration file for declarative seeding:
# Copy template
cp assets/seed-config-template.yaml seed-config.yaml
# Edit seed-config.yaml to define models and factories
# Run seeding
python scripts/seed_database.py --config seed-config.yaml
Benefits:
Based on chosen approach:
For Fixtures:
python scripts/seed_database.py \
--fixtures fixtures/test_data.json \
--db postgresql \
--connection "postgresql://user:pass@localhost/db"
For Custom Factories:
python scripts/seed_elios.py
For Configuration:
python scripts/seed_database.py --config seed-config.yaml
After seeding completes, verify the data:
# For PostgreSQL/MySQL
psql -d mydb -c "SELECT COUNT(*) FROM users;"
psql -d mydb -c "SELECT COUNT(*) FROM candidates;"
# For SQLite
sqlite3 mydb.db "SELECT COUNT(*) FROM users;"
# For MongoDB
mongosh mydb --eval "db.users.countDocuments()"
scripts/)seed_database.pyMain seeding orchestrator with Faker integration.
Features:
Usage:
# Seed from fixtures
python scripts/seed_database.py \
--fixtures data.json \
--db postgresql \
--connection "postgresql://user:pass@localhost/db"
# Seed from config
python scripts/seed_database.py --config seed-config.yaml
# Custom locale for international data
python scripts/seed_database.py \
--fixtures data.json \
--db sqlite \
--connection "sqlite:///test.db" \
--locale fr_FR
detect_db_config.pyAutomatically detects database configuration from project.
Features:
.env, settings.py, config.yaml)Usage:
# Auto-detect
python scripts/detect_db_config.py
# Specify config file
python scripts/detect_db_config.py --config-path src/infrastructure/config/settings.py
# Specify .env file
python scripts/detect_db_config.py --env-file .env.local
# Specify project root
python scripts/detect_db_config.py --project-root /path/to/project
generate_fixtures.pyGenerates JSON fixtures with realistic fake data.
Features:
Usage:
# Generate from template
python scripts/generate_fixtures.py \
--template elios-interview \
--output fixtures.json \
--pretty
# Generate specific models
python scripts/generate_fixtures.py \
--models User:100,Post:500 \
--output test_data.json
# Use different locale (Vietnamese)
python scripts/generate_fixtures.py \
--template elios-interview \
--locale vi_VN \
--output vietnamese_data.json \
--pretty
# Japanese locale
python scripts/generate_fixtures.py \
--template blog \
--locale ja_JP \
--output japanese_blog_data.json
Available Templates:
elios-interview - Candidates, Questions, Interview Sessions (Elios-specific)blog - Users, PostsSupported Locales:
en_US - English (United States) - Defaultvi_VN - Vietnamese (Vietnam) - Includes Vietnamese universities, degrees, majorsja_JP - Japanese (Japan)fr_FR - French (France)en_GB - English (United Kingdom)inspect_schema.py ⭐ NEWAutomatically inspects database schema and generates seeding helpers.
Features:
Usage:
# Print schema summary
python scripts/inspect_schema.py \
--db postgresql \
--connection "postgresql://user:pass@localhost/mydb"
# Generate factory functions for all tables
python scripts/inspect_schema.py \
--db postgresql \
--connection "postgresql://user:pass@localhost/mydb" \
--generate-factories
# Output: generated_factories.py
# Generate JSON fixture templates
python scripts/inspect_schema.py \
--db postgresql \
--connection "postgresql://user:pass@localhost/mydb" \
--generate-fixtures \
--fixture-count 5
# Output: generated_fixtures.json
# Generate both
python scripts/inspect_schema.py \
--db sqlite \
--connection "sqlite:///./test.db" \
--generate-factories \
--generate-fixtures
# Save schema info as JSON
python scripts/inspect_schema.py \
--db postgresql \
--connection "postgresql://user:pass@localhost/mydb" \
--output schema_info.json
Smart Field Detection: The script intelligently detects field types and generates appropriate Faker methods:
email field → fake.email()phone field → fake.phone_number()address field → fake.address()first_name field → fake.first_name()description field → fake.paragraph()created_at (TIMESTAMP) → fake.date_time_between()fake.random_int()fake.boolean()Example Output:
# generated_factories.py (auto-generated)
def candidate_factory(fake, index):
"""Factory for candidate model"""
return {
'full_name': fake.name(),
'email': fake.email(),
'phone': fake.phone_number(),
'years_of_experience': fake.random_int(min=1, max=1000),
'skills': {}, # JSON field
'created_at': fake.date_time_between(start_date='-1y', end_date='now'),
'status': fake.word(),
}
references/)database-configs.mdComprehensive database connection patterns and configuration examples.
Contents:
.env, settings.py, config.yaml)Use when:
faker-recipes.mdCommon patterns and examples for generating realistic fake data with Faker.
Contents:
Use when:
orm-patterns.mdPatterns and best practices for seeding databases using various ORMs.
Contents:
Use when:
assets/)seed-config-template.yamlTemplate for YAML-based seeding configuration.
Features:
Usage:
# Copy template
cp assets/seed-config-template.yaml seed-config.yaml
# Edit configuration
# ... customize models, counts, factories ...
# Run seeding
python scripts/seed_database.py --config seed-config.yaml
fixture-template.jsonTemplate for JSON test fixtures.
Features:
Usage:
# Copy and customize
cp assets/fixture-template.json fixtures/my_data.json
# Edit JSON file with your data
# ...
# Seed database
python scripts/seed_database.py \
--fixtures fixtures/my_data.json \
--db postgresql \
--connection "postgresql://user:pass@localhost/db"
Seed local database with sample data for immediate development:
# 1. Auto-detect database
python scripts/detect_db_config.py
# 2. Generate fixtures
python scripts/generate_fixtures.py \
--template elios-interview \
--output fixtures/dev_data.json
# 3. Seed database
python scripts/seed_database.py \
--fixtures fixtures/dev_data.json \
--db postgresql \
--connection "postgresql://postgres:password@localhost/elios_dev"
# Verify
psql -d elios_dev -c "SELECT COUNT(*) FROM candidates;"
Create fixtures for automated testing:
# Generate small, focused test fixtures
python scripts/generate_fixtures.py \
--models Candidate:10,Question:20,InterviewSession:5 \
--output tests/fixtures/test_data.json \
--pretty
# Use in tests:
# - Version control fixtures/test_data.json
# - Load in test setup
# - Consistent test data across CI/CD
Populate staging with production-like data:
# 1. Generate large dataset
python scripts/generate_fixtures.py \
--template elios-interview \
--output fixtures/staging_data.json
# Manually increase counts in fixture file if needed
# 2. Detect staging database
python scripts/detect_db_config.py --env-file .env.staging
# 3. Seed staging
python scripts/seed_database.py \
--fixtures fixtures/staging_data.json \
--db postgresql \
--connection "$STAGING_DATABASE_URL"
Test migrations with seeded data:
# 1. Seed old schema
python scripts/seed_database.py --fixtures fixtures/old_schema.json
# 2. Run migrations
alembic upgrade head
# 3. Verify data integrity
python scripts/verify_migration.py
# 4. Seed new fields (if needed)
python scripts/seed_database.py --fixtures fixtures/new_fields.json
Store fixtures in version control for consistency:
# Create fixtures directory
mkdir -p fixtures/{development,testing,staging}
# Generate and commit
python scripts/generate_fixtures.py \
--template elios-interview \
--output fixtures/development/base_data.json \
--pretty
git add fixtures/
git commit -m "Add base development fixtures"
For consistent test data, use Faker seeds:
from faker import Faker
# Set seed for reproducibility
Faker.seed(12345)
fake = Faker()
# Always generates same data
fake.name() # Always "John Smith" (example)
scripts/
├── seed_development.py # Small datasets for local dev
├── seed_testing.py # Controlled fixtures for tests
├── seed_staging.py # Large production-like datasets
└── seed_demo.py # Curated demo data
Ensure seeding can be run multiple times safely:
def seed_users(session, count=100):
# Check if already seeded
existing_count = session.query(User).count()
if existing_count >= count:
print(f"Already seeded with {existing_count} users, skipping...")
return
# Seed remaining
remaining = count - existing_count
# ... create users ...
# Batch insertions with progress
batch_size = 1000
for i in range(0, count, batch_size):
# ... create batch ...
print(f"Progress: {i}/{count} ({(i/count)*100:.1f}%)")
pip install faker)pip install sqlalchemy) - For PostgreSQL, MySQL, SQLitepip install psycopg2-binary) - PostgreSQL driverpip install pymysql) - MySQL driverpip install pymongo) - MongoDB driverpip install pyyaml) - For YAML config support# Install core dependencies
pip install faker pyyaml
# Install database drivers (choose based on your database)
pip install sqlalchemy psycopg2-binary # PostgreSQL
pip install sqlalchemy pymysql # MySQL
pip install pymongo # MongoDB
Error: Faker library not installed
Solution:
pip install faker
Error: connection refused
Solutions:
references/database-configs.md for detailed troubleshootingError: duplicate key value violates unique constraint
Solutions:
session.query(Model).delete()Error: foreign key constraint fails
Solutions:
created_users = [...]; post.author_id = random.choice([u.id for u in created_users])Error: MemoryError
Solutions:
session.flush() every N recordsCreate domain-specific providers:
from faker import Faker
from faker.providers import BaseProvider
class InterviewProvider(BaseProvider):
def interview_status(self):
return self.random_element(['pending', 'scheduled', 'completed', 'cancelled'])
def skill_level(self):
return self.random_element(['beginner', 'intermediate', 'advanced', 'expert'])
def programming_language(self):
return self.random_element(['Python', 'JavaScript', 'Java', 'C++', 'Go'])
fake = Faker()
fake.add_provider(InterviewProvider)
# Use custom methods
candidate = {
'skill_level': fake.skill_level(),
'primary_language': fake.programming_language(),
}
Generate international test data:
from faker import Faker
# Create multiple locales
fake_us = Faker('en_US')
fake_jp = Faker('ja_JP')
fake_fr = Faker('fr_FR')
users = [
{'name': fake_us.name(), 'address': fake_us.address()},
{'name': fake_jp.name(), 'address': fake_jp.address()},
{'name': fake_fr.name(), 'address': fake_fr.address()},
]
Handle complex relationships:
# One-to-Many
author = User(username=fake.user_name())
session.add(author)
session.flush() # Get author.id
posts = [
Post(title=fake.sentence(), author_id=author.id)
for _ in range(10)
]
session.add_all(posts)
# Many-to-Many
skills = [Skill(name=name) for name in ['Python', 'JavaScript', 'SQL']]
session.add_all(skills)
session.flush()
candidate = Candidate(full_name=fake.name())
candidate.skills.extend(random.sample(skills, k=2))
session.add(candidate)
session.commit()
# Generate Elios-specific fixtures
python scripts/generate_fixtures.py \
--template elios-interview \
--output fixtures/elios_dev.json \
--pretty
# Seed database
python scripts/seed_database.py \
--fixtures fixtures/elios_dev.json \
--db postgresql \
--connection "postgresql://postgres:password@localhost/elios_dev"
# Verify
psql -d elios_dev -c "SELECT COUNT(*) FROM candidates;"
psql -d elios_dev -c "SELECT COUNT(*) FROM questions;"
psql -d elios_dev -c "SELECT COUNT(*) FROM interview_sessions;"
# Generate small, controlled fixtures
python scripts/generate_fixtures.py \
--models Candidate:5,Question:10 \
--output tests/fixtures/ci_test_data.json \
--pretty
# In CI pipeline:
python scripts/seed_database.py \
--fixtures tests/fixtures/ci_test_data.json \
--db sqlite \
--connection "sqlite:///:memory:"
# Run tests with seeded data
pytest tests/
# Generate Vietnamese fixtures for Elios
python scripts/generate_fixtures.py \
--template elios-interview \
--locale vi_VN \
--output fixtures/elios_vietnamese.json \
--pretty
# Seed database
python scripts/seed_database.py \
--fixtures fixtures/elios_vietnamese.json \
--db postgresql \
--connection "postgresql://postgres:password@localhost/elios_dev"
# Verify Vietnamese data
psql -d elios_dev -c "SELECT full_name, education->>'university' as university FROM candidates LIMIT 5;"
Expected output:
full_name | university
-------------------------+-------------------------------
Nguyễn Văn Minh | Đại học Bách Khoa Hà Nội
Trần Thị Hương | Đại học FPT
Lê Minh Tuấn | Đại học Quốc gia Hà Nội
Phạm Thị Lan | Đại học Công nghệ
Hoàng Văn Nam | Đại học Bách Khoa TP.HCM
# scripts/seed_custom.py
from seed_database import create_seeder
from faker import Faker
fake = Faker()
def advanced_candidate_factory(fake, index):
"""Generate realistic interview candidates"""
skills_by_role = {
'frontend': ['JavaScript', 'React', 'CSS', 'HTML', 'Vue'],
'backend': ['Python', 'Django', 'FastAPI', 'SQL', 'Docker'],
'fullstack': ['JavaScript', 'React', 'Python', 'SQL', 'AWS'],
'data': ['Python', 'Pandas', 'SQL', 'Machine Learning', 'Statistics'],
}
role = fake.random_element(list(skills_by_role.keys()))
skills = fake.random_elements(
skills_by_role[role],
length=fake.random_int(min=3, max=5),
unique=True
)
return {
'full_name': fake.name(),
'email': fake.email(),
'phone': fake.phone_number(),
'years_of_experience': fake.random_int(min=0, max=15),
'skills': list(skills),
'desired_role': role,
'expected_salary': fake.random_int(min=50000, max=200000),
'created_at': fake.date_time_between(start_date='-6m', end_date='now'),
}
# Run seeding
seeder = create_seeder('postgresql', 'postgresql://user:pass@localhost/db')
candidates = seeder.seed_model(Candidate, count=100, factory_func=advanced_candidate_factory)
print(f"✓ Created {len(candidates)} candidates")
Add seeding to Docker Compose setup:
# docker-compose.yml
version: '3.8'
services:
postgres:
image: postgres:15
environment:
POSTGRES_DB: elios_dev
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
ports:
- "5432:5432"
seeder:
build: .
depends_on:
- postgres
environment:
DATABASE_URL: postgresql://postgres:password@postgres:5432/elios_dev
command: >
sh -c "
sleep 5 &&
python scripts/generate_fixtures.py --template elios-interview --output /tmp/fixtures.json &&
python scripts/seed_database.py --fixtures /tmp/fixtures.json --db postgresql --connection $$DATABASE_URL
"
# Makefile
.PHONY: seed seed-dev seed-test
seed-dev:
python scripts/generate_fixtures.py --template elios-interview --output fixtures/dev.json
python scripts/seed_database.py --fixtures fixtures/dev.json --db postgresql --connection $(DATABASE_URL)
seed-test:
python scripts/generate_fixtures.py --models Candidate:10,Question:20 --output tests/fixtures/test.json
python scripts/seed_database.py --fixtures tests/fixtures/test.json --db sqlite --connection "sqlite:///:memory:"
seed-staging:
python scripts/detect_db_config.py --env-file .env.staging
python scripts/seed_database.py --fixtures fixtures/staging.json --db postgresql --connection $(STAGING_DATABASE_URL)
Usage:
make seed-dev
make seed-test
make seed-staging
This skill provides a complete database seeding solution:
Use the skill whenever you need to populate databases with realistic test data efficiently.
xiaohongshu
technical spec
product ux expert
database patterns
Conduct multi-agent task orchestration and workflow coordination.
Initialize project with Conductor artifacts (product definition,
Expert in web animations, transitions, and motion design using Framer Motion and CSS
Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...
PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.
Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...
Display project status, active tracks, and next actions
Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience