Part of #257 — Phase 1 step (6).
RFC: #275.
Goal
Add the CQ_DATABASE_URL environment variable as the canonical way to
select the backend, with a factory that returns the right concrete
store. Backward-compatible: falls back to CQ_DB_PATH.
Scope
-
create_store(database_url: str) -> Store factory in
store/__init__.py. URL parsing dispatches on scheme:
sqlite:///... → SqliteStore
postgresql+psycopg://... → raises NotImplementedError for now,
with a message pointing at the Phase 2 PostgresStore child.
-
app.py lifespan resolves the URL:
database_url = os.environ.get(
"CQ_DATABASE_URL",
f"sqlite:///{os.environ.get('CQ_DB_PATH', '/data/cq.db')}",
)
-
Document the new env var in the relevant config doc.
Acceptance criteria
- Existing deployments using
CQ_DB_PATH continue to work unchanged.
- Setting
CQ_DATABASE_URL=sqlite:///custom.db works.
- Setting a
postgresql+psycopg://... URL fails with a clear
NotImplementedError message pointing at the Phase 2
PostgresStore child.
Definition of Done
- TDD: failing tests for each branch (default fallback, explicit
SQLite URL, Postgres URL → NotImplementedError) land before the
factory implementation.
- End-to-end smoke: server boots under each of (a) no env, (b)
CQ_DB_PATH only, (c) CQ_DATABASE_URL=sqlite:///....
- Full test suite green.
- Lint clean.
- Deployment / configuration docs updated to introduce
CQ_DATABASE_URL and document the CQ_DB_PATH fallback as legacy.
(Full multi-backend deployment guide lands in the Phase 4
documentation child.)
Blocked by
- Implement
SqliteStore against Store protocol via Core helpers
(Phase 1 child).
Part of #257 — Phase 1 step (6).
RFC: #275.
Goal
Add the
CQ_DATABASE_URLenvironment variable as the canonical way toselect the backend, with a factory that returns the right concrete
store. Backward-compatible: falls back to
CQ_DB_PATH.Scope
create_store(database_url: str) -> Storefactory instore/__init__.py. URL parsing dispatches on scheme:sqlite:///...→SqliteStorepostgresql+psycopg://...→ raisesNotImplementedErrorfor now,with a message pointing at the Phase 2
PostgresStorechild.app.pylifespan resolves the URL:Document the new env var in the relevant config doc.
Acceptance criteria
CQ_DB_PATHcontinue to work unchanged.CQ_DATABASE_URL=sqlite:///custom.dbworks.postgresql+psycopg://...URL fails with a clearNotImplementedErrormessage pointing at the Phase 2PostgresStorechild.Definition of Done
SQLite URL, Postgres URL →
NotImplementedError) land before thefactory implementation.
CQ_DB_PATHonly, (c)CQ_DATABASE_URL=sqlite:///....CQ_DATABASE_URLand document theCQ_DB_PATHfallback as legacy.(Full multi-backend deployment guide lands in the Phase 4
documentation child.)
Blocked by
SqliteStoreagainstStoreprotocol via Core helpers(Phase 1 child).