Sunday, October 25, 2015

Liquibase in Action

Download the product from http://sourceforge.net/projects/liquibase/files/Liquibase%20Core/liquibase-3.1.1-bin.zip/download

Unzip it on your local drive

Type "liquibase" , you will get a pretty help. We learn that we have several areas:
Standard Commands (update, rollback..)
Diff commands
Maintenance Commands

We learn that some parameters are required (changeLogFile, username and pw, DB url) and other optional (drive, logfile...).

All the default parameters can be stored in liquibase.properties. More info here

vi liquibase.properties
driver: oracle.jdbc.OracleDriver
classpath: /opt/oracle/fmw11_1_1_5/wlserver_10.3/server/lib/ojdbc6.jar
url: jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=myrachost.acme.com)(PORT=1522))(CONNECT_DATA=(SERVICE_NAME=d01osb_app.acme.com)))
username: pl1_soainfra
password: pl1_acme
mkdir data
I try first an export:
java -jar liquibase.jar --changeLogFile="./data/myexportfile.xml" --diffTypes="data" generateChangeLog
you must provide an extension (.xml) in the filename, otherwise you get "Liquibase generateChangeLog Failed: No serializer associated with the filename or extension '/data/myexportfile'"

A sample entry generated is:
    <changeSet author="soa (generated)" id="1395989865665-193">
        <insert tableName="BPM_MEASUREMENT_ACTION_SEQ">
            <column name="SEQ_NAME" value="ACTION_SEQ"/>
            <column name="SEQ_COUNT" valueNumeric="0"/>
        </insert>
    </changeSet>


The changelog file is a huge file not very easy to read. If I do 2 subsequent changelogs, the differences are many even if schema/data are the same... not very intuitive.

Now I try:
java -jar liquibase.jar updateSQL
Errors:
--changeLogFile is required

I try again:
java -jar liquibase.jar --changeLogFile=./data/myexportfile.xml updateSQL


-- Changeset ./data/myexportfile.xml::1395989865665-193::soa (generated)
INSERT INTO PL1_SOAINFRA.BPM_MEASUREMENT_ACTION_SEQ (SEQ_NAME, SEQ_COUNT) VALUES ('ACTION_SEQ', 0);


INSERT INTO PL1_SOAINFRA.DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, LIQUIBASE) VALUES ('1395989865665-193', 'soa (generated)', './data/myexportfile.xml', SYSTIMESTAMP, 193, '7:f8ab8f75bd7c0bafd9cd43fd119e4340', 'insert', '', 'EXECUTED', '3.1.1');

so basically for each row in the DB (in this case it's a definition of a sequence, not a row) it produces the SQL and the reference to the changeset element.

No comments: