04f5786cf6
psql doesn't understand ?schema=public in the DATABASE_URL. Strip query parameters before passing to psql for RLS, collation, and search index scripts. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
49 lines
1.3 KiB
Bash
49 lines
1.3 KiB
Bash
#!/bin/sh
|
|
set -e
|
|
|
|
echo "Waiting for database..."
|
|
MAX_RETRIES=30
|
|
RETRY=0
|
|
|
|
while [ $RETRY -lt $MAX_RETRIES ]; do
|
|
if npx prisma db push --skip-generate 2>&1; then
|
|
echo "Database schema synced successfully."
|
|
break
|
|
fi
|
|
RETRY=$((RETRY + 1))
|
|
echo "Database not ready (attempt $RETRY/$MAX_RETRIES), retrying in 3s..."
|
|
sleep 3
|
|
done
|
|
|
|
if [ $RETRY -ge $MAX_RETRIES ]; then
|
|
echo "ERROR: Could not connect to database after $MAX_RETRIES attempts."
|
|
exit 1
|
|
fi
|
|
|
|
# Strip Prisma-specific query params (e.g. ?schema=public) that psql doesn't understand
|
|
PSQL_URL="${DATABASE_URL%%\?*}"
|
|
|
|
echo "Applying position column collation fix..."
|
|
if psql "$PSQL_URL" -f ./scripts/setup-collation.sql; then
|
|
echo "Collation fix applied successfully."
|
|
else
|
|
echo "WARNING: Failed to apply collation fix. Continuing anyway..."
|
|
fi
|
|
|
|
echo "Applying RLS policies..."
|
|
if psql "$PSQL_URL" -f ./scripts/setup-rls.sql; then
|
|
echo "RLS policies applied successfully."
|
|
else
|
|
echo "WARNING: Failed to apply RLS policies. Continuing anyway..."
|
|
fi
|
|
|
|
echo "Applying full-text search indexes..."
|
|
if psql "$PSQL_URL" -f ./scripts/setup-search.sql; then
|
|
echo "Search indexes applied successfully."
|
|
else
|
|
echo "WARNING: Failed to apply search indexes. Continuing anyway..."
|
|
fi
|
|
|
|
echo "Starting server..."
|
|
exec node server.js
|