From 009d56f3c131b379da36411eb78efc8fbab8ba44 Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Mon, 21 Apr 2025 14:50:30 -0400 Subject: [PATCH] docs: update docs and some of the scripts that run them --- flake.nix | 1 + migrations/README.md | 12 ++++++++---- nix/tools/dbmate-tool.sh.in | 9 ++++++++- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/flake.nix b/flake.nix index a0a347760..f3564df71 100644 --- a/flake.nix +++ b/flake.nix @@ -951,6 +951,7 @@ ]; shellHook = '' export HISTFILE=.history + export DATABASE_URL="postgres://supabase_admin@localhost:5435/postgres?sslmode=disable" ''; }; cargo-pgrx_0_11_3 = mkCargoPgrxDevShell { diff --git a/migrations/README.md b/migrations/README.md index ffe18a0b5..7cb439df8 100644 --- a/migrations/README.md +++ b/migrations/README.md @@ -85,12 +85,16 @@ First, start a local postgres server in another terminal window: nix run .#start-server 15 ``` -Then, in your main terminal window: +Then, in your main terminal window, run: ```shell -# Set up the database URL for migrations -export DATABASE_URL="postgres://supabase_admin@localhost:5435/postgres?sslmode=disable" +nix develop +``` +in the root of `supabase/postgres`. + +Next run: +``` shell # Create a new migration (make sure to specify the migrations directory) dbmate --migrations-dir="migrations/db/migrations" new '' ``` @@ -98,7 +102,7 @@ dbmate --migrations-dir="migrations/db/migrations" new '' Then, execute the migration at `./migrations/db/xxxxxxxxx_` and make sure it runs successfully with: ```shell -dbmate up +dbmate --no-dump-schema --migrations-dir"migrations/db/migrations" up ``` Note: Migrations are applied using the `supabase_admin` superuser role, as specified in the "How it was Created" section above. diff --git a/nix/tools/dbmate-tool.sh.in b/nix/tools/dbmate-tool.sh.in index fe3f524b7..ca38f3ac1 100644 --- a/nix/tools/dbmate-tool.sh.in +++ b/nix/tools/dbmate-tool.sh.in @@ -189,8 +189,15 @@ perform_dump() { while [ $attempt -le $max_attempts ]; do echo "Attempting dbmate dump (attempt $attempt/$max_attempts)" + # Run dbmate dump if dbmate dump; then - return 0 + # Post-process schema.sql to remove schema_migrations INSERT statements + if [ -f "db/schema.sql" ]; then + # Remove INSERT INTO schema_migrations lines + sed -i '/^INSERT INTO schema_migrations/d' db/schema.sql + echo "Schema dump completed successfully (schema_migrations data removed)" + return 0 + fi fi echo "Dump attempt $attempt failed, waiting before retry..."