fix: replace psql with Python for DB checks (no apt-get needed!)
Deploy Development / deploy (push) Failing after 3s
Build Test / lint-backend (push) Successful in 0s
Build Test / build-frontend (push) Successful in 31s

- Remove postgresql-client installation (causes 150s+ hangs due to network)
- Add db_init.py: Pure Python PostgreSQL checks using psycopg2-binary
- Simplify startup.sh: Call Python script instead of psql commands
- Build should now complete in <30s instead of hanging

This fixes the deployment timeout issue by avoiding APT network problems entirely.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
LarsandClaude Opus 4.6 committed 2026-03-18 10:01:19 +01:00
1 parent 67b00b941e
commit 627eb8e265
3 files changed
+141 -69

No files matched your search

+5 -59
View File
@@ -1,66 +1,12 @@
#!/bin/bash
set -e
echo "═══════════════════════════════════════════════════════════"
echo "MITAI JINKENDO - Backend Startup (v9b)"
echo "═══════════════════════════════════════════════════════════"
# Run database initialization with Python (no psql needed!)
python /app/db_init.py
# ── PostgreSQL Connection Check ───────────────────────────────
echo ""
echo "Checking PostgreSQL connection..."
MAX_RETRIES=30
RETRY_COUNT=0
until PGPASSWORD=$DB_PASSWORD psql -h "$DB_HOST" -U "$DB_USER" -d "$DB_NAME" -c '\q' 2>/dev/null; do
RETRY_COUNT=$((RETRY_COUNT + 1))
if [ $RETRY_COUNT -ge $MAX_RETRIES ]; then
echo "✗ PostgreSQL not ready after ${MAX_RETRIES} attempts"
echo " Exiting..."
exit 1
fi
echo " Waiting for PostgreSQL... (attempt $RETRY_COUNT/$MAX_RETRIES)"
sleep 2
done
echo "✓ PostgreSQL ready"
# ── Schema Initialization ──────────────────────────────────────
echo ""
echo "Checking database schema..."
# Check if profiles table exists
TABLE_EXISTS=$(PGPASSWORD=$DB_PASSWORD psql -h "$DB_HOST" -U "$DB_USER" -d "$DB_NAME" -tAc \
"SELECT COUNT(*) FROM information_schema.tables WHERE table_schema='public' AND table_name='profiles'")
if [ "$TABLE_EXISTS" = "0" ]; then
echo " Schema not found, initializing..."
PGPASSWORD=$DB_PASSWORD psql -h "$DB_HOST" -U "$DB_USER" -d "$DB_NAME" -f /app/schema.sql
echo "✓ Schema loaded from schema.sql"
else
echo "✓ Schema already exists"
fi
# ── Auto-Migration (SQLite → PostgreSQL) ───────────────────────
echo ""
echo "Checking for SQLite data migration..."
SQLITE_DB="/app/data/bodytrack.db"
PROFILE_COUNT=$(PGPASSWORD=$DB_PASSWORD psql -h "$DB_HOST" -U "$DB_USER" -d "$DB_NAME" -tAc \
"SELECT COUNT(*) FROM profiles")
if [ -f "$SQLITE_DB" ] && [ "$PROFILE_COUNT" = "0" ]; then
echo " SQLite database found and PostgreSQL is empty"
echo " Starting automatic migration..."
python /app/migrate_to_postgres.py
echo "✓ Migration completed"
elif [ -f "$SQLITE_DB" ] && [ "$PROFILE_COUNT" != "0" ]; then
echo "⚠ SQLite DB exists but PostgreSQL already has $PROFILE_COUNT profiles"
echo " Skipping migration (already migrated)"
elif [ ! -f "$SQLITE_DB" ]; then
echo "✓ No SQLite database found (fresh install or already migrated)"
else
echo "✓ No migration needed"
if [ $? -ne 0 ]; then
echo "✗ Database initialization failed"
exit 1
fi
# ── Start Application ──────────────────────────────────────────