Java code changeset in liquibase

Pavel Bernshtam picture Pavel Bernshtam · Aug 16, 2012 · Viewed 23.8k times · Source

Is there a way in liquibase to create java code change set (i.e. provide a java class, which will receive a JDBC connection and will perform some changes in the database) ?

(I know that flyway has such feature)

Answer

poussma picture poussma · Aug 16, 2012

Yes, there is such feature. You can create a customChange:

    <customChange class="my.java.Class">
        <param name="id" value="2" />
    </customChange>

The class must implements the liquibase.change.custom.CustomTaskChange interface.

@Override
public void execute(final Database arg0) throws CustomChangeException {
    JdbcConnection dbConn = (JdbcConnection) arg0.getConnection();
    try {
         ... do funny stuff ...
    } catch (Exception e) {
        // swallow the exception !
    }
}