|
| 1 | +#!/usr/bin/env bash |
| 2 | +# shellcheck shell
D7AE
=bash |
| 3 | + |
| 4 | +[ ! -z "$DEBUG" ] && set -x |
| 5 | + |
| 6 | +# first argument should be '15' or '16' for the version |
| 7 | +if [ "$1" == "15" ]; then |
| 8 | + echo "Starting client for PSQL 15" |
| 9 | + PSQL15=@PSQL15_BINDIR@ |
| 10 | + BINDIR="$PSQL15" |
| 11 | +elif [ "$1" == "16" ]; then |
| 12 | + echo "Starting client for PSQL 16" |
| 13 | + PSQL16=@PSQL16_BINDIR@ |
| 14 | + BINDIR="$PSQL16" |
| 15 | +elif [ "$1" == "orioledb-16" ]; then |
| 16 | + echo "Starting client for PSQL ORIOLEDB 16" |
| 17 | + PSQLORIOLEDB16=@PSQLORIOLEDB16_BINDIR@ |
| 18 | + BINDIR="$PSQLORIOLEDB16" |
| 19 | +else |
| 20 | + echo "Please provide a valid Postgres version (15, 16, or orioledb-16)" |
| 21 | + exit 1 |
| 22 | +fi |
| 23 | +#vars for migration.sh |
| 24 | +export PATH=$BINDIR/bin:$PATH |
| 25 | +export POSTGRES_DB=postgres |
| 26 | +export POSTGRES_HOST=localhost |
| 27 | +export POSTGRES_PORT=@PGSQL_DEFAULT_PORT@ |
| 28 | +PORTNO="${2:-@PGSQL_DEFAULT_PORT@}" |
| 29 | +PGSQL_SUPERUSER=@PGSQL_SUPERUSER@ |
| 30 | +MIGRATIONS_DIR=@MIGRATIONS_DIR@ |
| 31 | +POSTGRESQL_SCHEMA_SQL=@POSTGRESQL_SCHEMA_SQL@ |
| 32 | +PGBOUNCER_AUTH_SCHEMA_SQL=@PGBOUNCER_AUTH_SCHEMA_SQL@ |
| 33 | +STAT_EXTENSION_SQL=@STAT_EXTENSION_SQL@ |
| 34 | +psql -v ON_ERROR_STOP=1 --no-password --no-psqlrc -U "$PGSQL_SUPERUSER" -p "$PORTNO" -h localhost -d postgres -f "$PGBOUNCER_AUTH_SCHEMA_SQL" |
| 35 | +psql -v ON_ERROR_STOP=1 --no-password --no-psqlrc -U "$PGSQL_SUPERUSER" -p "$PORTNO" -h localhost -d postgres -f "$STAT_EXTENSION_SQL" |
| 36 | +for sql in "$MIGRATIONS_DIR"/init-scripts/*.sql; do |
| 37 | + echo "$0: running $sql" |
| 38 | + psql -v ON_ERROR_STOP=1 --no-password --no-psqlrc -U postgres -p "$PORTNO" -h localhost -f "$sql" postgres |
| 39 | +done |
| 40 | +psql -v ON_ERROR_STOP=1 --no-password --no-psqlrc -U postgres -p "$PORTNO" -h localhost -c "ALTER USER supabase_admin WITH PASSWORD '$PGPASSWORD'" |
| 41 | +# run migrations as super user - postgres user demoted in post-setup |
| 42 | +for sql in "$MIGRATIONS_DIR"/migrations/*.sql; do |
| 43 | + echo "$0: running $sql" |
| 44 | + psql -v ON_ERROR_STOP=1 --no-password --no-psqlrc -U supabase_admin -p "$PORTNO" -h localhost -f "$sql" postgres |
| 45 | +done |
| 46 | +psql -v ON_ERROR_STOP=1 --no-password --no-psqlrc -U supabase_admin -p "$PORTNO" -h localhost -f "$POSTGRESQL_SCHEMA_SQL" postgres |
| 47 | +# TODO Do we need to reset stats when running migrations locally? |
| 48 | +#psql -v ON_ERROR_STOP=1 --no-password --no-psqlrc -U supabase_admin -p "$PORTNO" -h localhost -c 'SELECT extensions.pg_stat_statements_reset(); SELECT pg_stat_reset();' postgres || true |
| 49 | + |
| 50 | +exec psql -U "$PGSQL_SUPERUSER" -p "$PORTNO" -h localhost postgres |
0 commit comments