Need Branching Strategy Advice
We are struggling to come up with a good branching strategy for our databases. We are using SQL Source Control with Git, Jenkins (for builds) and Octopus (for deployments to Test and Production). Only the master branch is pushed through the Jenkins/Octopus processes.
Suppose we have two pending issues (Issue1 and Issue2) being worked by two different developers. Each developer creates a branch, commits their changes to their respective branches, and performs unit testing. Both decide the changes are ready to be pushed downstream and merge their changes into master. The Jenkins process does a successful build and we use Octopus to push the changes into our Test environment.
Suppose further that for whatever reason, we decide that only Issue1 is ready for production deployment. How do we unwind the Issue2 change? Is there a better way to handle this?
Best Answer
-
MikielAgutu Posts: 29 Silver 1Hello TomYour question is difficult to answer in some ways, as it's about your team's processes. However I'll try and answer the best I can.To me, the main problem is that you're putting your changes through the CI process too late. As you said:'Only the master branch is pushed through the Jenkins/Octopus processes.'This means you'll only be able to fully test your changes once they've been merged to master. If you discover the changes are bad, you'll want to undo them, as you said.In my opinion, your master branch should always be in a releasable state. That means any changes that go into master must be fully tested and reviewed before they're merged.Therefore, the simple fix is to ensure that you put all your branches through your Jenkins and Octopus testing process. That way you'll be able to validate if they're ready to be deployed. Only merge a branch into master once you're convinced that branch is in a releasable state.If you're still in a position where you find a change needs to be 'rolled back', the best way is to introduce the fix as another branch, and go through the testing process over again. In this sense you should 'roll forward', instead of trying to undo things.I hope that's helpful. As I said, this is a broad question about Agile delivery, and this is only my opinion on the matter based on your description of the situation.ThanksMikielMikiel Agutu | Software Engineer | Redgate Software
Answers
Having feature toggles/flags and rolling db changes out first are more helpful here if you need to undo something.
Create a new branch named Issue1 from master
Code a change (e.g. add a column) and check it in
At this point Jenkins starts a build and all is well. However, if I then checkout master (using git checkout), SQL Source Control thinks the Git version (in master) is more recent than what's in my database and shows the column deletion on the Get Latest tab. The Commit tab is empty.
This is obviously not what I want. Thoughts?
You ought to have a separate database per branch. Ideally, when you abandon a branch, you should drop that db, and then create a new one to reload from a new branch. If you're trying to determine what is different when merging two branches, this is better handled in a VCS tool (GitKrakken, SourceTree, etc). SOC doesn't handle this well and it gets confusing.