Skip to content

fix(cli): Don't detect column renames for live columns that still exist in the target - #5920

Open
ChandraChaan wants to merge 2 commits into
serverpod:mainfrom
ChandraChaan:fix/5915-live-schema-rename-cycle
Open

ChandraChaan wants to merge 2 commits into
serverpod:mainfrom
ChandraChaan:fix/5915-live-schema-rename-cycle

Conversation

@ChandraChaan

Copy link
Copy Markdown

generateTableMigration matches source and target columns by effectiveFieldName, which falls back to the column name when fieldName is null. A schema read from a live database never has field names, so when a model maps fields to each other's column names (first: String, column=second / second: String, column=first), each live column was matched to the wrong field and the diff reported a rename cycle (first → second, second → first) for a table that is already in sync. The generated SQL can't run either, because each target name still exists when its rename runs.

Source columns without a stored fieldName are now only considered for a rename when their name no longer exists in the target. If the target still has a column with that name, it's the same physical column, as the issue suggests. Columns with a stored fieldName are matched exactly as before.

Tests in column_rename_test.dart:

  • the swapped-columns case from the issue (live schema without field names) now produces no migration actions;
  • a definition without field names whose column was renamed in the target is still detected as a rename, so the legacy fallback keeps working.

The swapped-columns test fails without this change. dart test test/database in tools/serverpod_cli passes (773 tests).

Fixes #5915

Pre-launch Checklist

  • I read the Contribute page and followed the process outlined there for submitting PRs.
  • This update contains only one single feature or bug fix and nothing else. (If you are submitting multiple fixes, please make multiple PRs.)
  • I read and followed the Dart Style Guide and formatted the code with dart format.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///), and made sure that the documentation follows the same style as other Serverpod documentation. I checked spelling and grammar. (not applicable: no public API changed)
  • I added new tests to check the change I am making.
  • All existing and new tests are passing.
  • Any breaking changes are documented below.

Breaking changes

None.

@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@ChandraChaan ChandraChaan changed the title fix(cli): don't detect column renames for live columns that still exist in the target fix(cli): Don't detect column renames for live columns that still exist in the target Nov 1, 2026
@ChandraChaan

Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

@ChandraChaan

Copy link
Copy Markdown
Author

I merged main into the branch yesterday, and the CI run on it failed for reasons outside this change:

  • 40 of the 41 failed jobs (the Serverpod integration tests (server) and Serverpod concurrent integration tests (server) shards) stopped at the Start Redis step, before any test ran.
  • The other one, serverpod_embedded_postgres integration (ubuntu-24.04-arm), failed one test in embedded_postgres_dual_integration_test.dart with PortInUseException: port 33375 on 127.0.0.1 is held by another process. The same job passed on other recent runs.

This PR only touches tools/serverpod_cli/lib/src/database/migration.dart and its test. Could a maintainer re-run the failed jobs when convenient? I can't re-run them from my side. Thanks!

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.

Migration rename detection creates a rename cycle when explicit column names match other field names

1 participant