3
3
4
4
[ ! -z " $DEBUG " ] && set -x
5
5
6
- # first argument should be '15' or '16' for the version
6
+ # Determine PostgreSQL version
7
7
if [ " $1 " == " 15" ]; then
8
8
echo " Starting client for PSQL 15"
9
9
PSQL15=@PSQL15_BINDIR@
20
20
echo " Please provide a valid Postgres version (15, 16, or orioledb-16)"
21
21
exit 1
22
22
fi
23
+
24
+ shift 1
25
+
23
26
# vars for migration.sh
24
27
export PATH=$BINDIR /bin:$PATH
25
28
export POSTGRES_DB=postgres
26
29
export POSTGRES_HOST=localhost
27
30
export POSTGRES_PORT=@PGSQL_DEFAULT_PORT@
31
+
32
+ # Optional second argument: path to custom migration script
33
+ if [ -n " $1 " ]; then
34
+ MIGRATION_FILE=" $1 "
35
+ else
36
+ MIGRATION_FILE=" "
37
+ fi
38
+
28
39
PORTNO=" ${2:-@ PGSQL_DEFAULT_PORT@ } "
29
40
PGSQL_SUPERUSER=@PGSQL_SUPERUSER@
30
41
MIGRATIONS_DIR=@MIGRATIONS_DIR@
@@ -35,20 +46,37 @@ psql -v ON_ERROR_STOP=1 --no-password --no-psqlrc -U "$PGSQL_SUPERUSER" -p "$POR
35
46
create role postgres superuser login password '$PGPASSWORD ';
36
47
alter database postgres owner to postgres;
37
48
EOSQL
38
- for sql in " $MIGRATIONS_DIR " /init-scripts/* .sql; do
39
- echo " $0 : running $sql "
40
- psql -v ON_ERROR_STOP=1 --no-password --no-psqlrc -U postgres -p " $PORTNO " -h localhost -f " $sql " postgres
41
- done
42
- psql -v ON_ERROR_STOP=1 --no-password --no-psqlrc -U postgres -p " $PORTNO " -h localhost -c " ALTER USER supabase_admin WITH PASSWORD '$PGPASSWORD '"
43
- psql -v ON_ERROR_STOP=1 --no-password --no-psqlrc -U postgres -p " $PORTNO " -h localhost -d postgres -f " $PGBOUNCER_AUTH_SCHEMA_SQL "
44
- psql -v ON_ERROR_STOP=1 --no-password --no-psqlrc -U postgres -p " $PORTNO " -h localhost -d postgres -f " $STAT_EXTENSION_SQL "
45
- # run migrations as super user - postgres user demoted in post-setup
46
- for sql in " $MIGRATIONS_DIR " /migrations/* .sql; do
47
- echo " $0 : running $sql "
48
- psql -v ON_ERROR_STOP=1 --no-password --no-psqlrc -U supabase_admin -p " $PORTNO " -h localhost -f " $sql " postgres
49
- done
50
- psql -v ON_ERROR_STOP=1 --no-password --no-psqlrc -U supabase_admin -p " $PORTNO " -h localhost -f " $POSTGRESQL_SCHEMA_SQL " postgres
51
- # TODO Do we need to reset stats when running migrations locally?
52
- # 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
53
49
50
+ # Use custom migration script if provided
51
+ if [ -n " $MIGRATION_FILE " ]; then
52
+ echo " $0 : running user-provided migration file $MIGRATION_FILE "
53
+ psql -v ON_ERROR_STOP=1 --no-password --no-psqlrc -U " $PGSQL_SUPERUSER " -p " $PORTNO " -h localhost -f " $MIGRATION_FILE " postgres
54
+ else
55
+ # Run default init scripts
56
+ for sql in " $MIGRATIONS_DIR " /init-scripts/* .sql; do
57
+ echo " $0 : running $sql "
58
+ psql -v ON_ERROR_STOP=1 --no-password --no-psqlrc -U postgres -p " $PORTNO " -h localhost -f " $sql " postgres
59
+ done
60
+
61
+ # Alter user password
62
+ psql -v ON_ERROR_STOP=1 --no-password --no-psqlrc -U postgres -p " $PORTNO " -h localhost -c " ALTER USER supabase_admin WITH PASSWORD '$PGPASSWORD '"
63
+
64
+ # Run additional schema files
65
+ psql -v ON_ERROR_STOP=1 --no-password --no-psqlrc -U postgres -p " $PORTNO " -h localhost -d postgres -f " $PGBOUNCER_AUTH_SCHEMA_SQL "
66
+ psql -v ON_ERROR_STOP=1 --no-password --no-psqlrc -U postgres -p " $PORTNO " -h localhost -d postgres -f " $STAT_EXTENSION_SQL "
67
+
68
+ # Run migrations as superuser
69
+ for sql in " $MIGRATIONS_DIR " /migrations/* .sql; do
70
+ echo " $0 : running $sql "
71
+ psql -v ON_ERROR_STOP=1 --no-password --no-psqlrc -U supabase_admin -p " $PORTNO " -h localhost -f " $sql " postgres
72
+ done
73
+
74
+ # Run PostgreSQL schema
75
+ psql -v ON_ERROR_STOP=1 --no-password --no-psqlrc -U supabase_admin -p " $PORTNO " -h localhost -f " $POSTGRESQL_SCHEMA_SQL " postgres
76
+ fi
77
+
78
+ # Optional: Reset stats if needed
79
+ # 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
80
+
81
+ # Start interactive psql session
54
82
exec psql -U postgres -p " $PORTNO " -h localhost postgres
0 commit comments