Reconcile models with DB schema (fix alembic drift) #89

Manually merged
marvin8 merged 3 commits from feat/issue-83-alembic-drift into feat/issue-80-collect 2026-08-14 03:09:56 +00:00
Collaborator

Reconciles the SQLAlchemy models with the actual database schema so alembic revision --autogenerate no longer emits spurious drift:

  • Adds the missing server_default values to match the DB (blocked_users.pattern_type, hashtag_streams.active/enable_scheduling/fetch_interval_minutes, posts.* boolean/count columns, queue_stats.*).
  • Adds the missing ix_posts_author_username and ix_posts_stream_id indexes.
  • Restores the named unique constraints (uq_post_id, uq_hashtag_stream) and unique indexes to match the DB.
  • Adds a migration to drop the legacy app_settings.api_key column + uq_app_settings_api_key constraint (the API key is stored as a row with key="api_key", not a column).

Verified: on a fresh DB, alembic revision --autogenerate now produces an empty migration.

Refs #83

Reconciles the SQLAlchemy models with the actual database schema so `alembic revision --autogenerate` no longer emits spurious drift: - Adds the missing `server_default` values to match the DB (`blocked_users.pattern_type`, `hashtag_streams.active`/`enable_scheduling`/`fetch_interval_minutes`, `posts.*` boolean/count columns, `queue_stats.*`). - Adds the missing `ix_posts_author_username` and `ix_posts_stream_id` indexes. - Restores the named unique constraints (`uq_post_id`, `uq_hashtag_stream`) and unique indexes to match the DB. - Adds a migration to drop the legacy `app_settings.api_key` column + `uq_app_settings_api_key` constraint (the API key is stored as a row with `key="api_key"`, not a column). Verified: on a fresh DB, `alembic revision --autogenerate` now produces an empty migration. Refs #83
🗃️ reconcile models with DB and drop legacy api_key
All checks were successful
/ gitleaks (pull_request) Successful in 18s
/ pr-review (pull_request) Successful in 36s
/ checks (pull_request) Successful in 2m10s
/ publish (pull_request) Has been skipped
/ publish-container (pull_request) Has been skipped
/ deploy-docs (pull_request) Has been skipped
d87c9406f3
forgejo-actions left a comment

WuMing

Found 1 issue(s). See inline comments below.

## WuMing Found **1** issue(s). See inline comments below.
@ -11,10 +11,12 @@ from sqlalchemy import Boolean
from sqlalchemy import DateTime
from sqlalchemy import Float
from sqlalchemy import ForeignKey
from sqlalchemy import Index

tests [LOW]

Non-trivial schema changes were made to models.py (new indexes, unique constraints, server_default columns) but no test file appears in the diff. Add or update tests that exercise the model schema/constraints, or a migration round-trip test for the new DDL.

**tests** [LOW] Non-trivial schema changes were made to models.py (new indexes, unique constraints, server_default columns) but no test file appears in the diff. Add or update tests that exercise the model schema/constraints, or a migration round-trip test for the new DDL. <!-- wuming:sha256:4a6c68223b144472dabae7ca637e054cc55ca48fd40e6a208f2099eb98a9ca96 -->
marvin8 marked this conversation as resolved
add schema-reconciliation metadata test
Some checks failed
/ gitleaks (pull_request) Successful in 22s
/ pr-review (pull_request) Successful in 46s
/ checks (pull_request) Failing after 2m14s
/ publish (pull_request) Has been skipped
/ publish-container (pull_request) Has been skipped
/ deploy-docs (pull_request) Has been skipped
801124a4f5
Author
Collaborator

packages/fenliu/src/fenliu/models.py line 14

tests [LOW]

Added a schema-reconciliation metadata test in commit 801124a — it asserts the server defaults, indexes, and named unique constraints on the reconciled columns.

[`packages/fenliu/src/fenliu/models.py` line 14](https://forge.marvin8.zone/marvin8/dujiangyan/pulls/89#issuecomment-1338) > **tests** [LOW] ✅ Added a schema-reconciliation metadata test in commit `801124a` — it asserts the server defaults, indexes, and named unique constraints on the reconciled columns.
🐛 fix flaky tests: per-request ContextVar overrides replace patch() isolation
All checks were successful
/ gitleaks (pull_request) Successful in 15s
/ pr-review (pull_request) Successful in 43s
/ checks (pull_request) Successful in 2m19s
/ publish (pull_request) Has been skipped
/ publish-container (pull_request) Has been skipped
/ deploy-docs (pull_request) Has been skipped
b22895bfa9
App-level tests patched get_db across a module list with process-global
patch(), which tryke's single-process junit reporter exposed as
order-dependent flakiness against the shared module-level in-memory
engine. Replace it with a TestAppWrapper that injects _db_session_override
and _auth_override per request, which get_db() and the UI auth middleware
already consult. Also widen isolated in-memory DB name entropy and drop
test_ui_auth's module-level create_all on the shared engine.
marvin8 approved these changes 2026-08-14 03:09:22 +00:00
marvin8 manually merged commit 08ede21838 into feat/issue-80-collect 2026-08-14 03:09:56 +00:00
marvin8 deleted branch feat/issue-83-alembic-drift 2026-08-14 03:10:09 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
3 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
marvin8/dujiangyan!89
No description provided.