Skip to content

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

Closed

Description

@marcelomendoncasoares

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

Activity

  1. added
    enhancement
    area: cli
    on Sep 18, 2025
  2. added
    ux
    good first issue
    and removed on Sep 18, 2025
  3. added this to the 3.0 Release milestone on Sep 18, 2025
  4. moved this from Inbox 📫 to Backlog 🗂️ in Serverpod Frameworkson Sep 18, 2025
  5. removed this from the 3.0 Release milestone on Oct 24, 2025
  6. Moe1211 commented on May 4, 2026

    @Moe1211
    Contributor

    I’m opening a new PR

  7. moved this from Backlog 🗂️ to Contributor In Progress 👩‍💻 in Serverpod Frameworkson Jun 11, 2026
  8. moved this from Contributor In Progress 👩‍💻 to Done 🚀 in Serverpod Frameworkson Aug 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area: clienhancementgood first issueux

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions