KS DB Merge Tools logo KS DB Merge Tools
database diff & merge
KS DB Merge Tools for PostgreSQL logo for PostgreSQL
 
KS DB Merge Tools for Oracle logo
KS DB Merge Tools for MySQL logo
MssqlMerge logo
KS DB Merge Tools for SQLite logo
AccdbMerge logo
KS DB Merge Tools for Cross-DBMS logo
KS DB Merge Tools All-In-One license

Automation and Scripting

KS DB Merge Tools for PostgreSQL can do a lot of database diff and merge tasks without user interaction. It has its own scripting language, designed to automate the most common tasks.

For example, you need to create a continuous integration (CI) nightly build that checks for schema changes between your Dev server database and Staging database. Such a report could be easily generated using KS DB Merge Tools for PostgreSQL GUI: we just need to get schema changes summary (see Schema changes summary use case). Then using the toolbar we need to apply a 'New and Changed' filter and then do Export. But all these actions should be done by someone, that's not applicable for our task that should be done without user interaction.

Let's automate this task. Open Script Editor application:

for PostgreSQL, click query result diff

As recommended in the sample script comments, 1 update connection strings, script log and json report file paths. Script sample already contains required command to generate schema summary report, if you need some other actions - please check the documentation. Сlick 2 to check the script and make sure the Result panel has no errors. If so, click 3 to run the script and check its execution result:

for PostgreSQL, check script editor result

4 'EXIT CODE: 0' and missing errors means successful execution. Note that now 5 log file and 6 report file paths are changed into hyperlinks, and you can click those links to open these files.

For many typical diff & merge tasks such a script can be generated automatically. For example, you can open databases (see Schema changes summary use case) and generate schema changes summary report script using 7'Generate automation script stub' toolbar button:

for PostgreSQL, generate automation script on Home

This button generates script for the current tab, it already contains your database names and all you have to do is 8setup passwords, log and report file paths:

for PostgreSQL, generated automation script stub

Once your script is ready, select and copy text of your script, paste it into some text editor and save as file with *.ksdms extension. Now, assuming that you have KS DB Merge Tools for PostgreSQL installed on CI server, you can create a task in your CI pipeline that would run the following command:

"c:\Program Files (x86)\KS DB Merge Tools for PostgreSQL\PgsqlMergeCmd.exe" "c:\temp\schemaDiff.ksdms"

where PgsqlMergeCmd.exe argument should be a real path to your *.ksdms file.