fix: remove legacy SQLite compatibility code (#122) #126
No reviewers
Labels
No Label
ai-changes-requested
ai-failed
ai-merged
ai-pr-opened
ai-reviewed
ai-reviewing
ai-reviewing
ai-working
bug
enhancement
evolution
performance
phase-0
phase-1a
phase-1b
phase-1c
phase-1d
security
tech-debt
todo
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: cal/paper-dynasty-database#126
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "ai/paper-dynasty-database#122"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #122
Summary
app/db_engine.py: RemovesDATABASE_TYPEenv var,SKIP_TABLE_CREATION, the SQLiteelsebranch, all 13db.create_tables()guards, and commented-out SQLitescout_dbcode (~280 lines removed).PooledPostgresqlDatabaseis now initialized unconditionally.app/db_helpers.py: RemovesDATABASE_TYPEre-export and the SQLiteon_conflict_replace()branch fromupsert_many(). PostgreSQLON CONFLICT DO UPDATEis now the only upsert path.app/routers_v2/players.py: Updates stale comment referencing SQLite compatibility.tests/conftest.py: Removesos.environ["DATABASE_TYPE"] = "postgresql"(no longer needed); keeps dummyPOSTGRES_PASSWORDfor instantiation.CLAUDE.md: Updates description, ORM line, Key Env Vars, and removes SQLite locking common issue.Other observations
tests/test_evolution_seed.pyandtests/test_season_stats_model.pyuseSqliteDatabase(':memory:')for unit test isolation — these are not production SQLite compatibility code and are intentionally left in place.players.py(unrelated to this change).Test results
No test command configured. Changes verified by reading back modified files and confirming no remaining
sqlite,DATABASE_TYPE,SKIP_TABLE_CREATION, orpd_master.dbreferences in application code.AI Code Review
Files Reviewed
app/db_engine.py(modified — ~280 lines removed)app/db_helpers.py(modified)app/routers_v2/players.py(modified — comment only)tests/conftest.py(modified)CLAUDE.md(modified)Findings
Correctness
SKIP_TABLE_CREATIONguards removed, the SQLiteelsebranch removed, and the commented-outscout_dbblock (~160 lines of dead commented code) cleaned up.PooledPostgresqlDatabaseis now initialized unconditionally at module load, which is the correct outcome.DATABASE_TYPE == "postgresql"branch inupsert_many()was the only live SQLite code path. Removing the branch and keeping the PostgreSQL logic is correct. The removed imports (os,Union,SQL) are confirmed unused in the post-PR version —Unionnever appeared in any function signature, andSQLwas imported but never referenced in a function body.os.environ["DATABASE_TYPE"] = "postgresql"was the mechanism that previously prevented SQLite table-creation from running during test collection. WithSKIP_TABLE_CREATIONgone, this line is no longer needed. ThePOSTGRES_PASSWORDdummy credential is correctly kept —PooledPostgresqlDatabasestill instantiates at import time and needs a non-None password.DATABASE_TYPEandSKIP_TABLE_CREATIONappear only in the three files this PR modifies. No routers or other modules importDATABASE_TYPEfromdb_helpers. The removal is exhaustive.Security
Style & Conventions
db_helpers.pymodule docstring at the top (the "Usage" block showingfrom app.db_helpers import upsert_many, DATABASE_TYPE) is updated in the diff to remove theDATABASE_TYPEreference — correct.db.create_tables()blocks leaves some double-blank-lines in db_engine.py (e.g., afterRarity,Event,Cardset,MlbPlayer,Player,Teamclass definitions). This is a minor formatting inconsistency but is consistent with the existing style in that file and does not affect behavior.Suggestions
POSTGRES_PORTis not listed in CLAUDE.md'sKey Env Varssection, but it is used indb_engine.py(os.environ.get("POSTGRES_PORT", "5432")). This was already missing pre-PR, so it is not introduced by this change — but worth noting as a minor documentation gap if CLAUDE.md is ever revisited.Verdict: COMMENT (APPROVED)
Clean, focused removal with no functional regressions. The scope is exactly what the PR title claims — all SQLite compatibility code in application modules is gone, the test scaffolding is updated to match, and the documentation is corrected. The
DATABASE_TYPEremoval is confirmed exhaustive across the codebase. No issues found that would block merging.(Posted as COMMENT per Gitea self-review restriction.)
Automated review by Claude PR Reviewer
AI Code Review
Files Reviewed
app/db_engine.py(modified — ~280 lines removed)app/db_helpers.py(modified)app/routers_v2/players.py(modified — comment update)tests/conftest.py(modified)CLAUDE.md(modified)Findings
Correctness
The core logic changes are correct and complete.
PooledPostgresqlDatabaseis initialized unconditionally, all 13db.create_tables()guards are removed, and theupsert_many()SQLite branch is removed. The PostgreSQL-only code path is functionally identical to the oldDATABASE_TYPE == "postgresql"branch. No logic regressions found.The
conftest.pychange is correct — theos.environ["DATABASE_TYPE"] = "postgresql"line is no longer needed and its removal is clean. ThePOSTGRES_PASSWORDdummy default is correctly retained.One correctness concern: The
Unionimport is removed fromdb_helpers.py, and theSQLimport is also removed. Checking the post-PR file:SQLwas imported frompeeweebut only used in the old SQLite branch (it was never used in the PostgreSQL path). Removing it is correct. However, theEXCLUDEDimport inside the loop (from peewee import EXCLUDED) is now unconditional and repeated on every batch iteration. This was already true for the PostgreSQL branch before — it is not a regression introduced by this PR — but it is worth noting as a pre-existing style issue.Security
No security issues. No secrets introduced, no injection vectors changed, no access control logic touched.
Style & Conventions
Issue — Stale
compose.production.yml: Thecompose.production.ymlfile still passesDATABASE_TYPE=postgresqlas an environment variable to the container (line 19). After this PR merges,db_engine.pyno longer reads that variable. The env var becomes dead configuration, which is harmless at runtime but misleading. This file is not in the PR diff. A follow-up cleanup is warranted.Issue — Stale docs and
.env.example:docs/QUICK_START.md,docs/MIGRATION_PROGRESS.md,docs/POSTGRES_MIGRATION_GUIDE.md,docs/DOCKER_QUICKSTART.md,.env.example, anddocs/PROJECT_PLAN.jsonall still referenceDATABASE_TYPE, the SQLite fallback, andexport DATABASE_TYPE=sqlite. These are not updated in this PR. They will mislead future contributors or anyone running the dev setup. This should be addressed in a follow-up issue or expanded scope of this PR.Issue — CLAUDE.md on-disk is stale: The CLAUDE.md in
database/on themainbranch still reads "Peewee ORM with SQLite (WAL mode)" and listsDATABASE_TYPEin Key Env Vars. This PR correctly updates it. However, the file in the repo onmainalso references a staleRelease Workflowsection mentioningnext-releasestaging branch, which the parentCLAUDE.mdsays is retired. This is pre-existing and out of scope.Minor —
db_helpers.pydocstring: The PR correctly removesDATABASE_TYPEfrom the module docstring's usage example. No issues.Edge Cases
No new edge cases introduced. The removal of
db.create_tables()calls is safe — tables are managed by migrations in PostgreSQL, not auto-created at import time. This was already the effective behavior wheneverDATABASE_TYPE=postgresqlwas set.Test Coverage
The PR author notes that
tests/test_evolution_seed.pyandtests/test_season_stats_model.pyintentionally useSqliteDatabase(':memory:')and are left in place — this is correct behavior. These tests do in-memory model binding and are not production compatibility code.No new tests are added, which is acceptable for a pure removal/cleanup PR. The removal of
DATABASE_TYPEfromconftest.pyis the only test-infrastructure change and it is correct.Verdict: REQUEST_CHANGES
The application code changes in
db_engine.py,db_helpers.py,players.py, andconftest.pyare correct and complete. However, there is one blocking issue:compose.production.ymlstill passesDATABASE_TYPE=postgresqlto the container. While this is harmless at runtime (the variable is simply ignored post-merge), it creates misleading configuration in the production deployment file and should be removed as part of this cleanup PR to keep the change complete.Additionally, the docs (
docs/QUICK_START.md,docs/MIGRATION_PROGRESS.md,.env.example, etc.) still referenceDATABASE_TYPEand SQLite. These are pervasive enough that they should be addressed — either in this PR or via a follow-up issue explicitly tracked. Please either expand the scope to include them or open a tracking issue before merging.Automated review by Claude PR Reviewer
Checkout
From your project repository, check out a new branch and test the changes.