Skip to content

refactor(parses): convert parses/db.py to ParsesStore(BaseCatalogue)#154

Merged
VortexUK merged 1 commit into
mainfrom
refactor/parses-store
Jul 11, 2026
Merged

refactor(parses): convert parses/db.py to ParsesStore(BaseCatalogue)#154
VortexUK merged 1 commit into
mainfrom
refactor/parses-store

Conversation

@VortexUK

Copy link
Copy Markdown
Owner

Summary

Second of three PRs extending the catalogue architecture beyond eq2db (CensusStore was #153; the users.db async family is next).

backend/server/parses/db.py (787 lines, 33 functions — the biggest function-module left) becomes ParsesStore(BaseCatalogue):

  • init_db → base template method: _create_schema hosts the six table schemas, the idempotent _MIGRATIONS loop, the three named migrations (attack-types UNIQUE rebuild, encounters/ingest-log world columns) and index creation. FOREIGN_KEYS=True, CREATE_META=False. The hand-rolled WAL/synchronous/FK pragma preamble and its pragma_* SQL blocks are deleted — the base owns them (the world-migration's own FK on/off toggle blocks stay, they're part of the rebuild dance).
  • 28 conn-taking helpers → staticmethods (callers own the transaction, same as RaidCatalogue/CensusStore); invalidate_is_player_cache becomes an instance method over self.path. SwingType + swing-type constants stay module-level. Shared store = ParsesStore().
  • :memory: support removed in line with fix(eq2db): apply all 10 code-review findings from the catalogue arc #152 (per-read connections would silently see fresh empty memory DBs); the handful of tests using it now use tmp_path files.

Consumers

admin, parses delete/ingest/list/tamper-report routes, rankings, cleanup, and app startup import the instance as parses_db — call sites read identically, and the redundant parses_db.init_db(parses_db.DB_PATH) calls collapse to parses_db.init_db(). parses_db.DB_PATH reads become parses_db.path. metrics keeps the module-constant read.

Tests

conftest and the shared parses_db_path fixture re-point store.path alongside DB_PATH; monkeypatch.setattr(parses_db, "DB_PATH", …) sites become instance path patches (what routes actually read now); static calls route through parses_db.store. ParsesStore inherits the full base surface: log-friendly repr, bool = provisioned, CM close-on-exit, narrowed unbuilt-schema read handling.

Full suite: 1524 green, ruff + pyright clean.

🤖 Generated with Claude Code

Second PR extending the catalogue architecture beyond eq2db (after
CensusStore #153):

- backend/server/parses/db.py: init_db collapses into the base template
  method (_create_schema hosts the six table schemas, the _MIGRATIONS
  loop, the three named migrations and indexes; FOREIGN_KEYS=True,
  CREATE_META=False). The 28 conn-taking helpers become staticmethods;
  invalidate_is_player_cache becomes an instance method over self.path.
  SwingType + the swing-type constants stay module-level. Shared
  `store = ParsesStore()` instance.
- The hand-rolled :memory: special-case is gone (BaseCatalogue dropped
  it in #152 for silently-broken reads); tests that used
  init_db(":memory:") now use tmp_path files. The unused pragma_* SQL
  blocks are removed (base owns the connection pragmas); the
  world-migration's own FK toggle blocks stay.
- Consumers (admin, parses delete/ingest/list/tamper, rankings, app
  startup, cleanup) import the instance as parses_db — call sites read
  the same, and the parses_db.init_db(parses_db.DB_PATH)
  explicit-default calls collapse to parses_db.init_db().
- conftest + the shared parses_db_path fixture re-point store.path
  alongside DB_PATH; test monkeypatches move from module DB_PATH to
  instance path; static calls route through the store.

1524 tests green, ruff + pyright clean.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@VortexUK
VortexUK merged commit 1a2538f into main Jul 11, 2026
6 checks passed
@VortexUK
VortexUK deleted the refactor/parses-store branch July 11, 2026 10:39
VortexUK added a commit that referenced this pull request Jul 11, 2026
…e classes (#155)

Final PR extending the catalogue architecture (CensusStore #153,
ParsesStore #154):

- backend/db_catalogue.py: the path-bound identity + dunder surface
  (repr/bool/eq/hash/fspath) extracts into PathBound; BaseCatalogue
  inherits it, and a new AsyncStoreBase(PathBound) is the base for the
  aiosqlite-backed users.db domains (which do NOT own schema — the
  package-level backend.server.db.init_db orchestrator is unchanged).
- Seven domain modules become store classes sharing one users.db:
  UsersStore, ClaimsStore, FavoritesStore, ItemWatchStore, TokensStore,
  ServersStore (sync), RaidScheduleStore — each with a shared `store`
  instance. The 58 `path: Path = DB_PATH` kwargs threaded through every
  public function are gone; pure helpers (generate_token, hash_token,
  _server_row, _teams_with_slots) are staticmethods.
- backend/server/db/__init__.py facade re-exports each store's BOUND
  METHODS under the original names, so the `users_db.get_active_claims(...)`
  API shape (and every from-package import) is preserved with zero route
  churn. ALL_STORES tuple lets conftest re-point every store in one loop.
- Direct domain-module importers (favorites API, raid_schedule API,
  raid_live, character views pre-warm, server_context.load_registry —
  which passed DB_PATH positionally) migrate to store instances.
- Tests: explicit path= kwargs stripped where they were the redirected
  default; genuinely-injected temp paths become XStore(tmp) constructions
  or autouse store-repoint fixtures; DB_PATH monkeypatches gain the
  instance-path repoint; stale patch strings move onto the store bindings.

1524 tests green, ruff + pyright clean. Live-verified /api/server
(registry), raid-schedule and raiding-live endpoints.

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant