Skip to content

Wire CQ_DATABASE_URL and store factory #309

@peteski22

Description

@peteski22

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestteam-apiTeam API / Docker component

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions