Copy and Share Data Sources in IntelliJ-based IDEs
In this tutorial we’re going to look at three popular use-cases:
— Duplicate a data source within one project.
— Share data sources between projects inside one IDE.
— Copy a data source from one IDE to another IDE, or to another computer.
Duplicate a data source within one project
A trivial problem deserves a trivial solution: in the context menu of the selected data source, click Duplicate or press Ctrl/Cmd+D.
A new data source will be created with the same properties, including the password.
Share data sources between projects inside one IDE
In IntelliJ-based IDEs, a data source can be global. This means it becomes visible from all projects you run from a particular IDE. By default, data sources are local. To make a data source global, click the corresponding button in the toolbar (or the context menu).
If you want to make it local again, click the button again.
Global data sources are visible in all projects you open from the same version of the same IDE. Say, if you use DataGrip 2020.1, global data sources will not be visible from projects you open in other versions of DataGrip or in IntelliJ IDEA.
Copy a data source from one IDE to another IDE, or to another computer
Global data sources can be copied via Export Settings. But what if you don’t want to export all settings? And what if you don’t use global data sources?
The first and the most convenient way to copy data sources to another IDE: select the ones you need and in the context menu choose Database tools → Copy data source to clipboard.
In fact, XML is copied to the clipboard like in the following example:
You can send this snippet to your colleague via a messenger, or just import it to another IDE on your machine. To do this, click Add data source (+) → Import from clipboard.
The datasource is copied without a password, so you’ll need to input it manually. DataGrip stores passwords in the KeePass storage on Windows and in native keychains on Linux and MacOS. You can configure the IDE to store passwords in KeePass on any OS: to do this go to Settings/Preferences → Appearance and behavior → System settings → Passwords.
If for some reason that flow doesn’t meet your needs, here comes something for advanced users.
DataGrip, like any other IDE from JetBrains, works in the context of a project. The entity of the project is not a thing that database developers are used to, which is why DataGrip creates a default project once you run the IDE. And you continue using this default project unless you create a new one.
The information on all data sources you have in a project is stored inside the dataSources.xml file inside this project.
Where is this default project located?
More information about the config folders is here.
If you created other projects than default, we assume you know where they are located. Anyway, if you go to File → Open Recent → Manage projects, you’ll see all projects with their paths except the opened one.
So, if you open a project from another IDE, it will contain all data sources without passwords. They are stored in \.idea\dataSources.xml
If you make any changes to this file, it will affect the data sources you use. It can be even placed under a VCS to synchronize the data sources list between several users.
You might also notice the dataSources.local.xml file where DataGrip stores schema visibility settings and some other information that can vary from user to user. If a data source becomes global, the information about it is stored in the options folder, which is located at the same level as the projects folder.
That’s it. Please comment if you have questions.