Schema comparison and migration
Enable the Database Tools and SQL plugin
This functionality relies on the Database Tools and SQL plugin, which is bundled and enabled in IntelliJ IDEA by default. If the relevant features are not available, make sure that you did not disable the plugin.
Press Ctrl+Alt+S to open settings and then select
.Open the Installed tab, find the Database Tools and SQL plugin, and select the checkbox next to the plugin name.
In IntelliJ IDEA, you can compare two database objects of the same type. For example, you can compare two schemas, two tables, or two routines. Databases with objects can be hosted on different servers. IntelliJ IDEA shows you the differences in the structures of these two objects in the Migration dialog.
Migration is a process of transferring structure and changes from one object to another (for example, from one schema to another). In IntelliJ IDEA, these objects are called Origin and Target. The migration script is generated to make Target equal to Origin. But you can modify the script to satisfy your requirements.
For changes, IntelliJ IDEA uses the following color coding.
Color | Description |
---|---|
Objects added in Origin, which will be created in Target in case of a successful migration. | |
Modified objects, which will be altered in Target. | |
Objects deleted in Origin, which will be dropped in Target in case of a successful migration. |
See the description of the dialog controls in the reference section.
Schema comparison
Show differences between objects
In the Database tool window ( ) , select two objects of the same type. For example, two schemas.
Right-click the selection and navigate to
. Alternatively, press Ctrl+D.
Show differences between changes in a table form
In the Migration dialog, click an item in Origin or Target fields.
Click the Object Properties Diff tab.
Show differences between changes in DDL
In the Migration dialog, click an item in Origin or Target fields.
Click the DDL Diff tab.
Show identical items
To display all items that are identical in Origin and Target objects, select the Show identical checkbox.
Schema migration
Migrate changes between objects
In the Database tool window ( ) , select two objects of the same type. For example, two schemas.
Right-click the selection and navigate to
. Alternatively, press Ctrl+D.A set of statements that you can use for writing migration scripts is generated in the Script Preview tab.
In the Script Preview tab, verify that the migration scripts are correct.
Click Execute. Alternatively, click Open Query in Console to open all the scripts in a query console.
Select changes to migrate
To exclude a change, click the checkbox neat the change.
To exclude all the changes, click the checkbox near the Target label.
To include all the changes that were excluded, click the checkbox near the Target label.
Controls of the Migration dialog
Icon | Tooltip and shortcut | Description |
---|---|---|
Expand All | Expands all the collapsed nodes. | |
Collapse All | Collapses all the expanded nodes. | |
Swap | Swap the Origin and Target panels. | |
Options | Select options according to which changes are differentiated. If the option is selected, properties that are mentioned in the option are ignored in the diff.
| |
Include change | Apply the selected change. | |
Show identical | Show all items that are identical. |
Controls of DDL Diff
Item | Tooltip and Shortcut | Description |
---|---|---|
/ | Previous Difference/Next Difference Shift+F7/F7 | Jump to the next or previous difference. |
Jump to Source F4 | Open a definition of the selected object in the active pane in the editor. The caret is placed in the same position as in the Diff Viewer. | |
Side-by-side viewer | Select a viewer mode: Side-by-side viewer or Unified viewer. The side-by-side mode has two panels, and the unified mode has one panel. | |
Whitespaces | Define how the Diff Viewer should treat whitespaces.
| |
Highlighting mode | Select the way differences are highlighted. The available options are:
| |
Synchronize Scrolling | Synchronize scrolling in the left and right panes. | |
Settings | Select options that you want to ignore during the comparison.
| |
Help F1 | Open a browser and show the corresponding help page. |