Database 具有Liquibase的多租户模式
我目前正在解决以下问题:我有一个JavaEE应用程序,希望使用Liquibase作为DB迁移工具。问题是我有多租户模型,每个租户都有自己的模式。目前,我正在使用生产者启动更新,但不确定如何配置它以使用不同的模式 我发现Spring有一些解决方案(有关更多详细信息,请参阅MultitenantsSpringLiquibase)。但是,没有针对JavaEE的解决方案。也许唯一的解决方案是编写定制的Liquibase servlet侦听器Database 具有Liquibase的多租户模式,database,jakarta-ee,database-migration,liquibase,Database,Jakarta Ee,Database Migration,Liquibase,我目前正在解决以下问题:我有一个JavaEE应用程序,希望使用Liquibase作为DB迁移工具。问题是我有多租户模型,每个租户都有自己的模式。目前,我正在使用生产者启动更新,但不确定如何配置它以使用不同的模式 我发现Spring有一些解决方案(有关更多详细信息,请参阅MultitenantsSpringLiquibase)。但是,没有针对JavaEE的解决方案。也许唯一的解决方案是编写定制的Liquibase servlet侦听器 感谢您的帮助和问候,如果您为每个租户指定了不同的模式名称,那么
感谢您的帮助和问候,如果您为每个租户指定了不同的模式名称,那么您可能需要使用Maven liquibase插件 您可能希望为每个架构声明不同的执行,如下所示:
<build>
<plugins>
<plugin>
<!--NOTE: clearCheckSums=true attribute will make the changesets run only once.
The runOnChange attribute added to changesets will not work as originally intended.-->
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>${database.liquibase.version}</version>
<executions>
<execution>
<id>admin-schema-database-update</id>
<phase>process-resources</phase>
<configuration>
<changeLogFile>admin-schema.db.changelog-master.xml</changeLogFile>
<driver>${database.driver}</driver>
<contexts>${database.liquibasecontext}</contexts>
<url>${database.server.url}</url>
<username>${database.adminschema.username}</username>
<password>${database.adminschema.password}</password>
<promptOnNonLocalDatabase>false</promptOnNonLocalDatabase>
<outputDefaultSchema>true</outputDefaultSchema>
<verbose>true</verbose>
<logging>${database.liquibase.logging}</logging>
<propertyFileWillOverride>false</propertyFileWillOverride>
</configuration>
<goals>
<goal>update</goal>
</goals>
</execution>
<execution>
<id>user-schema-database-update</id>
<phase>process-resources</phase>
<configuration>
<changeLogFile>user-schema.db.changelog-master.xml</changeLogFile>
<driver>${database.driver}</driver>
<contexts>${database.liquibasecontext}</contexts>
<url>${database.server.url}</url>
<username>${database.username}</username>
<password>${database.password}</password>
<promptOnNonLocalDatabase>false</promptOnNonLocalDatabase>
<outputDefaultSchema>true</outputDefaultSchema>
<verbose>true</verbose>
<logging>${database.liquibase.logging}</logging>
<propertyFileWillOverride>false</propertyFileWillOverride>
</configuration>
<goals>
<goal>update</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.liquibase.ext</groupId>
<artifactId>liquibase-mssql</artifactId>
<version>1.3.0</version>
</dependency>
<dependency>
<groupId>org.liquibase.ext</groupId>
<artifactId>liquibase-oracle</artifactId>
<version>3.1</version>
</dependency>
</dependencies>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>**/*.xml</include>
<include>**/*.csv</include>
<include>**/*.sql</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
<excludes>
<exclude>**/*.xml</exclude>
<exclude>**/*.csv</exclude>
<exclude>**/*.sql</exclude>
</excludes>
</resource>
</resources>
</build>
org.liquibase
liquibase maven插件
${database.liquibase.version}
管理模式数据库更新
过程资源
admin-schema.db.changelog-master.xml
${database.driver}
${database.liquibasecontext}
${database.server.url}
${database.adminschema.username}
${database.adminschema.password}
假的
真的
真的
${database.liquibase.logging}
假的
更新
用户模式数据库更新
过程资源
user-schema.db.changelog-master.xml
${database.driver}
${database.liquibasecontext}
${database.server.url}
${database.username}
${database.password}
假的
真的
真的
${database.liquibase.logging}
假的
更新
org.liquibase.ext
液化mssql
1.3.0
org.liquibase.ext
液化甲骨文
3.1
src/main/resources
真的
**/*.xml
**/*.csv
**/*.sql
src/main/resources
假的
**/*.xml
**/*.csv
**/*.sql
始终可以将参数化构建与Maven一起使用,添加默认值如下:
<properties>
<liquibase.clearCheckSums>true</liquibase.clearCheckSums>
<database.username>userSchema</database.username>
<database.password>myUserPassword</database.password>
<database.adminschema.username>adminSchema</database.adminschema.username>
<database.adminschema.password>myAdminPassword</database.adminschema.password>
<database.liquibasecontext>!IntegrationTesting</database.liquibasecontext>
</properties>
真的
用户模式
myUserPassword
管理模式
myAdminPassword
!集成测试
希望这能对你有所帮助