Using liquibase on the existing database

The process to put a existing database under liquibase control is the following: Create the initial changelog (that’s what you did) Run liquibase using the command changelogSync. This will create the Liquibase tables and mark all change sets as being applied (this is what you missed) Add your change sets Run liquibase using the command … Read more

How to get liquibase to log using slf4j?

There is, but it is a little bit obscure. Quoting Fixing liquibase logging with SLF4J and Log4J: There’s The Easy Way, by dropping in a dependency: <!– your own standard logging dependencies –> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.7.5</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId><!– or log4j2 or logback or whatever–> <version>1.7.5</version> </dependency> <!– special dependency to fix liquibase’s … Read more

Liquibase error [Postgresql]: unterminated dollar-quoted string at or near “$BODY$

I just encountered the same issue days ago. It does not work if we add the changeset into changelog.xml file using the format below: <include file=”path/to/sqlfile” /> To work around, I use another format: <changeSet author=”authour_name” id=”your_id”> <sqlFile path=”path/to/sqlfile” splitStatements=”false”/> </changeSet> Here is the link which gives a brief explanation to Problem with dollar-quoted-in-postgresql.

Flyway and liquibase together? [closed]

A small correction, before I answer question. The assumption Liquibase seems to have everything Flyway has isn’t correct. Flyway shines when it comes to parsing SQL. You can use unmodified SQL files generated by your native tools containing all kinds of complexity like PL/SQL packages and procedures, MySQL delimiter changes, T-SQL, PostgreSQL procedures, … With … Read more

Hibernate using JPA (annotated Entities) and liquibase

Yes, Liquibase uses hibernate’s metadata classes, which are the same whether you use xml mappings or annotations. You do need a hibernate config file to point liquibase to, but your mappings can be xml or jpa annotations. More information can be found at https://github.com/liquibase/liquibase-hibernate/wiki but you can use “database urls” such as hibernate:classic:com/example/hibernate.cfg.xml if you … Read more

How to work with liquibase, a concrete example

You should never modify a <changeSet> that was already executed. Liquibase calculates checksums for all executed changeSets and stores them in the log. It will then recalculate that checksum, compare it to the stored ones and fail the next time you run it if the checksums differ. What you need to do instead is to … Read more

liquibase : Insert current date

What you you will have to do is use changelog parameters and define a “now” or “current_timestamp” parameter that is replaced per database type. At the top of your <databaseChangeLog>, normally just outside your <changeset>, add per-database definitions of the property like: <property name=”now” value=”sysdate” dbms=”oracle”/> <property name=”now” value=”now()” dbms=”mysql”/> <property name=”now” value=”now()” dbms=”postgresql”/> then … Read more

Running liquibase within Java code

It should be something like (taken from liquibase.integration.spring.SpringLiquibase source): java.sql.Connection c = YOUR_CONNECTION; Liquibase liquibase = null; try { Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(c)) liquibase = new Liquibase(YOUR_CHANGELOG, new FileSystemResourceAccessor(), database); liquibase.update(); } catch (SQLException e) { throw new DatabaseException(e); } finally { if (c != null) { try { c.rollback(); c.close(); } catch (SQLException … Read more

tech