Skip to content

Commit 14e8969

Browse files
committed
update dbmate to use the local flake for checking version to gen for
1 parent 50fef18 commit 14e8969

3 files changed

Lines changed: 31 additions & 12 deletions

File tree

migrations/README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ from the root of the `supabase/postgres` project, you can run the following comm
77
Usage: nix run .#dbmate-tool -- [options]
88

99
Options:
10-
-v, --version [15|16|orioledb-17|all] Specify the PostgreSQL version to use (required defaults to --version all)
10+
-v, --version [15|17|18|orioledb-17|all] Specify the PostgreSQL version to use (defaults to all)
1111
-p, --port PORT Specify the port number to use (default: 5435)
12+
-u, --user USER Specify the PostgreSQL user to use (default: postgres)
1213
-h, --help Show this help message
14+
-f, --flake-url URL Specify the flake URL to use (default: current repo if available, otherwise github:supabase/postgres)
1315

1416
Description:
1517
Runs 'dbmate up' against a locally running the version of database you specify. Or 'all' to run against all versions.
@@ -18,7 +20,7 @@ Description:
1820
Examples:
1921
nix run .#dbmate-tool
2022
nix run .#dbmate-tool -- --version 15
21-
nix run .#dbmate-tool -- --version 16 --port 5433
23+
nix run .#dbmate-tool -- --version 18 --port 5433
2224

2325
```
2426
@@ -29,7 +31,7 @@ nix run github:supabase/postgres#dbmate-tool -- --version 15
2931

3032
or
3133

32-
nix run github:supabase/postgres/mybranch#dbmate-tool -- --version 15
34+
nix run github:supabase/postgres/mybranch#dbmate-tool -- --version 18
3335
```
3436
# supabase/migrations
3537

migrations/schema-18.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
\restrict SupabaseTestDumpKey123
66

7-
-- Dumped from database version 17.6
8-
-- Dumped by pg_dump version 17.6
7+
-- Dumped from database version 18.3
8+
-- Dumped by pg_dump version 18.3
99

1010
SET statement_timeout = 0;
1111
SET lock_timeout = 0;

nix/packages/dbmate-tool.nix

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,31 @@ writeShellApplication {
2525
];
2626
text = ''
2727
# Default values
28-
PSQL_VERSION="ALL"
28+
PSQL_VERSION="all"
2929
PORTNO="${defaults.port}"
3030
PGSQL_SUPERUSER="${defaults.superuser}"
3131
PGPASSWORD="''${PGPASSWORD:-postgres}"
3232
PGSQL_USER="postgres"
33-
FLAKE_URL="github:supabase/postgres"
33+
DEFAULT_FLAKE_URL="github:supabase/postgres"
34+
FLAKE_URL=""
3435
MIGRATIONS_DIR="${migrationsDir}"
3536
CURRENT_SYSTEM="${system}"
3637
ANSIBLE_VARS="${ansibleVars}"
3738
PGBOUNCER_AUTH_SCHEMA_SQL="${pgbouncerAuthSchemaSql}"
3839
STAT_EXTENSION_SQL="${statExtensionSql}"
3940
41+
resolve_flake_url() {
42+
if [ -n "$FLAKE_URL" ]; then
43+
return
44+
fi
45+
46+
if [ -f "./flake.nix" ]; then
47+
FLAKE_URL="."
48+
else
49+
FLAKE_URL="$DEFAULT_FLAKE_URL"
50+
fi
51+
}
52+
4053
# Start PostgreSQL using nix
4154
start_postgres() {
4255
DATDIR=$(mktemp -d)
@@ -82,19 +95,20 @@ writeShellApplication {
8295
echo "Usage: nix run .#dbmate-tool -- [options]"
8396
echo
8497
echo "Options:"
85-
echo " -v, --version [15|17|18|orioledb-17|all] Specify the PostgreSQL version to use (required defaults to --version all)"
98+
echo " -v, --version [15|17|18|orioledb-17|all] Specify the PostgreSQL version to use (defaults to all)"
8699
echo " -p, --port PORT Specify the port number to use (default: 5435)"
100+
echo " -u, --user USER Specify the PostgreSQL user to use (default: postgres)"
87101
echo " -h, --help Show this help message"
88-
echo " -f, --flake-url URL Specify the flake URL to use (default: github:supabase/postgres)"
102+
echo " -f, --flake-url URL Specify the flake URL to use (default: current repo if available, otherwise github:supabase/postgres)"
89103
echo "Description:"
90104
echo " Runs 'dbmate up' against a locally running the version of database you specify. Or 'all' to run against all versions."
91105
echo " NOTE: To create a migration, you must run 'nix develop' and then 'dbmate new <migration_name>' to create a new migration file."
92106
echo
93107
echo "Examples:"
94108
echo " nix run .#dbmate-tool"
95109
echo " nix run .#dbmate-tool -- --version 15"
96-
echo " nix run .#dbmate-tool -- --version 16 --port 5433"
97-
echo " nix run .#dbmate-tool -- --version 16 --port 5433 --flake-url github:supabase/postgres/<commithash>"
110+
echo " nix run .#dbmate-tool -- --version 18 --port 5433"
111+
echo " nix run .#dbmate-tool -- --version 18 --port 5433 --flake-url github:supabase/postgres/<commithash>"
98112
}
99113
100114
# Parse arguments
@@ -105,7 +119,7 @@ writeShellApplication {
105119
PSQL_VERSION="$2"
106120
shift 2
107121
else
108-
echo "Error: --version requires an argument (15, 16, or orioledb-17)"
122+
echo "Error: --version requires an argument (15, 17, 18, or orioledb-17)"
109123
exit 1
110124
fi
111125
;;
@@ -148,6 +162,8 @@ writeShellApplication {
148162
esac
149163
done
150164
165+
resolve_flake_url
166+
151167
# Function to wait for PostgreSQL to be ready
152168
wait_for_postgres() {
153169
local max_attempts=30 # Increased significantly
@@ -227,6 +243,7 @@ writeShellApplication {
227243
228244
migrate_version() {
229245
echo "PSQL_VERSION: $PSQL_VERSION"
246+
echo "Using flake URL: $FLAKE_URL"
230247
#pkill -f "postgres" || true # Ensure PostgreSQL is stopped before starting
231248
PSQLBIN=$(nix build --no-link "$FLAKE_URL#psql_$PSQL_VERSION/bin" --json | jq -r '.[].outputs.out + "/bin"')
232249
echo "Using PostgreSQL version $PSQL_VERSION from $PSQLBIN"

0 commit comments

Comments
 (0)