简体   繁体   English

sql-maven-plugin:清理多个数据库?

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

I would like to clean and fill two different databases for integration testing with a Maven project. 我想清理并填充两个不同的数据库,以便与Maven项目进行集成测试。 I use the sql-maven-plugin , but I wasn't able to make it handle different databases (I can have only one plugin declaration for the sql-maven-plugin , and the configuration is shared between its executions ). 我使用sql-maven-plugin ,但是无法使它处理不同的数据库( sql-maven-plugin只能有一个插件声明,并且configurationexecutions之间共享)。

How do you guys solve that? 你们如何解决呢? Is there any workaround to solve this issue? 有没有解决此问题的方法?

Thanks in advance! 提前致谢!

You can simply define all of the configuration within each individual execution section and configure as required. 您可以简单地在每个execution部分中定义所有configuration ,然后根据需要进行配置。 Instead of having a shared configuration. 而不是共享配置。

So here is an example to connect to two different HSQLDB databases: 因此,以下是连接到两个不同的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