The guide provides step-by-step instructions to walk you through the process of:
With the help of dbForge Studio for SQL Server, you can version-control database schemas and data, roll back unwanted changes, handle static data conflicts, and maintain the integrity of the database. Using the tool, you can link your database to Git, a distributed version control system.
Note
In dbForge Studio for SQL Server 6.0 and later, a new Git client is implemented - Git for Windows. Therefore, you can work with all possible connection and authentication types, as this task is delegated to the Git client. Before trying to connect your database to Git, make sure that you have a Git for Windows client installed on your machine.
See the following how-to topics to learn how to link a database to a Git repository:
When dbForge Studio connects to a Git repository, is the connection secure? In other words, is TLS enabled?
dbForge Studio connects to Git using the standard Git client for Windows, which supports current security protocols, including TLS 1.2. Secure connections are established when the server both supports them and requires them. For instance, if a repository’s address begins with HTTPS and the server stipulates TLS, the connection will comply with these security requirements. The choice of security protocol is determined by the server’s configuration, not by dbForge settings.
dbForge Studio doesn’t work with either local or remote repositories directly – only through a clone. Therefore, you will need to create a local Git repository and then clone it.
For this, perform the following steps:
1. Create two empty folders on the disk of your computer where the local repository will be stored.
2. Start Windows Command Prompt (CMD).
Note
To navigate to the folder where the main local repository will be located, in the Command Prompt, use the
cd
command.
3. Type git init --bare
to create the main repository locally.
4. Navigate to the second folder and clone the local repository you have just created using git clone <pathToMainRepo>
. Make sure to place a dot at the end of the command to clone the repository to the folder you have created. Otherwise, another subfolder will be created.
Note
<pathToMainRepo>
is the path to the main repository you created locally when executing thegit init --bare
command.
5. Execute these CMD commands in the folder in question:
git commit --allow-empty -m initial
to make an initial commitgit push
to push the changes to the remote repository6. Link source control to the folder with the cloned repository.
It is also possible to automate the cloning of a Git repository executing the .bat file with the script from the command line. The script will clone the repository, make an initial commit, and push the changes to the repository.
To do this, perform the following steps:
1. In a text editor, enter the following script to create a batch file to clone the repository:
:: Change DatabaseName to your database name; it will be the repository folder name.
set _database=DatabaseName
:: Change _main if desired; it will be the folder for the main repository.
set _mainfolder=_main
:: Please do not change the following variables and commands.
set _maindir=%_mainfolder%\%_database%
:: Create the main folder to store the main repository.
md %_mainfolder%
:: Create a subfolder under the main folder with the name of the database.
md %_maindir%
:: Navigate to the subfolder.
cd %_maindir%
:: Initialize the main repository (it will be empty).
git init --bare
:: Go back to the root directory.
cd ..\..
:: Clone the main repository, creating a folder with the name of the database.
git clone %_maindir%
:: Navigate to the cloned folder.
cd %_database%
:: Run git commands in the cloned folder.
git commit --allow-empty -m initial
git push
set _path=%cd%
:: Print the repository folder for reference.
echo Cloned repo folder: %_path%
cd ..
pause
Note
Replace
DatabaseName
with the actual database name. This folder will be your repository.Optional: Change the name of the main repository folder -
_main
.Do not change the following variables and commands:
%_mainfolder%
and%_database%
.
2. Save the file with a .bat extension in the folder that will store the repositories.
3. Run the script.
Next, navigate to the folder that stores the repositories. In our example, it is D:\git_SQL
. As you can see, the following folders have been created:
After the repository has been cloned, you can link dbForge Source Control to that folder. To do this, perform the following steps:
Note
In our example, we’ll link the BikeStores database to the repository.
1. In Database Explorer, right-click the database you want to link to source control and select Source Control > Link Database to Source Control.
Alternatively, select Database > Link Database to Source Control on the ribbon.
2. In the Source Control Repository Properties dialog, do the following:
Optional: Click Test to verify that the database has successfully been connected to source control.
Click OK to apply the changes and close the Source Control Repository Properties dialog.
3. Select a database development model: shared or dedicated.
4. Click Link to establish the connection between the database and source control.
5. After the refresh operation, Source Control Manager opens, displaying the local changes, which you can commit to the repository.
Additionally, watch this video to get more information on how to create a local Git repository and link your database to it with the help of Source Control.
Download dbForge Studio for SQL Server and try it absolutely free for 30 days!
If you are the first person to link this database, add the database objects to source control in an ‘initial commit’: go to the Local changes section, select the objects, and click Commit. For more information, see Commit changes.
If you linked a database that is already in source control, update your database to the latest version: go to the Remote changes section, select the objects, and click Get Latest, which is available only in the dedicated model. For more details, see Get the latest version.