6021a3883d
- Add trumpsignal.db to git (one-time migration source) - entrypoint.sh detects empty Postgres and runs migration automatically - scripts/migrate_sqlite_to_postgres.py: posts, subscriptions, bot_trades - Add psycopg2-binary to requirements for migration script Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
39 lines
1.2 KiB
Bash
39 lines
1.2 KiB
Bash
#!/bin/sh
|
|
set -e
|
|
|
|
echo "[entrypoint] Running Alembic migrations..."
|
|
alembic upgrade head
|
|
|
|
# One-time migration: if trumpsignal.db exists and posts table is empty,
|
|
# migrate SQLite data into Postgres then remove the db file.
|
|
if [ -f "trumpsignal.db" ]; then
|
|
echo "[entrypoint] Found trumpsignal.db — checking if migration needed..."
|
|
POST_COUNT=$(python -c "
|
|
import asyncio, os
|
|
os.environ.setdefault('DATABASE_URL', '')
|
|
import psycopg2
|
|
url = os.environ.get('DATABASE_URL','').replace('+asyncpg','')
|
|
try:
|
|
conn = psycopg2.connect(url)
|
|
cur = conn.cursor()
|
|
cur.execute('SELECT COUNT(*) FROM posts')
|
|
print(cur.fetchone()[0])
|
|
conn.close()
|
|
except Exception as e:
|
|
print('0')
|
|
" 2>/dev/null || echo "0")
|
|
|
|
if [ "$POST_COUNT" = "0" ]; then
|
|
echo "[entrypoint] Postgres is empty — running SQLite migration..."
|
|
python scripts/migrate_sqlite_to_postgres.py
|
|
echo "[entrypoint] Migration done. Removing trumpsignal.db..."
|
|
rm -f trumpsignal.db
|
|
else
|
|
echo "[entrypoint] Postgres already has data (${POST_COUNT} posts) — skipping migration."
|
|
rm -f trumpsignal.db
|
|
fi
|
|
fi
|
|
|
|
echo "[entrypoint] Starting API server..."
|
|
exec uvicorn app.main:app --host 0.0.0.0 --port 8000
|