Repository navigation
Description
Problem to Solve
When the latest migration version folder is empty - usually to a discard changes operation -, the create-migration command will end with an error, requesting the user to manually delete the folder. This workflow is inefficient, since it is frequent that developers discard their changes and end up with the empty folder to be manually removed in order to continue.
⠙ Creating migration... (1ms)
Unable to determine latest database definition due to a corrupted
migration. Please re-create or remove the migration version and try
again. Migration version: "20250918013903164".
PathNotFoundException: Cannot open file, path =
'/.../tests/serverpod_test_server/migrations/20250918013903164/definition_project.json'
(OS Error: No such file or directory, errno = 2)
✗ Creating migration (9ms)
This message was introduced on PR #1537 as a fix to the crash reported on #1512. It can be improved to not consider an empty folder as a "corrupted state".
Proposal
Empty folders should be ignored by the versioning evaluation, since they are not really a corrupted state. As the migrations folder is managed by the CLI, it could safely remove these empty migration folders. An efficient implementation would be to remove the last folder if empty until it finds one that has files. Only then return this version as the last existing migration.
If such folder has files, but the definition.json file is missing, then we throw the exception, since this would be an actual corrupted state.
Use Case
When developing, it is frequent that we create a migration but end up discarding it to create again after more changes. The discard operation lead to an empty folder that will break the second migration generation, only for the developer to have to manually delete it and call the command again.
Alternatives
Continue removing the empty folder manually after the error in the command.
Additional context
N/A.
How experienced are you with this library?
Expert - Experienced and comfortable with using this library in complex projects
Are you interested in working on a PR for this?
- I want to work on this
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone 🚀
Activity
Moe1211 commentedon May 4, 2026
I’m opening a new PR
fix: Prune trailing empty migration dirs (#3985) (#5044)