Skip to content

fix: Prune trailing empty migration dirs (#3985) - #5044

Merged
marcelomendoncasoares merged 4 commits into
serverpod:mainfrom
Moe1211:fix/3985-empty-migraiton-folders
Aug 7, 2026
Merged

marcelomendoncasoares merged 4 commits into
serverpod:mainfrom
Moe1211:fix/3985-empty-migraiton-folders

Conversation

@Moe1211

@Moe1211 Moe1211 commented May 4, 2026 •

Copy link
Copy Markdown
Contributor

When the newest migration version directory exists but is completely empty (common after discarding generated files), create-migration used to treat that as a corrupted migration and fail when reading definition_project.json.

This PR aligns behavior with issue #3985:

  • FileSystemMigrationArtifactStore.listVersions (server migrations/): from the end of the sorted version list, remove directories that contain no files or subdirectories. Stop as soon as a non-empty directory is found, so a folder that still has files but is missing real migration artifacts continues to surface the existing “missing artifact” / corrupted path.
  • If any directory was removed and migration_registry.txt already exists, rewrite it so it matches the remaining versions.
  • ClientMigrationArtifactStore.listVersions applies the same rule under lib/migrations/ and refreshes migration_registry.dart when pruning occurred and that file exists (so part directives do not point at removed folders).
  • Tests: packages/serverpod_database/test/migration_artifacts_store/file_system_migration_artifact_store_test.dart and an extra case in tools/serverpod_cli/test/integration/migrations/client_migration_artifact_store_test.dart.

Fixes: #3985


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.
  • 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 May 4, 2026 •

Copy link
Copy Markdown

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

@Moe1211

Moe1211 commented May 4, 2026

Copy link
Copy Markdown
Contributor Author

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

@Moe1211 Moe1211 changed the title fix(cli): prune trailing empty migration dirs (#3985) Fix(cli): prune trailing empty migration dirs (#3985) May 4, 2026
@Moe1211 Moe1211 changed the title Fix(cli): prune trailing empty migration dirs (#3985) fix(cli): prune trailing empty migration dirs (#3985) May 4, 2026
@Moe1211 Moe1211 changed the title fix(cli): prune trailing empty migration dirs (#3985) Prune trailing empty migration dirs (#3985) : fix(cli) May 4, 2026
@Moe1211 Moe1211 changed the title Prune trailing empty migration dirs (#3985) : fix(cli) fix(cli): Prune trailing empty migration dirs (#3985) May 4, 2026

@marcelomendoncasoares marcelomendoncasoares left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution with this fix, @Moe1211! And sorry for the long delay on the review, we have been heads down on a big release in the past month.

Your approach is very good! It fixes the issue with negligible performance penalty - given that we just check the trailing directory and abort on the first found file. I made only a few suggestions to reduce code duplication and make the tests more adherent to the pattern.

I know it has been a while since you opened the PR, so please signal if you do not intend to work on it anymore - in which case we'll get it ready for merge.

@marcelomendoncasoares
marcelomendoncasoares force-pushed the fix/3985-empty-migraiton-folders branch from c025b87 to efe35e3 Compare August 7, 2026 15:54
@marcelomendoncasoares marcelomendoncasoares changed the title fix(cli): Prune trailing empty migration dirs (#3985) fix: Prune trailing empty migration dirs (#3985) Aug 7, 2026
@marcelomendoncasoares
marcelomendoncasoares merged commit 3bc067b into serverpod:main Aug 7, 2026
958 of 959 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 7, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create migration should not throw error when the latest migration folder is empty

2 participants