Skip to content

fix(migrations): avoid duplicate Feishu delivery target columns on fresh databases - #1019

Open
fengnanrui wants to merge 1 commit into
dataelement:mainfrom
fengnanrui:codex/fresh-database-migration-20260925
Open

fengnanrui wants to merge 1 commit into
dataelement:mainfrom
fengnanrui:codex/fresh-database-migration-20260925

Conversation

@fengnanrui

Copy link
Copy Markdown

Summary

Fixes #1018.

initial_schema builds current ORM metadata, so empty databases already contain
the Feishu delivery_target_id columns. Revision f065 used to add them again
unconditionally, breaking fresh installations and Drone build 588.

Inspect both tables independently and add/drop only absent/present columns.
Existing UUID values are preserved on upgrade, partial schemas are handled,
and inspection failures remain errors. No revision ID, graph edge, business
data or dependency declaration changes. A later revision cannot repair this
failure because bootstrap stops at f065; the guards must live in that revision.
The owning Agent Note documents the rationale and rollback semantics.

Verification

  • 13 of the 16 new cases fail before the fix, including real PostgreSQL duplicate-column errors; all 16 pass after it.
  • CLAWITH_TEST_POSTGRES_BIN=<PostgreSQL 17 bin> .venv/bin/python -m pytest tests/test_feishu_group_target_migration.py tests/test_agent_model_deleted_at_migration.py -q: 21 passed.
  • Independently verified the complete empty-database upgrade, current --check-heads, downgrade one revision and re-upgrade on PostgreSQL 15 as used by CI. Both resulting columns are nullable UUIDs.
  • The opt-in PostgreSQL tests create and clean up their own Unix-socket cluster with TCP disabled. No existing database or production server is used.
  • Focused Ruff, git diff --check, Gitleaks and the unchanged single Alembic head check pass.

Fork checkout in the upstream Drone pipeline is separately addressed by #1015;
this PR deliberately does not duplicate that change. Once checkout is fixed,
the existing fresh-database CI stage exercises this migration repair.
The documented pre-push skill and docs/testing.md are absent from upstream;
available checks were run directly. No production deployment was performed.

Checklist

  • Tested locally
  • No unrelated changes included

Initial schema uses current metadata and already creates delivery_target_id on fresh databases. Inspect both tables independently before additions/removals, preserve existing values, and keep revision history unchanged. Add the owning Agent Note and schema/error/real-PostgreSQL regressions.

Validated 21 related tests, focused Ruff, unchanged single Alembic head, and PostgreSQL 15/17 fresh upgrade plus downgrade/upgrade. Thirteen new regression cases failed before the fix. Staged Gitleaks and diff checks pass.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fresh database migration fails on duplicate Feishu delivery target columns

1 participant