refactor: split database.py god-object into focused repositories (#116)#138
Merged
adrunkhuman merged 1 commit intomasterfrom Mar 21, 2026
Merged
refactor: split database.py god-object into focused repositories (#116)#138adrunkhuman merged 1 commit intomasterfrom
adrunkhuman merged 1 commit intomasterfrom
Conversation
Replaces the 1094-line Database class with four focused repository modules (fixtures, predictions, results, scores) and a thin composition root in connection.py that delegates all CRUD and owns schema/migration on startup. All 11 call sites and the full test suite remain unchanged. - connection.py: Database facade + schema init + migration helpers - fixtures.py: FixtureRepository (~190 lines) - predictions.py: PredictionRepository + SaveResult (~270 lines) - results.py: ResultsRepository (~90 lines) - scores.py: ScoreRepository + cross-cutting recalc helpers (~230 lines) Monkeypatch targets in test_admin_service updated to patch the module- level _recalculate_scores_in_connection function at its new location. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
🚅 Deployed to the matchday-typer-pr-138 environment in patient-quietude
|
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
Databasegod-object with four focused repository modules (fixtures.py,predictions.py,results.py,scores.py) and a thin composition root inconnection.pythat delegates all CRUD and owns schema/migration on startupfrom typer_bot.database import Databasestill worksSaveResultre-exported from__init__.pyas beforeChanges
connection.pyDatabasefacade + schema init + migration helpersfixtures.pyFixtureRepository(~190 lines)predictions.pyPredictionRepository+SaveResult(~270 lines)results.pyResultsRepository(~90 lines)scores.pyScoreRepository+ module-level_fixture_has_scores_in_connection/_recalculate_scores_in_connection(~230 lines)Cross-cutting recalculation helpers live as module-level functions in
scores.pyand are imported bypredictions.pyandresults.py— no circular imports.Additional fixes (caught in review)
resultstable schema: addedCREATE UNIQUE INDEX IF NOT EXISTSafter migrations so fresh installs get the constraint without relying solely on the migration pathif unique_index_exists and "updated_at" in columns→if unique_index_exists:_recalculate_scores_in_connection: wrapped body intry/finallyto restoredb.row_factoryon all exit pathssave_scores: broadenedexcept aiosqlite.Error→except Exceptionso non-SQLite exceptions also trigger explicit rollback and loggingTest plan
test_admin_service.pyupdated to patch module-level functions at their new locations (predictions_module._recalculate_scores_in_connection,results_module._recalculate_scores_in_connection)test_database.pyimport updated fromtyper_bot.database.database→typer_bot.databaseCloses #116
🤖 Generated with Claude Code