Skip to main content
Learn how to import actual production data to Fixture DB for use in tests.

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

Parameters:
  • 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.
Internal operation:

3. Auto Sync

After import, Fixture DB → Test DB sync is automatically executed.

Execution Examples

Import Users

Import Posts

Complex Relation Handling

HasMany Relations

ManyToMany Relations

Duplicate Handling

Uses INSERT 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

Solution:
  • Verify the ID exists in production DB
  • Use correct Entity name

Permission Error

Solution:

Too Much Data

Cautions

Cautions when loading fixtures: 1. Minimal data: Import only minimum necessary records 2. Check relations: BelongsTo is automatic, HasMany is manual 3. Duplicate safe: INSERT IGNORE prevents duplicates 4. Circular references: Handled automatically 5. Check permissions: Write permission needed for Fixture DB

Next Steps

Test DB

Test DB setup

Creating Fixtures

Writing fixture.ts

Syncing Fixtures

Fixture → Test DB

Writing Tests

Understanding test structure