2017-02-27 120 views
1

我目前在解決以下問題:我有一個Java EE應用程序,並希望使用Liquibase作爲數據庫遷移工具。問題是我有多租戶模式,每個租戶都有自己的模式。目前,我正在使用生產者開始更新,但不知道如何將其配置爲使用不同的架構。多租戶架構與Liquibase

我發現Spring有一些解決方案(請參閱MultiTenantSpringLiquibase獲取更多詳細信息)。但是,Java EE沒有解決方案。也許唯一的解決方案是編寫自定義Liquibase servlet偵聽器。

任何幫助的感謝和問候,艾爾諾

回答

0

如果你有不同的模式名稱爲每個租戶,可能比你想使用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> 

您可以隨時使用的參數用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> 

希望,這可能幫你。