Goal
Introduce a bugfix migration on master and also backport that bugfix to an earlier z-stream of Pulp. To keep it simple, let’s say it’s the most recent z-stream. So for example let’s introduce a bugfix migration on master (not-yet-released 3.16.0) and try to backport to 3.15.next also, in this case 3.15.3 would be the next z-stream for 3.15.
Let’s say this new migration is migration 0077_bmbouter_test
to give a tangible name.
We want all migrations to run once, so for all these upgrade paths the migration 0077_bmbouter_test
needs to run once.
- 3.15.2 → 3.15.3 → 3.16.0
- 3.15.2 → 3.16.0
- fresh install of 3.16.0
Problem
If you’re not careful Django complains for some of the upgrade paths. For fresh installs you could get a “multiple leaf node” errors. Or for some upgrade paths you could receive a InconsistentMigrationHistory
exception.
Possible Solution
Here are two branches I made:
- Here’s the branch simulating the PR to master.
- Here’s the branch simulating the PR to the 3.15 branch.
The master migration
1.Checkout master
2. Create the migration of interest. In this case a dummy migration: pulpcore-manager makemigrations --name bmbouter_test --empty core
. This made 0077_bmbouter_test
.
3. Edit the migration to depend on the latest available migration from the 3.15 branch. So instead of depending on 0076_remove_reserved_resource
have it depend on 0075_rbaccontentguard
. You can see that edit in the migration here.
4. This creates two leaf nodes which Django doesn’t like and it will tell you this if you try to run migrations fresh. Solve this by creating a merge migration: pulpcore-manager makemigrations --merge
. This made migration 0078_merge_20211001_2019
. which is also in the PR against master.
The backport migration
These are in separate commits, and only the migration 0077_bmbouter_test
would be the one to backport to 3.15. So I made the 3.15 backport PR with just that migration only.
3.15.2 → 3.15.3 → 3.16.0 Upgrade Verification
At this point you can checkout pulpcore:3.15 and run pclean
. Then checkout the branch simulating the PR to the 3.15 branch and run pulpcore-manager migrate
and you’ll see 0077_bmbouter_test
apply. Then checkout the PR to master and run pulpcore-manager migrate
and it’ll just run the additional master migrations and the merge migration.
3.15.2 → 3.16.0 Upgrade Verification
At this point you can checkout pulpcore:3.15 and run pclean
. Then checkout the PR to master and run pulpcore-manager migrate
and it’ll run 0077_bmbouter_test
, the additional master migrations, and the merge migration.
Fresh install of 3.16.0 Verification
Checkout the PR to master and run pclean
. You’ll see it run run 0077_bmbouter_test
, the additional master migrations, and the merge migration.
Conclusion
The trick of it is to do two things:
- Have the migration on master declare dependency on the oldest migration of the z-stream you want to backport to.
- Make a merge migration
Open Questions
How to backport to multiple z-streams? In that case you can’t just have one z-stream that is the “lastest one migration” to declare a dependency on. Maybe we could keep the migration name the same, and just have it declare dependency on the one it needs to for that z-stream? I haven’t tested this but I could when I get back.
In the case of multiple z-streams, I’m a little unclear if we have to backport and release to every z-stream in between.