Skip to main content
ff-serv includes a CLI tool (ff-serv) with database utilities for pulling and dumping PostgreSQL databases.

Installation

The CLI is available as ff-serv in your node_modules/.bin or via bun run.

Commands

db pull

Pull a database from a source and restore it to a target database.
Features:
  • Interactive prompts for configuration
  • Automatic schema introspection and truncation
  • Retry on failure
  • Save dump file for reuse
Options:
  • --fromDump <path>: Use an existing dump file instead of downloading
  • --saveDump <path>: Save the dump file to a specific location
  • --config <path>: Path to config file
Examples:
Interactive Flow:
  1. Source Selection: Choose source database (from config or manual input)
  2. Confirmation: Review source and target database details
  3. Dump: Downloads database dump to temp file
  4. Schema Review: Shows all tables that will be truncated
  5. Truncation: Confirms and truncates target database
  6. Restore: Restores data from dump file
  7. Cleanup: Optionally removes temp dump file

db dump

Dump a database to a SQL file.
Options:
  • --output <path> or -o <path>: Output file path (default: ./dump.sql)
  • --config <path>: Path to config file
Examples:

Configuration File

Create ff-serv.config.json to store database sources:
Schema:

Cloudflare R2 Source

Load dumps from Cloudflare R2:
Requires environment variables:

Complete Workflow

Setup

  1. Create config file:
ff-serv.config.json
  1. Pull database:
  1. Review the output:
  1. Confirm truncation:
  1. Wait for restore:

Error Handling

If an error occurs during pull:
  1. Dump file is preserved
  2. You’re prompted to retry
  3. Can resume with --fromDump flag

Use Cases

Daily Development Sync

Backup Before Migration

CI/CD Test Database

.github/workflows/test.yml

Implementation Details

The CLI uses:
  • @effect/cli for command parsing
  • inquirer for interactive prompts
  • postgres for database introspection
  • psql and pg_dump for dump/restore operations

Database Introspection

The CLI introspects schemas and tables to show what will be truncated:

Truncation

Uses TRUNCATE ... RESTART IDENTITY CASCADE:

Troubleshooting

Command not found: psql

Install PostgreSQL client tools:

Permission denied

Ensure target database user has permissions:

R2 authentication failed

Verify environment variables: