Supabase Migration Tools

Tools for migrating databases and storage buckets between Supabase instances.

Features

  • Database migration with schema and data backup/restore
  • Storage bucket migration with automatic retry and progress bars
  • Connection testing and validation
  • Support for both cloud and self-hosted Supabase instances

Prerequisites

  • Node.js (for storage migration)
  • Supabase CLI (for database migration)
  • PostgreSQL client (psql)

Setup

  1. Install dependencies:
npm install
  1. Copy the environment example file:
cp .env.example .env.local
  1. Update .env.local with your configuration:
    • For storage migration: Set SOURCE_HOST, TARGET_HOST, and their respective service role keys
    • For database migration: Set database connection details for both source and target

Usage

Database Migration

The database migration script will:

  • Backup roles, schema, and data from the source database
  • Restore to the target database with options for selective restore
npm run migrate-db
# or directly
bash supabase_migration.sh

Storage Migration

The storage migration script will:

  • List and copy all buckets from source to target
  • Show progress bars for downloads and uploads
  • Automatically retry failed transfers
  • Generate a detailed migration report
npm run migrate-storage
# or directly
node storage_migration.js

Environment Variables

Storage Migration

  • SOURCE_HOST: Source Supabase project URL
  • SOURCE_SERVICE_ROLE_KEY: Source project's service role key
  • TARGET_HOST: Target Supabase URL
  • TARGET_SERVICE_ROLE_KEY: Target project's service role key

Database Migration

  • SOURCE_DB_HOST: Source database host (with 'db.' prefix)
  • SOURCE_USERNAME: Source database username
  • SOURCE_DBNAME: Source database name
  • SOURCE_PASSWORD: Source database password
  • SOURCE_PORT: Source database port
  • TARGET_DB_HOST: Target database host
  • TARGET_USER: Target database username
  • TARGET_DBNAME: Target database name
  • TARGET_PASSWORD: Target database password
  • TARGET_PORT: Target database port

Notes

  • For database migration using a remote target, you can use SSH tunneling:

    ssh -L 5432:localhost:5432 user@your-server

    Then use localhost as your TARGET_DB_HOST

  • For local Supabase instances, use localhost:5432 as your target database host

License

MIT