amo*_*moe 5 java liquibase maven
有什么方法可以根据外部属性文件的内容填充 Liquibase 变更日志文件中的参数吗?
就像,我想说:
<createTable tableName="${table.name}">
<column name="id" type="int"/>
<column name="${column1.name}" type="varchar(${column1.length})"/>
<column name="${column2.name}" type="int"/>
</createTable>
Run Code Online (Sandbox Code Playgroud)
table.name并将和其他参数的值保留在外部文件中db.properties,并从变更日志中、从 Liquibase 命令行或作为运行 liquibase 的 Maven 插件的选项来引用该文件。
我似乎找不到任何方法来做到这一点,有可能吗?
在编译时执行此操作:听起来像是 Maven过滤器和/或配置文件的工作
注意:小心 liquibase 和任何“标记”替换... liquibase 存储应用变更集的 CRC
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>
Run Code Online (Sandbox Code Playgroud)
/src/main/filters/liquibase.properties
table.name=TABLE_NAME
column1.name=COLUMN1_NAME
column1.length=10
column2.name=COLUMN2_NAME
Run Code Online (Sandbox Code Playgroud)
/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>
Run Code Online (Sandbox Code Playgroud)
编辑:典型的调用(使用过滤的资源)将如下所示:
mvn resources:resources liquibase:update
或更优选地使用配置文件...
mvn resources:resources liquibase:update -P<profile_name>
EDIT2:这种定义列的方式有一个很大的优点。您可以使用此属性(例如:column1.length)值(例如:10)来验证每个层:Hibernate、DAO、WEB、faces、JavaScript。只需在需要验证的每个地方使用此属性即可。即使在 i18n/messages.properties 中(如果需要)(例如:input1.validation=不超过 ${column1.length} 个字母。)。
唯一的复杂之处是,如果您需要更改此值,您需要提供正确的 liquibase 更新/回滚脚本。有时可以更改值并设置新的 liquibase 校验和(安全操作,例如增加 varchar 长度),但其他时候您需要使用新属性/值创建安全更新更改脚本。
| 归档时间: |
|
| 查看次数: |
18610 次 |
| 最近记录: |