Skip to main content
Learn how to sync Fixture DB data to Test DB to prepare the test environment.

Fixture Sync Overview

Complete Copy

All data Schema + Records

Clean Start

Test DB initialization Consistent environment

Fast Execution

pg_dump + pg_restore Efficient copy

Auto Execution

Auto after import Manual also available

pnpm sonamu fixture sync

Copies all data from Fixture DB to Test DB.

Basic Usage

This command:
  1. Completely initializes Test DB
  2. Dumps Fixture DB
  3. Restores to Test DB

How It Works

Internal Implementation

Execution Process

Usage Scenarios

1. After Fixture Changes

2. Test DB Initialization

3. Team Synchronization

Database Comparison

pg_dump Options

-Fc (Format Custom)

Dumps in binary format for speed and efficiency.
Benefits:
  • Compressed, smaller size
  • Selective restore possible with pg_restore
  • Fast speed

—no-owner —no-acl

Excludes owner and permission information.
Reason:
  • Users may differ between local and remote
  • Prevents permission conflicts

Auto vs Manual

Auto Sync

Sync is automatically called when running pnpm sonamu fixture import:

Manual Sync

Run directly when needed:

Workflow

Typical Development Flow

Fixture Sharing Flow

Performance Optimization

1. Local Fixture DB

Sync is faster when running Fixture DB locally:

2. Minimal Data

Keep only necessary data in Fixture:

Best Practices

1. Regular Sync

2. CI/CD Integration

3. Add Scripts

Troubleshooting

Connection Failed

Solution:
  • Check network connection
  • Check Fixture DB server status
  • Check firewall settings

Permission Error

Solution:

DB In Use

Solution:
Or:

Cautions

Cautions when syncing fixtures: 1. Test DB initialization: All existing data will be deleted 2. Permissions required: DROP/CREATE permissions for Test DB 3. Connection termination: Will fail if tests are running 4. Network: Takes time if Fixture DB is remote 5. Data size: Sync is slow if Fixture is large

Next Steps

Test DB

Test DB setup

Creating Fixtures

Writing fixture.ts

Loading Fixtures

Import production data

Writing Tests

Understanding test structure