freshyo/apps/migrator/README.md
2026-03-23 10:57:28 +05:30

1.4 KiB

Migrator

Data-only migration tool between Postgres and SQLite using Drizzle.

What it does

  • Copies data from source to target
  • Does NOT create or alter tables
  • Overwrites target data if any rows exist (via DELETE FROM in dependency-safe order)

Requirements

  • Tables must already exist on the target database
  • Schema must match the backend Drizzle schemas

Usage

Run from repo root:

bun --cwd apps/migrator run migrate --from postgres --to sqlite --source "<PG_URL>" --target "<SQLITE_PATH>"
bun --cwd apps/migrator run migrate --from sqlite --to postgres --source "<SQLITE_PATH>" --target "<PG_URL>"

Flags

  • --from: postgres or sqlite
  • --to: postgres or sqlite
  • --source: Postgres connection string or SQLite file path
  • --target: Postgres connection string or SQLite file path
  • --batch: optional batch size (default: 500)

Examples

bun --cwd apps/migrator run migrate \
  --from postgres \
  --to sqlite \
  --source "postgres://user:pass@host:5432/db" \
  --target "./sqlite.db"
bun --cwd apps/migrator run migrate \
  --from sqlite \
  --to postgres \
  --source "./sqlite.db" \
  --target "postgres://user:pass@host:5432/db" \
  --batch 1000

Notes

  • IDs are copied as-is to preserve relationships.
  • For Postgres targets, sequences may need manual reset after import.