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

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.

Update one row in the table, using liquibase

The above answers are overly complicated, for most cases this is enough: <changeSet author=”name” id=”123″> <update tableName=”SomeTable”> <column name=”PropertyToSet” value=”1″ /> <where>otherProperty = ‘otherPropertyValue'</where> </update> </changeSet> important to use single quotes ‘ and not double quotes ” in the WHERE clause.

Liquibase or Flyway database migration alternative for Elasticsearch

From this point of view/need, ES have a huge limitations: despite having dynamic mapping, ES is not schemaless but schema-intensive. Mappings cant be changed in case when this change conflicting with existing documents (practically, if any of documents have not-null field which new mapping affects, this will result in exception) documents in ES is immutable: … Read more

Liquibase: How to set the default value of a date column to be “now” in UTC format?

Maybe this topic in the liquibase forum will help? I think defaultValueComputed will take a database specific function to express “now”. In mySQL it would be CURRENT_TIMESTAMP so it could look like this: <createTable tableName=”D_UserSession”> <column name=”ts” type=”TIMESTAMP” defaultValueComputed=”CURRENT_TIMESTAMP”/> </createTable> (Copied from the forum post.)

Java code changeset in liquibase

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 ! … Read more

Liquibase: How to Set Foreign Key(s) Constraint in Column Tag?

Use a nested <constraints> tag in your column tag. Example: <changeSet id=”SAMPLE_1″ author=”alice”> <createTable tableName=”employee”> <column name=”id” type=”int” autoIncrement=”true”> <constraints primaryKey=”true”/> </column> <column name=”first_name” type=”varchar(255)”/> <column name=”last_name” type=”varchar(255)”> <constraints nullable=”false”/> </column> </createTable> </changeSet> <changeSet id=”create address table” author=”bob”> <createTable tableName=”address”> <column name=”id” type=”int” autoIncrement=”true”> <constraints primaryKey=”true”/> </column> <column name=”line1″ type=”varchar(255)”> <constraints nullable=”false”/> </column> <column name=”line2″ … Read more