Basics of Gitflow Workflow for SQL Database Projects Part 1
As a beginner or an entry level SQL Server database developer, how can I understand basic concepts of Git Workflow to be used with SQL Database Projects?
The solution is to get a basic understanding of Git Workflow from database development perspective so that you should to be able to apply these concepts efficiently and effectively for designing professional SQL Database Projects.
About Gitflow Workflow and SQL Database Projects
This tip is focused on the concepts of using Git Workflow with SQL Database Projects provided the reader has some background in SQL Database Projects and source control systems including Git.
Git is simply a code branching model to save, protect and share the code used for any sort of development ranging from software web applications to database solutions.
Git as a source control system technically maintains an exact point in time copy of the database code commonly known as code history for sharing, referencing, collaboration and working further.
What is Git Workflow or Gitflow Workflow
Gitflow Workflow or the Git Workflow is by far the most comprehensive workflow (standard pattern) to support all the phases of database development from design to delivery.
How SQL Database Project can be linked with Gitflow Workflow
You have to add your SQL Database Project to the Git source control. There are two ways to link your SQL Database Project with Git source control:
- You start off with an Azure DevOps project followed by creating a local copy of the project repo (repository) and then creating a SQL Database Project while connected to repo using master branch or dev branch
- You create a SQL Database Project then add to Git source control pointing to the remote repo (you must have created earlier)
What are the most prominent features of Gitflow Workflow
The three most prominent features (not to be confused with Feature branch) of Gitflow Workflow are as follows:
- This workflow supports a dedicated branching for solving production issues
- This workflow protects production-ready branch known as master from any kind of accidental overwrites
- This workflow supports multiple flows in a parallel fashion including normal development, features, hotfixes etc.
Is Gitflow Workflow suitable for big teams
Gitflow Workflow by design supports big teams working together on the projects ranging from simple to complex database solutions.
Is Gitflow Workflow suitable for small teams
This workflow is equally suitable for small teams.
Are there any competitive workflows
There are other workflows such as Feature Branch Workflow a special purpose workflow to be used by bigger teams if it serves the purpose.
Apart from the above workflow there are some workflows which are more suitable for single-developer projects or very small teams such as Git Centralized Workflow.
How many branches of code are used in Gitflow Workflow
There are two must-have branches in Gitflow Workflow. A workflow is not a Gitflow Workflow without these branches.
The two main mandatory branches are as follows:
What is the role of master branch in Gitflow Workflow
Master branch (master) in Gitflow Workflow is the branch of the database code which is in its finest form because of being tested and validated before it finds its way to the master branch.
Please note that master branch is also called production-ready branch because it is used to deploy database code to the different environments including Production.
What is the role of dev branch in Gitflow Workflow
Dev branch (dev) is that branch of the code where development takes place. In other words all the development work is saved on this branch and all the development team can interact with this branch for a number of purposes including branching off from dev to work on their piece of code.
Can a developer directly save changes to the master branch
A developer must not save database code changes directly to the master branch and policies need to be in place to ensure this does not happen as master branch is the production-ready branch.
How can changes be saved to the master branch
The database code changes can and must only be saved by pull request by merging code with master branch.
What is the pull request from master branch context
A pull request is technically an integration request when database code from another branch tries to integrate with master branch to roll out new changes to the master branch if there are no conflicts.
Getting connected to Git for Gitflow Workflow
In this section we are going to learn two basic methods of connecting to the Git source control before it can be used to apply Gitflow Workflow.
Creating a local copy of the Git repository from Azure DevOps Project
In this method you start off by creating an Azure DevOps project on Azure web portal provided you have already an Azure DevOps account.
Once the Azure DevOps project is created you go to the repos section and create a local copy of the repo to work with SQL Server Data Tools (SSDT) in Visual Studio.
Then you create a new solution and a SQL Database project inside that solution to begin your database development journey.
The next thing is to switch branches from master to dev to comfortably start working without the concerns to overwrite the production-ready branch.
Once you save your changes to the remote dev branch you create a pull request to merge your changes with master branch and that is when first cycle of your database development is completed.
These can be summarized in the following steps:
- Create an Azure DevOps project
- Create a local copy of the Git repository
- Create dev branch from the master branch
- Create SQL Database Project on dev branch
- Add desired changes to the database project
- Compile the project before pushing your changes to the remote dev branch
- Push changes to the remote dev branch
- Merge the pushed changes with the master branch
- Start working again on dev branch
To see all this in action please refer to the SQL Database Project Code Branching in Git tip.
Adding SQL Database Project to the Git Source Control Overview
Another way to get connected to the Git source control to be able to use Gitflow Workflow is to start working on your database project and then connect it to the Azure DevOps project little later.
You can add your project to any existing repo in any of the previously created Azure DevOps project or you can create a blank Azure DevOps project.
The steps are as follows:
- Create an Azure DevOps project or there must be an existing Azure DevOps project to connect to
- Create a new SQL Database Project under a new solution in SQL Server Data Tools (SSDT)
- Add your desired changes (which is normally not recommended without using any source control first except in few cases)
- Create dev branch from the master branch
- Add your project to the Git source control
- Push your changes to the remote dev branch
- Merge your changes with remote dev branch
- Carry on your work on the same dev branch
The above method is more suitable when you are working on a test project before you start your actual work so it can be easily discarded without becoming part of the source control.
The above method can also be used if you purposely do not want to add your work to the source control such as for teaching or demo purposes.
Adding SQL Database Project to the Git Source Control Walkthrough
Please create a blank Azure DevOps project called gitflow-workflow:
Open visual studio and create a new SQL Database Project WatchesGW under a solution Gitflow Workflow:
Click Add to Source Control and then click on Git at the status bar of the Visual Studio IDE:
Click Publish Git Repo in Team Explorer window:
Please sign in to your Azure DevOps account next if you have already not been connected to your account:
Click Advance to see advanced settings as shown below:
Select your Azure DevOps organization, Project and the repository and click on Publish Repository as shown below:
Congratulations, your SQL database project has been successfully pushed to the master branch of the remote repository:
You can click see it on the web link shown above to see the saved changes:
Please remember to branch off from master to create dev branch to begin with Gitflow Workflow and stay in touch as there is a lot more to learn about this workflow in the next part of this tip.
- Please refer to the tip and create a dev branch from the master branch to get ready to implement Gitflow Workflow
- Please try to create a new SQL Database Project using dev branch based on a sample database called OfficeSuppliesSampleV2 by which can found in this tip
- Please use Git stash method to create dev branch from master for the project mentioned in this tip to get some hands on experience of starting off with Gitflow Workflow using this tip as a reference
About the author
View all my tips
Article Last Updated: 2020-11-17