Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can liquibase have configuration placeholders in sql

Can liquibase have configuration placeholders in sql?

Example code:

<changeSet author="name" id="sql-example" runAlways="true" failOnError="true">
    <sql>SELECT schema.admin_insert('PARAMETER_PLACEHOLDER')</sql>
</changeSet>

Can I define parameter value in properties file; so that liquibase replace the value of the argument from a properties file ?

like image 761
Vibin Avatar asked Mar 04 '16 19:03

Vibin


People also ask

What is Liquibase formatted SQL?

Liquibase (LB) is an open source tool written in Java. It makes defining database changes easy, in a format that's familiar and comfortable to each user. Then, it automatically generates database-specific SQL for you. Database changes (every change is called changeset) are managed in files called changelogs.

What is a change set in Liquibase?

The changeset tag is a unit of change that Liquibase executes on a database and which is used to group database Liquibase Change Types together. A list of changes created by multiple changesets are tracked in a changelog.

Can Liquibase create a schema?

In Liquibase there is no "create schema" tag, because it is designed to manage objects within the application's schema. However, we can use a custom SQL statement inside a 'sql' tag to make a creation of a schema a part of our migration.


1 Answers

Yes, you can. Liquibase calls these "Changelog Parameters"

http://www.liquibase.org/documentation/changelog_parameters.html

A short excerpt from that page:

Liquibase allows dynamic substitution of parameters in a changelog. The parameters to replace are described using the ${parameterName} syntax.

Configuring parameter values

Parameter values are looked up in the following order:

  • Passed as a parameter to your Liquibase runner (see Ant, command_line, etc. documentation for how to pass them)
  • As a JVM system property
  • In the parameters block (<property> Tag) of the DatabaseChangeLog file itself.

Example

<createTable tableName="${table.name}">
      <column name="id" type="int"/>
      <column name="${column1.name}" type="varchar(${column1.length})"/>
      <column name="${column2.name}" type="int"/> 
</createTable>
like image 135
SteveDonie Avatar answered Sep 28 '22 23:09

SteveDonie