Skip to content

Instantly share code, notes, and snippets.

@myagizmaktav
Last active January 28, 2024 10:18
Show Gist options
  • Select an option

  • Save myagizmaktav/c63ae604377fbe237fc21b118a068da1 to your computer and use it in GitHub Desktop.

Select an option

Save myagizmaktav/c63ae604377fbe237fc21b118a068da1 to your computer and use it in GitHub Desktop.
Supabase Local To Local Server Migration
DB URL: postgresql://postgres:[email protected]:54322/postgres
Local pc:
npx supabase migration new mig
supabe migration new mig
supabase db diff -f initial_migration
supabase db dump --db-url "$OLD_DB_URL" -f roles.sql --role-only
supabase db dump --db-url "$OLD_DB_URL" -f schema.sql
supabase db dump --db-url "$OLD_DB_URL" -f data.sql --use-copy --data-only
After created files transfer to server pc
Server pc:
# first migration file should be inside migration file on supabase init folder.
supabase supabase migration up --db-url $NEW_DB_URL
# docker container name like that: public.ecr.aws/supabase/postgres:15.1.0.147 "sh -c 'cat <<'EOF' …" 45 minutes ago Up 45 minutes (healthy) 0.0.0.0:54322->5432/tcp, :::54322->5432/tcp
# Copy paste to inside postgress container
sudo docker cp $(pwd)/roles.sql <containername>:./roles.sql
# exec to file for import
sudo docker exec -it <containername> psql -U postgres -f ./roles.sql
# delete copy from inside docker for disk place
sudo docker exec -it <containername> rm -r ./roles.sql
sudo docker cp $(pwd)/schema.sql <containername>:./schema.sql
sudo docker exec -it <containername> psql -U postgres -f ./schema.sql
sudo docker exec -it <containername> rm -r ./schema.sql
sudo docker cp $(pwd)/data.sql <containername>:./data.sql
sudo docker exec -it <containername> psql -U postgres -f ./data.sql
sudo docker exec -it <containername> rm -r ./data.sql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment