Vatxzz commited on
Commit
c5a2d01
·
1 Parent(s): dfd5a64

fixed the db issues.

Browse files
Files changed (3) hide show
  1. Dockerfile +3 -1
  2. backend/Dockerfile +3 -1
  3. backend/app/store/db.py +11 -0
Dockerfile CHANGED
@@ -21,7 +21,9 @@ COPY web_dist ./static
21
  RUN mkdir -p /data/downloads && chown -R 1000:1000 /data && chmod -R 777 /data
22
 
23
  ENV MEDIA_DIR=/data/downloads
24
- ENV DATABASE_URL=sqlite+aiosqlite:////data/cachy.db
 
 
25
  # Firebase project id (public, not a secret) — enables ID-token verification on
26
  # every data route. HF_API_KEY (media + embeddings) stays a Space secret.
27
  ENV FIREBASE_PROJECT_ID=cachy-057
 
21
  RUN mkdir -p /data/downloads && chown -R 1000:1000 /data && chmod -R 777 /data
22
 
23
  ENV MEDIA_DIR=/data/downloads
24
+ # DATABASE_URL is intentionally NOT set here — set it as an HF Space secret to the
25
+ # Neon postgres URL (postgresql+asyncpg://...). Never hardcode it: it holds a
26
+ # password. Without the secret the app falls back to ephemeral local SQLite.
27
  # Firebase project id (public, not a secret) — enables ID-token verification on
28
  # every data route. HF_API_KEY (media + embeddings) stays a Space secret.
29
  ENV FIREBASE_PROJECT_ID=cachy-057
backend/Dockerfile CHANGED
@@ -15,7 +15,9 @@ RUN pip install --no-cache-dir .
15
  COPY app ./app
16
 
17
  ENV MEDIA_DIR=/data/downloads
18
- ENV DATABASE_URL=sqlite+aiosqlite:////data/cachy.db
 
 
19
  RUN mkdir -p /data/downloads
20
 
21
  # HF Spaces expects the app on 7860.
 
15
  COPY app ./app
16
 
17
  ENV MEDIA_DIR=/data/downloads
18
+ # DATABASE_URL is intentionally NOT set here — set it as an HF Space secret to the
19
+ # Neon postgres URL (postgresql+asyncpg://...). Never hardcode it (holds a
20
+ # password). Without the secret the app falls back to ephemeral local SQLite.
21
  RUN mkdir -p /data/downloads
22
 
23
  # HF Spaces expects the app on 7860.
backend/app/store/db.py CHANGED
@@ -4,6 +4,7 @@ card row, not a table-per-block-type (docs/08). The jobs table is the queue."""
4
  from __future__ import annotations
5
 
6
  import difflib
 
7
  import uuid
8
  from datetime import datetime, timezone
9
 
@@ -486,8 +487,18 @@ def _ensure_engine():
486
  return _engine, _sessionmaker
487
 
488
 
 
 
 
489
  async def init_db() -> None:
490
  engine, _ = _ensure_engine()
 
 
 
 
 
 
 
491
  async with engine.begin() as conn:
492
  await conn.run_sync(Base.metadata.create_all)
493
  if "postgresql" in str(conn.engine.url):
 
4
  from __future__ import annotations
5
 
6
  import difflib
7
+ import logging
8
  import uuid
9
  from datetime import datetime, timezone
10
 
 
487
  return _engine, _sessionmaker
488
 
489
 
490
+ log = logging.getLogger("app.db")
491
+
492
+
493
  async def init_db() -> None:
494
  engine, _ = _ensure_engine()
495
+ # A silent SQLite fallback means a deploy quietly splits off its own local DB
496
+ # (data won't match Neon). Shout so a missing DATABASE_URL secret is obvious.
497
+ if str(engine.url).startswith("sqlite"):
498
+ log.warning(
499
+ "DATABASE_URL is SQLite (%s) — set it to the Neon postgres URL for a "
500
+ "shared/persistent database.", engine.url,
501
+ )
502
  async with engine.begin() as conn:
503
  await conn.run_sync(Base.metadata.create_all)
504
  if "postgresql" in str(conn.engine.url):