Skip to content

Closes #1: Enable branch migrations #264

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 18 commits into
base: feature
Choose a base branch
from

Conversation

jeremystretch
Copy link
Contributor

@jeremystretch jeremystretch commented May 21, 2025

Closes: #1

  • Introduce the "migrating" state & associated signals for branches
  • Add a BranchEvent type for migration
  • Add the applied_migrations ArrayField on Branch to record schema migrations which have been applied to the branch
  • Override the allow_migrate() method on our custom database router to suppress migrations of models which do not support branching
  • Introduce the migrate() method on Branch & add supporting UI view
  • The apply() and undo() methods on our proxy model for ObjectChange now take a Branch instance as the first argument
  • Add a migrate() method on ObjectChange to automatically adapt pre- and post-change data according to the applicable migrators

@CLAassistant
Copy link

CLAassistant commented May 28, 2025

CLA assistant check
All committers have signed the CLA.

@jeremystretch jeremystretch force-pushed the 1-branch-migrations branch from ba98492 to 57eaec2 Compare June 2, 2025 12:16
@jeremystretch jeremystretch marked this pull request as ready for review June 2, 2025 16:32
@jeremystretch jeremystretch requested a review from a team June 6, 2025 14:45
Copy link
Contributor

@arthanson arthanson left a comment

Choose a reason for hiding this comment

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

Some questions on it during test:

  1. Any branch created before having branching 0.5.6 cannot be migrated?
  2. If you are on an older version of NetBox 4.1.9 and you upgrade branching to 0.5.6 then you upgrade NetBox to 4.2 and make changes on the branch, then update to NetBox 4.3 and more changes to the branch then upgrade to this PR and do the branch migration - should that still be valid?
  3. The branch in the list shows as Ready before you run the branch migration, it also shows in the dropdown as "{name} (Ready)" but grayed - should we make that show a different status (Pending Migration) or something as it isn't really ready?

I got a weird crash and I think it was because I still had the browser window open to the branch pre-update. I.E.

  1. install old NetBox
  2. create. branch and make changes
  3. make sure you have the branch active and keep the browser window open
  4. Update NetBox, update branching to this PR and run migrate
  5. Go to your open browser window and refresh or try to go to any page - get errors that database fields don't exist.
  6. Open up new browser (will be in main branch) - go to branches and run the branch migrations.
  7. After branch is migrated, go back to original browser and refresh, everything works.

@jeremystretch
Copy link
Contributor Author

  1. Any branch created before having branching 0.5.6 cannot be migrated?

Any branch can be migrated, but v0.5.6 of the plugin must be installed before upgrading NetBox.

  1. If you are on an older version of NetBox 4.1.9 and you upgrade branching to 0.5.6 then you upgrade NetBox to 4.2 and make changes on the branch, then update to NetBox 4.3 and more changes to the branch then upgrade to this PR and do the branch migration - should that still be valid?

Yes, that should be supported. However, NetBox v4.3.2 or later is necessary to enable migrating branches.

  1. The branch in the list shows as Ready before you run the branch migration, it also shows in the dropdown as "{name} (Ready)" but grayed - should we make that show a different status (Pending Migration) or something as it isn't really ready?

Its status is technically "ready" however the branch is not available for use due pending migrations. We could introduce an explicit status for this, however I'm not sure how we'd reliably update the branch's status to it.

@jeremystretch
Copy link
Contributor Author

  1. Go to your open browser window and refresh or try to go to any page - get errors that database fields don't exist.

This is because the non-migrated branch is still active in the session, so NetBox is trying to access a schema from a previous version. We need to check in middleware that the branch doesn't have any pending migrations before activating it for the request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants