簡體   English   中英

sql-maven-plugin:清理多個數據庫?

[英]sql-maven-plugin: clean multiple databases?

我想清理並填充兩個不同的數據庫,以便與Maven項目進行集成測試。 我使用sql-maven-plugin ,但是無法使它處理不同的數據庫( sql-maven-plugin只能有一個插件聲明,並且configurationexecutions之間共享)。

你們如何解決呢? 有沒有解決此問題的方法?

提前致謝!

您可以簡單地在每個execution部分中定義所有configuration ,然后根據需要進行配置。 而不是共享配置。

因此,以下是連接到兩個不同的HSQLDB數據庫的示例:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>sql-maven-plugin</artifactId>
    <version>1.5</version>

    <dependencies>
      <dependency>
        <groupId>org.hsqldb</groupId>
        <artifactId>hsqldb</artifactId>
        <version>2.2.9</version>
      </dependency>
      <!-- you could add dependencies to other database drivers here -->
    </dependencies>

    <executions>
      <!-- execution against database 1 -->
      <execution>
        <id>database1</id>
        <phase>process-test-resources</phase>
        <goals>
          <goal>execute</goal>
        </goals>
        <!-- specific configuration for execution against database1 -->
        <configuration>
          <driver>org.hsqldb.jdbcDriver</driver>
          <url>jdbc:hsqldb:hsql://localhost:9999/database1</url>
          <username>sa</username>
          <password></password>
          <sqlCommand>select count(TYPE_NAME) from INFORMATION_SCHEMA.SYSTEM_TABLES</sqlCommand>
        </configuration>
      </execution>
      <!-- execution against database 2 -->
      <execution>
        <id>database2</id>
        <phase>process-test-resources</phase>
        <goals>
          <goal>execute</goal>
        </goals>
        <!-- specific configuration for execution against database2 -->
        <configuration>
          <driver>org.hsqldb.jdbcDriver</driver>
          <url>jdbc:hsqldb:hsql://localhost:8888/database2</url>
          <username>sa</username>
          <password></password>
          <sqlCommand>select count(TYPE_NAME) from INFORMATION_SCHEMA.SYSTEM_TABLES</sqlCommand>
        </configuration>
      </execution>
    </executions>
  </plugin>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM