|
3 | 3 |
|
4 | 4 | echo " ProStaff API - Starting..." |
5 | 5 |
|
6 | | -# Fix DATABASE_URL if it has unescaped special characters in password |
7 | | -if [ -n "$DATABASE_URL" ]; then |
8 | | - echo " Checking DATABASE_URL format..." |
9 | | - |
10 | | - # Extract components - match everything after last @ as host part |
11 | | - # Format: postgresql://user:pass@host:port/db |
12 | | - if [[ "$DATABASE_URL" =~ ^([^:]+)://([^:]+):(.+)@([^@/]+.*) ]]; then |
13 | | - scheme="${BASH_REMATCH[1]}" |
14 | | - user="${BASH_REMATCH[2]}" |
15 | | - pass="${BASH_REMATCH[3]}" |
16 | | - rest="${BASH_REMATCH[4]}" # host:port/database |
17 | | - |
18 | | - # URL-encode the password using Python |
19 | | - # Escape single quotes and backslashes for safe Python execution |
20 | | - safe_pass=$(printf '%s' "$pass" | sed "s/\\\\/\\\\\\\\/g; s/'/\\\\'/g") |
21 | | - encoded_pass=$(python3 -c "import urllib.parse; print(urllib.parse.quote('''$safe_pass''', safe=''))") |
22 | | - |
23 | | - # Reconstruct DATABASE_URL with encoded password |
24 | | - export DATABASE_URL="${scheme}://${user}:${encoded_pass}@${rest}" |
25 | | - echo " DATABASE_URL password URL-encoded" |
26 | | - else |
27 | | - echo " DATABASE_URL format not recognized, using as-is" |
28 | | - fi |
29 | | -fi |
| 6 | +# Skip DATABASE_URL encoding - handled by Rails initializer |
| 7 | +# The initializer (config/initializers/database_url_override.rb) will detect |
| 8 | +# special characters and parse manually in database.yml |
| 9 | +echo " Database configuration will be handled by Rails initializer" |
30 | 10 |
|
31 | 11 | # Remove any pre-existing server PID file |
32 | 12 | rm -f /app/tmp/pids/server.pid |
33 | 13 |
|
34 | 14 | # Wait for database to be ready |
35 | 15 | echo " Waiting for database..." |
36 | | -if [ -n "$DATABASE_URL" ]; then |
37 | | - until pg_isready -d "$DATABASE_URL"; do |
| 16 | +# Use SUPABASE_DB_URL or DATABASE_URL, extract host for pg_isready |
| 17 | +DB_URL="${SUPABASE_DB_URL:-$DATABASE_URL}" |
| 18 | +if [ -n "$DB_URL" ]; then |
| 19 | + # Extract host and port from URL (format: postgresql://user:pass@host:port/db) |
| 20 | + # Parse from right to left to handle @ in password |
| 21 | + DB_HOST=$(echo "$DB_URL" | sed -E 's|.*@([^@/]+):[0-9]+/.*|\1|') |
| 22 | + DB_PORT=$(echo "$DB_URL" | sed -E 's|.*@[^@/]+:([0-9]+)/.*|\1|') |
| 23 | + |
| 24 | + echo " Checking connection to ${DB_HOST}:${DB_PORT}..." |
| 25 | + until pg_isready -h "$DB_HOST" -p "$DB_PORT" > /dev/null 2>&1; do |
38 | 26 | echo " Database is unavailable - sleeping" |
39 | 27 | sleep 2 |
40 | 28 | done |
|
62 | 50 |
|
63 | 51 | echo " Application ready!" |
64 | 52 |
|
65 | | -# Execute the main command with modified environment |
66 | | -if [ -n "$DATABASE_URL" ]; then |
67 | | - # Export for child processes |
68 | | - export DATABASE_URL |
69 | | -fi |
| 53 | +echo " Starting application server..." |
70 | 54 |
|
| 55 | +# Execute the main command |
71 | 56 | exec "$@" |
0 commit comments