News

Copy and Share Data Sources in IntelliJ-based IDEs

800x418_Twitter_DG_DataCopy2

Hello,

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.

Duplicate

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).

MakeGlobal

If you want to make it local again, click the button again.

MoveToProject

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

UPD: Starting from version 2021.1 you can:

  • Select the needed data soucres.
  • Copy them via Ctr/Cmd+C.
  • Paste them in the needed IDE via Ctrl/Cmd+V.
  • If the target IDE is on the another computer, just use the XML clipboard value produced on the step two.

—————————

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.

CopyToClipboard

In fact, XML is copied to the clipboard like in the following example:

XML

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.

ImportFromClipboard

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.

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?

Windows
%APPDATA%\Roaming\JetBrains\%product%%version%\projects

Linux
~/.config/JetBrains/<product><version>/projects

MacOS
~/Library/Application Support/JetBrains/<product><version>/projects

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

dataSourcesXML

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.

image description

Discover more