Rebranche la base sur DATABASE_URL (PostgreSQL partagé) au lieu du SQLite en dur
Build & Deploy / build (push) Successful in 34s
Build & Deploy / build (push) Successful in 34s
database.py codait la base en dur en SQLite et ignorait la variable DATABASE_URL fournie par le compose. Le conteneur recréait donc un /app/regwatch.db vide à chaque démarrage (aucun volume), pendant que les 397 documents réels dormaient dans PostgreSQL : GET /documents renvoyait [] et le cron de veille comptait dans PG des documents que les scrapers écrivaient dans le SQLite jetable. - DATABASE_URL est lu depuis l'environnement, le SQLite ne reste qu'en repli. - check_same_thread n'est passé que pour SQLite (psycopg2 le rejette). - psycopg2-binary ajouté : aucun driver PostgreSQL n'était installé. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -3,11 +3,14 @@ from sqlalchemy.orm import sessionmaker, declarative_base
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
DB_PATH = os.path.join(os.path.dirname(os.path.dirname(__file__)), "regwatch.db")
|
DB_PATH = os.path.join(os.path.dirname(os.path.dirname(__file__)), "regwatch.db")
|
||||||
DATABASE_URL = f"sqlite:///{DB_PATH}"
|
DATABASE_URL = os.getenv("DATABASE_URL", f"sqlite:///{DB_PATH}")
|
||||||
|
|
||||||
|
# check_same_thread est propre à SQLite : psycopg2 le rejette.
|
||||||
|
CONNECT_ARGS = {"check_same_thread": False} if DATABASE_URL.startswith("sqlite") else {}
|
||||||
|
|
||||||
engine = create_engine(
|
engine = create_engine(
|
||||||
DATABASE_URL,
|
DATABASE_URL,
|
||||||
connect_args={"check_same_thread": False}
|
connect_args=CONNECT_ARGS
|
||||||
)
|
)
|
||||||
|
|
||||||
SessionLocal = sessionmaker(
|
SessionLocal = sessionmaker(
|
||||||
|
|||||||
@@ -9,3 +9,4 @@ python-jose[cryptography]
|
|||||||
passlib[argon2]
|
passlib[argon2]
|
||||||
python-multipart
|
python-multipart
|
||||||
pdfplumber
|
pdfplumber
|
||||||
|
psycopg2-binary
|
||||||
|
|||||||
Reference in New Issue
Block a user