@@ -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