Skip to content

Commit 0574335

Browse files
committed
fix startup
1 parent 5fa826d commit 0574335

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

backend/app/core/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ def DATABASE_URL(self) -> str:
155155
f"postgresql+psycopg2://{self.DATABASE_USER}:"
156156
f"{self.DATABASE_PASSWORD}@{self.DATABASE_HOST}:"
157157
f"{self.DATABASE_PORT}/{self.DATABASE_NAME}"
158+
f"?connect_timeout=5"
158159
)
159160

160161
@property

backend/start.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
#!/bin/sh
22
set -e
33

4+
# Wait for database to be reachable before running migrations
5+
MAX_RETRIES=${DB_WAIT_RETRIES:-10}
6+
RETRY=0
7+
until python -c "import socket; s=socket.create_connection(('${DATABASE_HOST:-localhost}', ${DATABASE_PORT:-5432}), timeout=3); s.close()" 2>/dev/null; do
8+
RETRY=$((RETRY + 1))
9+
if [ "$RETRY" -ge "$MAX_RETRIES" ]; then
10+
echo "ERROR: Database not reachable after $MAX_RETRIES attempts. Exiting."
11+
exit 1
12+
fi
13+
echo "Waiting for database ($RETRY/$MAX_RETRIES)..."
14+
sleep 3
15+
done
16+
echo "Database is reachable."
17+
418
echo "Running Alembic migrations..."
519
alembic upgrade head
620
echo "Migrations complete."

0 commit comments

Comments
 (0)