Repository navigation
fix: a media path over 500 chars fails on PostgreSQL, and nothing tested PostgreSQL at all - #293
Conversation
…ends for real PostgreSQL was never actually exercised. The test workflow had no database service, and the "postgres" tests asserted on mock calls, so the SQL they generate was never compiled, let alone run. Meanwhile SQLite was built by create_all and PostgreSQL only by Alembic, so the two schemas drifted with nothing able to notice. Measured: 54 differences on SQLite, 50 on PostgreSQL. One of them is a live bug rather than cosmetics — media.file_path is VARCHAR(500) on a real PostgreSQL install but Text in the models, so a media path over 500 characters hard-fails there and works on SQLite. Two more: the reactions table has no foreign key to messages in the migrated schema on either backend, and PostgreSQL carries two unused sequences from a BIGSERIAL that the models explicitly disclaim. Migration 021 aligns the migrated schema with the models on both backends: nullability on 35 columns, the declared defaults, the file_path widening, the missing reaction foreign key, eight SQLite integer widths, and the empty rollback table migration 005 leaves behind. Every step reads the live schema first and does nothing where the shape already matches, so an install provisioned by create_all rebuilds nothing. CI now runs a real PostgreSQL service, and a new fixture yields a real adapter on a real engine parameterised over both backends. The workflow fails if the PostgreSQL leg skips, because a silently skipped backend is how this drift survived. A schema-parity test builds both schemas and fails on any difference. Also fixes a pre-existing crash loop found while working in the entrypoint: its SQLite path chain omitted DATABASE_DIR, so such an install was inspected at one path and migrated at another, and Alembic then re-ran the initial migration against the real database.
|
Warning Review limit reached
Next review available in: 10 minutes You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (7)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
🐳 Dev images published!
The dev/test instance will pick up these changes automatically (Portainer GitOps). To test locally: docker pull drumsergio/telegram-archive:dev
docker pull drumsergio/telegram-archive-viewer:dev |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #293 +/- ##
==========================================
+ Coverage 93.79% 93.82% +0.02%
==========================================
Files 27 27
Lines 8965 8965
==========================================
+ Hits 8409 8411 +2
+ Misses 556 554 -2
🚀 New features to boost your workflow:
|
…ends for real (#293) PostgreSQL was never actually exercised. The test workflow had no database service, and the "postgres" tests asserted on mock calls, so the SQL they generate was never compiled, let alone run. Meanwhile SQLite was built by create_all and PostgreSQL only by Alembic, so the two schemas drifted with nothing able to notice. Measured: 54 differences on SQLite, 50 on PostgreSQL. One of them is a live bug rather than cosmetics — media.file_path is VARCHAR(500) on a real PostgreSQL install but Text in the models, so a media path over 500 characters hard-fails there and works on SQLite. Two more: the reactions table has no foreign key to messages in the migrated schema on either backend, and PostgreSQL carries two unused sequences from a BIGSERIAL that the models explicitly disclaim. Migration 021 aligns the migrated schema with the models on both backends: nullability on 35 columns, the declared defaults, the file_path widening, the missing reaction foreign key, eight SQLite integer widths, and the empty rollback table migration 005 leaves behind. Every step reads the live schema first and does nothing where the shape already matches, so an install provisioned by create_all rebuilds nothing. CI now runs a real PostgreSQL service, and a new fixture yields a real adapter on a real engine parameterised over both backends. The workflow fails if the PostgreSQL leg skips, because a silently skipped backend is how this drift survived. A schema-parity test builds both schemas and fails on any difference. Also fixes a pre-existing crash loop found while working in the entrypoint: its SQLite path chain omitted DATABASE_DIR, so such an install was inspected at one path and migrated at another, and Alembic then re-ran the initial migration against the real database.
The problem
PostgreSQL was never actually exercised. The test workflow had no database service, and every "postgres" test asserted on mock calls —
mock_session.execute.assert_awaited_once()— so the SQL those paths generate was never compiled, let alone run. One mock helper is used ~145 times against a handful of real-SQLite tests. That is a check that cannot go red.Meanwhile there were two schema authorities: SQLite built by
create_all, PostgreSQL built only by Alembic. They drifted, and nothing could notice.Measured, not assumed: 54 differences on SQLite, 50 on PostgreSQL.
One is a live bug rather than cosmetics:
media.file_pathisVARCHAR(500)on a real PostgreSQL install butTextin the models — the comment says "changed to Text for long paths" but no migration ever widened it. A media path over 500 characters hard-fails on PostgreSQL and works on SQLite.Two more the audit had missed: the
reactionstable has no foreign key tomessagesin the migrated schema on either backend (so reaction rows are orphanable), and on SQLite migration 005's rebuild dropped its other foreign key too, leaving that table with none. PostgreSQL also carries two unusednextval()sequences from aBIGSERIALthe models explicitly disclaim.One audit claim turned out stale and is reported as such: the audit-log indexes it flagged as missing are now declared — #288 added them. There is no index drift anywhere, on either backend.
The fix
Migration 021 aligns the migrated schema with the models on both backends: nullability on 35 columns (backfill, then tighten), the declared defaults, the
file_pathwidening, the missing reaction foreign key, eight SQLite integer widths, and the empty rollback table migration 005 leaves behind on every fresh install.Every step reads the live schema first and does nothing where the shape already matches — so an install provisioned by
create_all, which is what most existing users have, rebuilds nothing. SQLite rebuilds go throughbatch_alter_tableper table, only where that table still differs.CI now runs a real PostgreSQL service, and a new fixture yields a real adapter on a real engine, parameterised over both backends, skipping cleanly when no server is reachable so a laptop without Docker still passes. The workflow fails if the PostgreSQL leg skips — a silently skipped backend is exactly how this drift survived.
A schema-parity test builds both schemas both ways on both backends and fails on any difference in tables, columns, types, nullability, defaults, indexes, unique constraints, primary keys or foreign keys.
Also fixes a pre-existing crash loop found while working in the entrypoint: its SQLite path chain omitted
DATABASE_DIR, so such an install was inspected at one path and migrated at another, and Alembic then re-ran the initial migration against the real database.Two deletions, stated loudly
_messages_media_backupis dropped only when empty; a copy holding a real pre-normalization row survives untouched (tested).fk_reaction_message, because PostgreSQL refuses the constraint otherwise. Acreate_all-built database already declares that FK, so nothing is deleted there.Verification
git archive origin/main's own models and migration chain — never the current tree — seeded with real rows and digested row-by-row, column-by-column, before and after. Fresh SQLite, fresh PostgreSQL, existingcreate_all-provisioned SQLite (the common real-user case; the shipped stamping ladder was extracted verbatim fromentrypoint.shand run, not reimplemented), existing PostgreSQL at the previous head, both backends from older revisions, and a re-run. Every row byte-identical where it should be.sqlite_masterDDL text, andpg_attribute/pg_constraint/pg_indexes/pg_sequencesdirectly. Zero differences after normalising cosmetic ordering.ruffclean.Known and deliberate
create_allstays as a fallback for the viewer image, which ships noalembic/and has no entrypoint, so it cannot migrate. It is limited to SQLite because on PostgreSQL it would race a concurrently migrating container. This is now two provably-equal paths rather than two drifting ones — the parity test fails if they diverge again. Making it literally one path means shipping Alembic into the viewer image, which is a bigger blast radius than this change warranted and is tracked separately.No version bump: still 7.33.6. The single 8.0.0 bump comes at the end of the programme.