steveahnahn opened a new pull request, #72980:
URL: https://github.com/apache/airflow/pull/72980

   The 3.1 to 3.2 upgrade destroys team bindings on any deployment that has 
team rows. The reachable path is the supported cycle: `airflow db downgrade` to 
3.1, whose conversion turns team names into freshly generated UUIDs, followed 
by `airflow db migrate`. The upgrade then fails foreign key validation on 
Postgres, leaves MySQL half-committed with the id-to-name mapping already 
dropped, and on SQLite silently orphans every team reference:
   
   ```
   psycopg.errors.ForeignKeyViolation: insert or update on table "connection" 
violates
   foreign key constraint "connection_team_name_fkey"
   DETAIL:  Key (team_name)=(59a79660-...) is not present in table "team".
   ```
   
   ### Root cause
   
   `upgrade()` renames `team_id` columns to `team_name` while the values are 
still UUIDs, drops `team.id`, which is the only mapping between the two, and 
then creates validated foreign keys onto `team.name`. Its own `downgrade()` 
performs the value conversion in the opposite direction; the upgrade never did.
   
   ### Fix
   
   Convert the references while the mapping still exists, one team at a time, 
mirroring the downgrade's own Python loop so the comparison stays a plain 
string equality on every backend. The fix has to live in this migration rather 
than a follow-up one: it must run between the rename and the `team.id` drop, 
and no later migration can recover the dropped mapping. Verified with the real 
CLI round-trip on Postgres, MySQL and SQLite; the upgrade now succeeds and the 
seeded binding survives:
   
   ```
   GATE downgrade to 3.1 exit code: 0
   GATE re-upgrade exit code: 0
   GATE after round-trip: connection.team_name = 'gate-team', teams = 
['gate-team']
   GATE binding preserved
   ```
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   - [X] Yes — Claude Code (Fable 5.1)
   
   Generated-by: Claude Code (Fable 5.1) following [the 
guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to