Repository navigation
Description
Problem to Solve
When multiple developers work on separate feature branches that each contain database migrations, merging these branches creates migration ordering conflicts. The migration_registry.txt file detects collisions, but developers currently have no automated way to resolve them. This forces teams to manually identify, delete, and recreate migrations after merge conflicts—a tedious and error-prone process that slows development velocity.
The core issue is that migrations must be applied in strict chronological order to maintain database integrity. When branches diverge and contain independent migrations, simply merging the branches can result in an incorrect migration sequence that isn't automatically detected until runtime.
Proposal
Introduce a new CLI command serverpod append-migration that automates the resolution of migration conflicts after branch merges. This command will:
-
Parse merge conflict markers in
migration_registry.txtto identify which migrations came from each branch (between<<<<<<< HEADand=======is our branch's migrations, between=======and>>>>>>>is the incoming branch's migrations) -
Identify our local migrations to delete by extracting our migration IDs from the conflict markers - these will be replaced by a new unified migration that applies our model changes on top of the new base state
-
Generate a unified migration that captures the complete database state transformation from the latest base migration to the current desired state, appending it with a new timestamp after the latest registry entry
Command usage:
serverpod append-migrationExample workflow:
Scenario: Developer A merged migrations ending at 20231115_123456, Developer B worked on a branch
with migrations 20231116_234567 and 20231117_345678 based on an older state.
Before append-migration (after merge conflict):
- migration_registry.txt has merge conflict markers
- Folders on disk: 20231115_123456/ (from A), 20231116_234567/ (ours), 20231117_345678/ (ours)
After append-migration:
- migration_registry.txt conflict resolved to: 20231115_123456, 20231118_999999
- Folders on disk: 20231115_123456/, 20231118_999999/
- Our migrations (20231116_234567/, 20231117_345678/) deleted and backed up
- 20231118_999999/ contains migration representing: applying our model changes on top of A's new base state
Use Case
Scenario: A team of 3 developers works on independent features on separate branches over a 2-week sprint. Developer A completes a user authentication feature with 2 migrations. Developer B completes a reporting feature with 3 migrations. Developer C completes an analytics feature with 1 migration. When the team merges these branches into main:
- Developer A's migrations land first (timestamps: 20231115_xxx, 20231115_yyy)
- Developer B's branch, created from main before A's merge, has migrations with timestamps (20231114_aaa, 20231114_bbb, 20231114_ccc) that are now "out of order"
- Developer C's branch has the same problem with conflicting timestamps
Currently, each developer must manually:
- Identify which migrations are "theirs"
- Delete those migration folders
- Create a new migration from scratch capturing all their changes
- Test it thoroughly before re-pushing
With append-migration, this process becomes:
# After merging main into feature-branch (which creates a conflict in migration_registry.txt)
git merge origin/main
serverpod append-migration
# Done—your local migrations deleted, new unified migration created based on your models on the new base state, ready to pushThis is especially valuable for teams that:
- Work in short-lived feature branches with frequent integrations
- Have multiple developers making database changes simultaneously
- Need to maintain a clean, linear migration history, while handling merge conflicts
Alternatives
-
Manual resolution (current approach): Developers manually delete and recreate migrations. This works but is time-consuming and error-prone, especially at scale.
-
Strict sequential branch policy: Require all developers to base feature branches on a synchronized state and merge in a specific order. This severely limits parallelism and isn't practical, especially for larger teams.
The proposed append-migration command is superior because it's:
- Lightweight and non-invasive
- Maintains the clean, linear migration history principle
- Aligns with Serverpod's documented best practice
- Minimal additional complexity in the CLI tool
Additional context
This feature is directly requested in the discussion (#4299) by community member (@cotw-fabier) who has encountered this issue in production. @SandPod confirmed that this is a known pain point and indicated willingness to support a CLI command to address it.
"When a collision is detected you should remove all migrations you have created in the branch and create a new one to correctly append to the history.
Removing all migrations that are not part of the migration registry is currently a manual task, but I think we could introduce a command for that in the cli."
How experienced are you with this library?
Intermediate - Familiar with the basics or have used it in a few 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 fieldsParked Contributions
Activity
jwelmac commentedon Dec 24, 2025
Thinking through this in more detail I am considering renaming the command to
rebase-migration.The reason for this change is because of another use case I thought of in the developer workflow.
As @SandPod stated in #4299
So not only could it be used as part of the workflow locally detecting and resolving merge conflicts, but it could also be used without conflicts locally or in a GitHub action.
Rationale
Here is the scenario.
Developer A creates a feature and during the process they created 2 migrations for the incremental changes to complete the feature. According to Serverpod best practices this should be merged in as a single migration. So before the developer marks the PR as ready they would need to ensure that they remove the previous migrations and create a new single migration. This is currently a manual task the developer would need to do.
By using
rebase-migrationit would rebase from either a provided migration (e.g. 20251224xxxxxxxxx) or by default the last migration in the base branch (default: main) of your repository (which can be specified). This would then squash all migrations local to the branch to a single migration, hence making the branch compliant.Check flag
The command could also take a flag (e.g. --check) that will confirm that the current branch has only a single migration since the last migration in the base branch, or a provided migration. It would then fail with a non-zero exit number if there are more than 1 migrations if the branch is not compliant.
Usage
The check flag could be run for pull requests that are not drafts to ensure that the branch is ready to be merged.
In that way, there would be checks and balances for the developer who may forget to ensure there is only a single migration prior to merging their feature branch.
jwelmac commentedon Dec 29, 2025
Implementation started.
I decided to remove the
onto-branchoption as the time and complexity to implement it reliably outweighs the benefit of parsing the last migration from the desired branch and passing to the command if executing in CI.Next step after this I am thinking is to create a Github action that would retrieve the migration id and pass to the
rebase-migration --checkcommand to verify that only a single additional migration is to be merged.marcelomendoncasoares commentedon Jan 2, 2026
Hi @jwelmac! Thanks for this proposal! This is indeed an area that we want to improve the developer experience. We are right now writing an RFC that will soon be published including this pain point and other proposals to greatly enhance the UX when working with migrations. It will be very good to have you onboard when we have the RFC if you are willing to contribute more to this area!
I saw you already started some work on your proposal, but we do have a few concerns about the coupling of git conflict resolution inside the
serverpod_cli. Since there are so many ways of using Git, this would represent high complexity while probably covering only a few opinionated usage patterns.Take the challenge for implementing the
checkflag you have proposed as an example:The way the detection of the "last migration in the base branch" is implemented in the PR - on the
getLastIncomingMigrationmethod - will only work correctly when the feature branch is the current branch (HEAD) and main is being merged into it. But if users callsrebase-migrationfrom the middle of a git rebase (when current and incoming are inverted), it would silently produce wrong results.This is a simple example, but highlights the complexity of bundling git conflict resolution inside the CLI. Although building the happy path for merging feature-braches might be possible - and you are probably very close to complete -, there would be several unexpected ways to break the command. Or, even worst, make it run and produce wrong results, generating second order problems for users when trying to initialize their servers. Guarding against this would be very hard and could be too consuming from a framework maintenance perspective.
From our first internal discussions around this RFC, we leaned more towards having a
cleancommand that will serve to remove all migrations that are not in themigrations-registry.txtand leave the conflict resolution for the users. Then, after manually solving the conflicts on themigrations-registry.txtfile, users can call an alias that would be the equivalent forclean && create, resulting in the same effect you proposed with theappend-migration- but without the complexity of resolving the conflicts. This strategy also keeps users accountable by the migrations that are generated, without having to check the result of black-box operations that could wrongly replace existing migrations.Would you agree with a change towards this direction?
jwelmac commentedon Jan 2, 2026
Thanks for the feedback @marcelomendoncasoares
After working through the complexities of the merge resolution and considering the other pathways to consider I agree with you. I would not mind removing the git related features and leaving that to the user. There are too many ways that issues can arise and its best that they are handled manually by the dev who will make the choices and take the responsibility.
I would love to be a part of further discussions around this and other ways to enhance the framework. UX/DX is something I am really passionate about and it would be an honor to further Serverpod's mission in that aspect.
Thanks again for the feedback.
I will make the changes to the PR to remove the conflict resolution.
marcelomendoncasoares commentedon Jan 3, 2026
You're welcome @jwelmac! And glad to know you would like to contribute more to this area of the framework! 🚀
One of the changes that we will probably do in this initiative is to introduce a new
migrationscommand that will contain all migration operations - as opposed as having several commands*-migrationon the root of the CLI. We're going to decide on this very soon, but it would change the way we implement the append migration. Ideally we don't want to introduce new commands using the current format if we are going to place them under a namespace, so I'll suggest we briefly park this PR while we close these definitions.Then, as soon as we have them, I'll be sure to involve so we can move this implementation forward!
jwelmac commentedon Jan 4, 2026
@marcelomendoncasoares
That sounds like a great initiative.
While working on this PR I had to extract some code of
create-migrationinto a class so that it could be used within therebase-migrationcommand. This change would definitely change the structure of this command and others as we likely would need to redefine the project structure for common methods and classes.Love it. Looking forward to it.
I am going to park the PR, but as a next step I will remove any code referencing conflict resolution so it only retains the necessary functionality.
craiglabenz commentedon Jan 7, 2026
Agreed with all the chatter here.
As the team works on the RFC, I want to (once again 😆) advocate for a
serverpod migrations rollback [migration_id]command which would un-apply any migrations downstream of the provided ID. IMO, this would make it quite manageable for a developer to back out one of their migrations to apply a different one that landed first, then regenerate and re-apply their own.This is how Django does it and it works very well there.
Of course, to do this, the whole migrations feature in Serverpod would have to be expanded to start capturing inverse statements for all of its operations.
craiglabenz commentedon Jan 7, 2026
I first described that idea in #4539, but I'll now close that in favor of centralizing conversations here.
jwelmac commentedon Jan 7, 2026
Great one @craiglabenz.
With a refactor around migrations this may be an easy win as this is partly completed in the first stage of the current
rebase-migrationimplementation. This includes backing up the migrations removed to the.dart-toolfolder. Just in case there is a change of mind.Looking forward to the RFC because it will help to highlight the use cases and variations. That will help a lot with ensuring that all the appropriate functionality is exposed and accounted for during the implementation phase.
marcelomendoncasoares commentedon Jan 16, 2026
@craiglabenz @jwelmac The RFC has just been posted! Would love to hear your perspective about the proposal.