supabase-postgres.git / summary / log / commit / refs
commit dd2363e180a4b0db8bb211dc50f43ad52a00d4df
Author: samrose <samuel@supabase.io>
Commit: GitHub <noreply@github.com>
Date: Mon Apr 21 23:25:56 2025 +0000
docs: update docs and some of the scripts that run them (#1560)
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 a0a34776..f3564df7 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 ffe18a0b..7cb439df 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 '<some message>'
```
@@ -98,7 +102,7 @@ dbmate --migrations-dir="migrations/db/migrations" new '<some message>'
Then, execute the migration at `./migrations/db/xxxxxxxxx_<some_message>` 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 fe3f524b..ca38f3ac 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..."
[parent: 057221788a3e]