REUNICO | Digital transformation laboratory. Certified partner of Camunda: Liquibase for the database scheme conversion

Liquibase for the database scheme conversion

Many users have heard of Liquibase, an open source library (Apache 2.0 License) that allows you to store, track, and apply database changes. And someone, for sure, used it for the database refactoring. Today we will talk about the unusual usage of such utility - the conversion of the database scheme.

During the process of developing any software (especially if it was originally developed to meet the requirements of a particular customer), sooner or later the question of moving the functionality to another platform may arise.
Liquibase

                         

Can your application store data in MS SQL Server? We do not have the opportunity to hire a separate DBA to maintain PostgreSQL!

Annoying Customer

Let's convert the data model in Oracle Data Modeler format!

Data Analyst

Its good if the solution was initially designed to use may different RDBMS. Or the DBMS has the ability to store data in an external database (such as OpenEdge Data Server for Oracle). But what about the others? Looking for a solution on the Internet? Is it possible to write a converter by itself, by mapping tables and fields, by matching data types?

The Liquibase library, designed for managing the version of the database, can help the developer.

Liquibase

With Liquibase, it is enough to create an initial snapshot of the database schema in XML format, which can then be uploaded as an SQL dump.

The following is an example for the PostgreSQL database that migrates to Oracle.

  1. Download liquibase: http://download.liquibase.org, unpack. The utility is cross-platform, written in Java.

    Those who want to use Liquibase as part of their own solution can clone the project with GitHub (https://github.com/liquibase)
  2. . If necessary, slip the necessary JDBC drivers into lib directory. The list of supported RDBMS .
  3. Generate changelog of source database:

    ./liquibase --url=jdbc:postgresql://127.0.0.1:5432/demo \
        --driver=org.postgresql.Driver --username="user" \
        --password="password" \
        --changeLogFile=demo.changelog.xml generateChangeLog
                 
  4. Based on the generated changelog-file, create a backup in the SQL format:
    ./liquibase --url=offline:oracle --changeLogFile=demo.changelog.xml updateSQL > changelog.sql
                
  5. The tagrget schema is ready. Please note that this method does not convert stored procedures and triggers.