refactor(parses): convert parses/db.py to ParsesStore(BaseCatalogue)#154
Merged
Conversation
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
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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) becomesParsesStore(BaseCatalogue):init_db→ base template method:_create_schemahosts the six table schemas, the idempotent_MIGRATIONSloop, 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 itspragma_*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).invalidate_is_player_cachebecomes an instance method overself.path.SwingType+ swing-type constants stay module-level. Sharedstore = 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 redundantparses_db.init_db(parses_db.DB_PATH)calls collapse toparses_db.init_db().parses_db.DB_PATHreads becomeparses_db.path. metrics keeps the module-constant read.Tests
conftest and the shared
parses_db_pathfixture re-pointstore.pathalongsideDB_PATH;monkeypatch.setattr(parses_db, "DB_PATH", …)sites become instancepathpatches (what routes actually read now); static calls route throughparses_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