Loading Fixtures Overview
Real Data
Production data Realistic testing
Auto Relation Resolution
Auto BelongsTo tracking Related data together
Duplicate Prevention
ID-based management Safe import
Simple Command
One-line execution Auto sync
pnpm sonamu fixture import
Import specific records from production DB to Fixture DB.Basic Usage
entityId: Entity name (e.g., “User”, “Post”)recordIds: Array of record IDs to import (comma-separated)
Examples
How It Works
1. Record Extraction
2. Auto Relation Tracking
Automatically tracks BelongsTo relations to import all necessary data.3. Auto Sync
Afterimport, Fixture DB → Test DB sync is automatically executed.
Execution Examples
Import Users
Import Posts
Complex Relation Handling
HasMany Relations
ManyToMany Relations
Duplicate Handling
UsesINSERT IGNORE to prevent duplicates.
Circular Reference Prevention
Tracks visited records to prevent circular references.Best Practices
1. Minimal Data
2. Representative Cases
3. Use with fixture.ts
Troubleshooting
Record Not Found
- Verify the ID exists in production DB
- Use correct Entity name
Permission Error
Too Much Data
Cautions
Next Steps
Test DB
Test DB setup
Creating Fixtures
Writing fixture.ts
Syncing Fixtures
Fixture → Test DB
Writing Tests
Understanding test structure