Tools for migrating databases and storage buckets between Supabase instances.
- 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
- Node.js (for storage migration)
- Supabase CLI (for database migration)
- PostgreSQL client (psql)
- Install dependencies:
npm install- Copy the environment example file:
cp .env.example .env.local- Update
.env.localwith 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
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.shThe 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.jsSOURCE_HOST: Source Supabase project URLSOURCE_SERVICE_ROLE_KEY: Source project's service role keyTARGET_HOST: Target Supabase URLTARGET_SERVICE_ROLE_KEY: Target project's service role key
SOURCE_DB_HOST: Source database host (with 'db.' prefix)SOURCE_USERNAME: Source database usernameSOURCE_DBNAME: Source database nameSOURCE_PASSWORD: Source database passwordSOURCE_PORT: Source database portTARGET_DB_HOST: Target database hostTARGET_USER: Target database usernameTARGET_DBNAME: Target database nameTARGET_PASSWORD: Target database passwordTARGET_PORT: Target database port
-
For database migration using a remote target, you can use SSH tunneling:
ssh -L 5432:localhost:5432 user@your-server
Then use
localhostas your TARGET_DB_HOST -
For local Supabase instances, use
localhost:5432as your target database host