How can I populate Liquibase parameter values from an external properties file?

amoe

Is there any way that I can populate parameters in a Liquibase changelog file based on the contents of an external property file?

As in, I would like to be able to say:

<createTable tableName="${table.name}">
     <column name="id" type="int"/>
     <column name="${column1.name}" type="varchar(${column1.length})"/>
     <column name="${column2.name}" type="int"/>
</createTable>

And keep the value of table.name and the other parameters in an external file db.properties, and reference this file either from within the changelog, or from the Liquibase command line, or as an option of the Maven plugin that runs liquibase.

I can't seem to find any way to do this, is it possible?

Wooff

Do that at compile time: sounds like job for maven filters and/or profiles

NOTE: be carefull with liquibase and any "marker" replacements... liquibase stores CRC of applied changessets

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>test</groupId>
    <artifactId>test</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <build>
        <filters>
            <filter>src/main/filters/liquibase.properties</filter>
        </filters>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
                <includes>
                    <include>liquibase.xml</include>
                </includes>
            </resource>
        </resources>
    </build>
</project>

/src/main/filters/liquibase.properties

table.name=TABLE_NAME
column1.name=COLUMN1_NAME
column1.length=10
column2.name=COLUMN2_NAME

/src/main/resources/liquibase.xml

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<databaseChangeLog logicalFilePath="liquibase.xml" xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-2.0.xsd">

    <changeSet author="me" id="changeSetId1">
        <comment>Test</comment>

        <createTable tableName="${table.name}">
            <column name="id" type="int" />
            <column name="${column1.name}" type="varchar(${column1.length})" />
            <column name="${column2.name}" type="int" />
        </createTable>
    </changeSet>

</databaseChangeLog>

EDIT: A typical invocation (using filtered resources) would look like this: mvn resources:resources liquibase:update or more preferably use profiles... mvn resources:resources liquibase:update -P<profile_name>

EDIT2: There is one big advantage of this way of defining columns. You could use this property's (e.g.: column1.length) value (e.g.: 10) for validation of every layer: Hibernate, DAO, WEB, faces, JavaScript. Just use this property at each place where you need to validate against it. Even in i18n/messages.properties if needed (e.g.: input1.validation=No more than ${column1.length} letters.).

The only complication is that if you need to change this value you need to provide proper liquibase update/rollback script. Sometimes it is possible to change value and set new liquibase checksum (safe operation like increase varchar length), but other times you need to create a safe update changescript using new property/value.

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Why I can't reach form properties from another file?

来自分类Dev

How can I populate an existing object from a JToken (using Newtonsoft.Json)?

来自分类Dev

How can I loop through values in my json file?

来自分类Dev

how to read gcc input from external file

来自分类Dev

How can I populate more than one zendform?

来自分类Dev

Trying to populate a list in JQuery from a JSON file. How to debug?

来自分类Dev

How can I dynamically include external files / user control?

来自分类Dev

How can i get from a FileInfo[] the file full name full directory including the file extension?

来自分类Dev

How can I merge 2 input values from a form before performing a form action?

来自分类Dev

How to set diffChangeLogFile parameter when "mvn liquibase:diff"?

来自分类Dev

How to parse values from a JSON file in Python

来自分类Dev

liquibase.properties中的Liquibase changelog参数

来自分类Dev

How can I read float data from a binary file using R

来自分类Dev

How can I prevent a PDF file from being downloaded or printed with PHP or JavaScript?

来自分类Dev

knockoutjs - How can I populate an empty observable array in response to user action (anchor link click)

来自分类Dev

How can I add a custom Parameter to a box in maxscript?

来自分类Dev

How can I used ReadAllLines with gzipped file

来自分类Dev

How can I extract text from images?

来自分类Dev

how to read items from file into a list of items and set the properties to the value in the file?

来自分类Dev

How can I add values through XML in OpenERP7?

来自分类Dev

How can a textfield from fxml file be updated by setText in java file?

来自分类Dev

Can i read from .ini file which located in resources files?

来自分类Dev

How to read float values from binary file using c#?

来自分类Dev

ServiceStack OrmLite How can I achieve automatic setting of foreign key/related properties?

来自分类Dev

How can I have both res/values-pt_PT and res/values-pt_BR on Android?

来自分类Dev

Where to store properties from properties file in java webapp

来自分类Dev

How can I print contents of file given filename as stdin in bash?

来自分类Dev

Using Gradle, how can I ensure that a file exists at a certain location?

来自分类Dev

How to parse a text file (CSV) into haskell so I can operate on it?

Related 相关文章

  1. 1

    Why I can't reach form properties from another file?

  2. 2

    How can I populate an existing object from a JToken (using Newtonsoft.Json)?

  3. 3

    How can I loop through values in my json file?

  4. 4

    how to read gcc input from external file

  5. 5

    How can I populate more than one zendform?

  6. 6

    Trying to populate a list in JQuery from a JSON file. How to debug?

  7. 7

    How can I dynamically include external files / user control?

  8. 8

    How can i get from a FileInfo[] the file full name full directory including the file extension?

  9. 9

    How can I merge 2 input values from a form before performing a form action?

  10. 10

    How to set diffChangeLogFile parameter when "mvn liquibase:diff"?

  11. 11

    How to parse values from a JSON file in Python

  12. 12

    liquibase.properties中的Liquibase changelog参数

  13. 13

    How can I read float data from a binary file using R

  14. 14

    How can I prevent a PDF file from being downloaded or printed with PHP or JavaScript?

  15. 15

    knockoutjs - How can I populate an empty observable array in response to user action (anchor link click)

  16. 16

    How can I add a custom Parameter to a box in maxscript?

  17. 17

    How can I used ReadAllLines with gzipped file

  18. 18

    How can I extract text from images?

  19. 19

    how to read items from file into a list of items and set the properties to the value in the file?

  20. 20

    How can I add values through XML in OpenERP7?

  21. 21

    How can a textfield from fxml file be updated by setText in java file?

  22. 22

    Can i read from .ini file which located in resources files?

  23. 23

    How to read float values from binary file using c#?

  24. 24

    ServiceStack OrmLite How can I achieve automatic setting of foreign key/related properties?

  25. 25

    How can I have both res/values-pt_PT and res/values-pt_BR on Android?

  26. 26

    Where to store properties from properties file in java webapp

  27. 27

    How can I print contents of file given filename as stdin in bash?

  28. 28

    Using Gradle, how can I ensure that a file exists at a certain location?

  29. 29

    How to parse a text file (CSV) into haskell so I can operate on it?

热门标签

归档