Databases in the Version Control System
DDL data source is a virtual data source with a schema based on a number of SQL scripts. Storing these files in the Version Control System (VCS) is a way to keep your database under the VCS.
The general workflow with VCS is the following:
First of all, you need to enable the VCS integration in your IDE. It will allow you to share and apply changes right from the IDE. With the VCS integration enabled, prepare a folder that you will share as a repository. This folder will also be a root folder for your DDL data source.
Then you need to create your DDL data source by dumping a regular data source (for example, SQLite) to a root/repository folder. Then you need to create a mapping between a data source and a DDL data source. You need the mapping to set what you want to share. For example, you hardly need to share all system or template schemas. So, you can select those schemas that you will exchange with your college.
Depending on what you want to do, you can dump your changes and share them through a VCS, or you can pull changes and apply it to your data source. All synchronization in both directions is made with the help of a DDL data source.
Configuring your Version Control System
We will use Git as a version control system and GitHub as a place to store our repository. To create a repository at GitHub, follow the steps in the Create a repo tutorial at docs.github.com.
By default, DataGrip has the VCS integration disabled. As a first step, we need to enable it and log into GitHub. To do that, you need to verify that the following plugins are installed and enabled: Git and GitHub.
Enable the Git plugin by JetBrains
Press Ctrl+Alt+S to open the IDE settings and select Plugins.
In the search field, type
Git, and press Enter.
Select the checkbox near the Git plugin name. To add integration with GitHub, you can also enable the GitHub plugin.
Restart the IDE.
Then you need to authorize at GitHub with a user account that has access to the repository with a DDL data source.
Register an existing account
Press Ctrl+Alt+S to open the IDE settings and select Version Control | GitHub.
In the dialog that opens, specify your GitHub server URL (either github.com, or an enterprise instance).
Do one of the following:
If you already have a token, click the Use Token link and paste it there.
If you want to obtain a new token, enter your login and password. If you have two-factor authentication enabled, you will be asked to enter a code that will be sent to you by SMS or through the mobile application. See Creating a personal access token for more details on GitHub tokens.
The token must have the repo, the gist and the read:org scopes enabled in your account permissions (see Understanding scopes).
After all the necessary plugins are installed, you need to enable the VCS integration in the IDE.
Enable version control integration
Clickon the menu bar.
In the Enable Version Control Integration dialog, ensure that
Gitis selected in the drop-down list and click OK.
Now clone the repository from GitHub to your local machine.
In the URL field, type the URL for your repository (for example,
In the Directory field, click the folder icon () and specify a directory for the repository files (for example, /Users/jetbrains/DataGripProjects/mySQLiteDDL).
In the Open Project dialog, click Attach.
The repository folder will appear in the Files tool window.
Prepare a DDL data source
When all the configuration with VCS is done, you can start preparing your DDL data source.
Dump an existing data source to a DDL data source
In the Database Explorer ( ), right-click a data source that you want to dump to a DDL data source and select .
To configure code settings for the DDL data source, see Configuring DDL generation settings.
In the Data Sources and Drivers dialog, select the DDL data source, and click Add directories or DDL files.
In the file browser, navigate to the directory that will store DDL files of a data source and click Open.
When you dump files to a DDL data source, the folder with these SQL files is automatically attached in the Files tool window.
Add a DDL mapping
Open data source properties. You can open data source properties by using one of the following options:
In the Database Explorer ( ), click the Data Source Properties icon .
Click the DDL Mappings tab.
Alternatively, you can get to this tab by clicking a data source in the Database Explorer ( ) and selecting .
Click the <Choose Data Source> for Data Source.
Click the <Choose Data Source> for DDL Data Source.
In the Scope tree, select schemas or databases that will be used in the mapping (for example,
Share your changes from a data source
This workflow might help you if you made changes to your data source and want to share it in the VCS. For example, let's add a new table (
actor_1) to our SQLite data source.
Update a DDL data source from a data source
In the Database Explorer ( ), right-click a DDL data source and select .
Commit and push your changes to VCS
Open the vertical Commit tool window Alt+0 located on the left.
As your changes are ready to be committed, select the corresponding files or an entire changelist.
If you press Ctrl+K, the entire active changelist will be selected.
Enter the commit message. You can click to choose from the list of recent commit messages.
To push changes from the current branch, press Ctrl+Shift+K or choose from the main menu.
Get changes from VCS and apply them to your data source
Otherwise, update a local copy of the repository and migrate changes.
In the Branches popup or in the Branches pane of the Version Control tool window, select a branch and choose Update from the context menu.
DataGrip will pull changes from the remote branch and will rebase or merge them into the local branch depending on which update method is selected in .
Migrate changes to a data source
In the Database Explorer ( ), right-click a data source and select .
In the Migration dialog, modify scripts generated in the Script Preview tab. Leave only those scripts that you plan to execute.
All actions for files are available on DDL data source elements as well. For example, you can delete, copy, or commit files related to the schema elements from the Database Explorer.
Automatically refresh a DDL data source when you change the corresponding files
If the Auto-sync option is turned on, the DDL data source will be automatically refreshed with changes to the corresponding files. This was already the default behavior, but now you have the option to disable it.
Initial search path
On the New File Layout tab, you can define names for your database and schemas, which will be displayed in the DDL data source. DDL scripts do not usually contain names, and in these cases, there will be dummy names for databases and schemas by default.