-
-
Notifications
You must be signed in to change notification settings - Fork 174
/
Copy pathrun-client.sh.in
107 lines (99 loc) · 3.17 KB
/
run-client.sh.in
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/env bash
# shellcheck shell=bash
[ ! -z "$DEBUG" ] && set -x
# Default values
PSQL_VERSION="15"
PORTNO="@PGSQL_DEFAULT_PORT@"
PSQL_USER="postgres"
# Function to display help
print_help() {
echo "Usage: nix run .#start-client -- [options]"
echo
echo "Options:"
echo " -v, --version [15|16|orioledb-16] Specify the PostgreSQL version to use (required)"
echo " -u, --user USER Specify the user/role to use (default: postgres)"
echo " -h, --help Show this help message"
echo
echo "Description:"
echo " Starts an interactive 'psql' session connecting to a Postgres database started with the"
echo " 'nix run .#start-server' command. If a migration file is not provided, the client"
echo " initializes the database with the default migrations for a new Supabase project."
echo " If a migrations file is provided, default migrations are skipped"
echo " If no migration file is provided, it runs the default Supabase migrations."
echo
echo "Examples:"
echo " nix run .#start-client"
echo " nix run .#start-client -- --version 15"
echo " nix run .#start-client -- --version 16 --port 5433"
echo " nix run .#start-client -- --version 16 --user supabase_admin"
}
# Parse arguments
while [[ "$#" -gt 0 ]]; do
case "$1" in
-v|--version)
if [[ -n "$2" && ! "$2" =~ ^- ]]; then
PSQL_VERSION="$2"
shift 2
else
echo "Error: --version requires an argument (15, 16, or orioledb-16)"
exit 1
fi
;;
-u|--user)
if [[ -n "$2" && ! "$2" =~ ^- ]]; then
PSQL_USER="$2"
shift 2
else
echo "Error: --user requires an argument"
exit 1
fi
;;
-p|--port)
if [[ -n "$2" && ! "$2" =~ ^- ]]; then
PORTNO="$2"
shift 2
else
echo "Error: --port requires an argument"
exit 1
fi
;;
-h|--help)
print_help
exit 0
;;
*)
echo "Unknown option: $1"
print_help
exit 1
;;
esac
done
# Check if version is provided
if [[ -z "$PSQL_VERSION" ]]; then
echo "Error: PostgreSQL version is required."
print_help
exit 1
fi
# Determine PostgreSQL version
if [ "$PSQL_VERSION" == "15" ]; then
echo "Starting client for PSQL 15"
PSQL15=@PSQL15_BINDIR@
BINDIR="$PSQL15"
elif [ "$PSQL_VERSION" == "17" ]; then
echo "Starting client for PSQL 17"
PSQL17=@PSQL17_BINDIR@
BINDIR="$PSQL17"
elif [ "$PSQL_VERSION" == "orioledb-17" ]; then
echo "Starting client for PSQL ORIOLEDB 17"
PSQLORIOLEDB17=@PSQLORIOLEDB17_BINDIR@
BINDIR="$PSQLORIOLEDB17"
else
echo "Please provide a valid Postgres version (15, 17, or orioledb-17)"
exit 1
fi
#vars for migration.sh
export PATH=$BINDIR/bin:$PATH
export POSTGRES_DB=postgres
export POSTGRES_HOST=localhost
# Start interactive psql session
exec psql -U "$PSQL_USER" -p "$PORTNO" -h localhost postgres