Black Friday is here! Get up to 30% off on Devart products!
ends in   {{days}}
Days
{{timeFormat.hours}}
:
{{timeFormat.minutes}}
:
{{timeFormat.seconds}}

Version-controlling TFS in Azure DevOps

This article is dedicated to the aspects of version-controlling SQL Server databases in Azure DevOps with dbForge Source Control.

Team Foundation Version Control is a centralized version control system. Usually, developers work on one version of each file on their dev machines and can change files simultaneously. You can view the changes history only if you are connected to the server. Branching in TFVC has a folder structure. You need to create a source and target branches. After that, files from the source branch are copied to the target branch. In Source Control, you can:

  • Commit and revert changes
  • View and resolve conflicts
  • View the history of changes
  • Link static data
  • Update the local version with the latest changes

Create an Azure DevOps project

To begin, you need to have an Azure DevOps project. If you haven't created it yet, sign in to your Azure DevOps account. Then, click Start free. On the organization page that opens, your projects will be displayed. If you want to create projects for a new organization, click New organization and follow the steps from the article Creating a TFVC Repository in Azure DevOps and Linking It to Source Control, part Getting Started With Azure DevOps.

After that, a new project with the repository is displayed on the Project page where you can commit, push changes, add files or make any changes. In the case of the private project, make sure to provide users with access to the repository.

dbForge Source Control - Creating a new Azure DevOps project in the Azure DevOps account

Link a database to Source Control

To get started, download, install dbForge Source Control, and then open SQL Server Management Studio. In Object Explorer, right-click the database you want to link to a repository to and select Source Control > Link Database to Source Control.

Note: For demo purposes, we will use a dedicated database development model, so that each developer can work on their own copy of the database.

dbForge Source Control - Link a database to Source Control

Select TFVC source control repository

In the Link Database to Source Control wizard that opens, under Source Control repository, click Manage to open Source Control Repository Properties dialog, where you can configure source control settings, and then click OK:

  • Specify a server URL (for example, https://dev.azure.com/Organization_Name)
  • Choose an authentication type
  • Enter a database folder name to store a SQL script
  • Repository name is auto-generated from the project name
dbForge Source Control - Set up the TFVC source control repository

Make an initial commit

After the database was linked to TFVC source control, the Source Control Manager opens displaying all the files that can be committed to the remote repository. Since the repository is empty, you need to make an initial commit. In the Local Changes section, select all the files, write a comment, and click Commit. In the Commit dialog, click OK.

When refreshed, you see that there are no local changes in database objects. When switching to the remote repository, it contains all the local database files you've just committed.

If you do not want to commit certain changes, select the changes and click Undo.

dbForge Source Control - Make an Initial Commit

View the database files in Azure DevOps

After we made an initial commit, we can start working on the database files, namely modify the files, commit the local changes, update the local copy of the database with the latest changes from the remote repository, revert the uncommitted changes, and resolve conflicts if any.

In the Azure DevOps account, you can view the linked database files on the Repos > Files page. If you want to see the history of changes and find out who and what changes applied, switch to the Changesets page.

dbForge Source Control - View database files and changes history in Azure DevOps

Associate commits with work items

With dbForge Source Control, you can associate a TFVC work item to the change to be committed by using a work item query.

To associate a work item to the commit, in the Local Changes section, select the changes you want to commit, enter a reason for the commit, and click Associate with Work Items. In the pop-up window that opens, enter a project name, choose a query, a work item, and an association type (Resolve or Associate). The Resolve type associates the work item and marks it as resolved, while the Associate type only links a work item to the commit but does not resolve it. Once done, click Commit.

dbForge Source Control - Associate Commits with Work Items

Get remote changes

There is a common situation when several developers collaborate on the same database, make changes in the database files, and commit them to the remote repository. You need to get these changes to keep your local copy up-to-date.

In order to get the latest changes, proceed to Object Explorer, right-click the database you want to update, and click Get Latest. Alternatively, in the Remote Changes section, select the changes and click Get Latest.

dbForge Source Control - Get the latest changes from the remote repository

Resolve conflicts

When you make changes to the same database file(s), you may face conflicts that will be displayed in the Conflicts section of the Source Control Document. In this case, conflicts should be resolved either by overwriting your local changes with the remote ones (Get Remote option) or by accepting the local changes and thus, overriding the remote ones (Get Local option).

At the bottom of the Source Control document, you can see DDL local (left pane) and remote (right pane) differences.

dbForge Source Control - Resolve conflicts

Conclusion

dbForge Source Control offers the quickest and simplest way to version-control SQL Server databases and manage database changes. Its functionality includes linking a database to the remote repository, committing the local changes and getting the latest ones from the repository, associating work items with commits, reverting the uncommitted changes, viewing the changes history, and resolving conflicts, if any.

Get Source Control as part of dbForge SQL Tools

SQL Tools is an extensive pack of advanced tools and SSMS add-ins