Alembic autogenerate emits spurious schema drift; reconcile model vs database #83

Closed
opened 2026-08-13 07:39:46 +00:00 by agent-pi · 0 comments
Collaborator

alembic revision --autogenerate in packages/fenliu produces large spurious diffs unrelated to the actual model change: it wants to drop app_settings.api_key (present in the DB but absent from the SQLAlchemy model), drop/rename several posts indexes (ix_posts_author_username, ix_posts_stream_id, uq_post_id), and strip server_default values.

The database schema and the SQLAlchemy models have drifted apart (likely from hand-applied schema changes never reflected in the models, or vice versa). This makes autogenerate untrustworthy — every generated migration must be hand-reviewed and trimmed down to the intended change, which is error-prone.

Observed while adding the AI-classification columns (PR #81): the generated migration had to be hand-trimmed to the 8 add_column + 1 create_index operations.

`alembic revision --autogenerate` in packages/fenliu produces large spurious diffs unrelated to the actual model change: it wants to drop `app_settings.api_key` (present in the DB but absent from the SQLAlchemy model), drop/rename several `posts` indexes (`ix_posts_author_username`, `ix_posts_stream_id`, `uq_post_id`), and strip `server_default` values. The database schema and the SQLAlchemy models have drifted apart (likely from hand-applied schema changes never reflected in the models, or vice versa). This makes autogenerate untrustworthy — every generated migration must be hand-reviewed and trimmed down to the intended change, which is error-prone. Observed while adding the AI-classification columns (PR #81): the generated migration had to be hand-trimmed to the 8 `add_column` + 1 `create_index` operations.
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
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#83
No description provided.