如何使用Liquibase更新嵌入式Glassfish实例中的数据库

时间:2014-04-22 13:25:50

标签: maven glassfish liquibase glassfish-embedded maven-glassfish-plugin

我正在将数据库管理转换为Liquibase。这很顺利。

作为后续步骤,我想确保在部署到常见环境之前对所有未来的修改进行测试,持续集成风格。我尝试使用以下设置执行此操作:

  • 构建包含EJB webservices的耳朵
  • 在预集成测试maven ohase期间使用maven-embedded-glassfish-plugin启动Glassfish 3的嵌入式实例
    • 创建我的数据源作为开始目标的一部分
    • 在部署目标期间部署耳朵
  • 仍在预集成测试中,我在同一个数据库URL上运行liquibase:update。在这种情况下是H2文件数据库
  • 然后我想在已部署的应用程序上运行SoapUI测试

但是当我到目前为止,应用程序无法在数据库中找到任何数据。所以问题是我是否在设置中遗漏了某些内容,或者是否有更好的方法来组织我的预期目标?

pom.xml,嵌入式Glassfish

  <plugin>
    <groupId>org.glassfish.embedded</groupId>
    <artifactId>maven-embedded-glassfish-plugin</artifactId>
    <version>4.0</version>
    <configuration>
      <ports>
        <http-listener>9090</http-listener>
        <https-listener>9191</https-listener>
      </ports>
      <goalPrefix>embedded-glassfish</goalPrefix>
      <app>${project.build.directory}/school-application-${project.version}.ear</app>
      <name>school-application</name>
      <commands>
        <command>create-jdbc-connection-pool --datasourceclassname=org.h2.jdbcx.JdbcDataSource --restype=javax.sql.DataSource --property URL=jdbc\:h2\:~/tmpLB\;AUTO_SERVER\=TRUE schoolDSPool</command>
        <command>create-jdbc-resource --connectionpoolid schoolDSPool jdbc/schoolDS</command>
      </commands>
    </configuration>
    <dependencies>
      <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
        <version>1.3.176</version>
      </dependency>
    </dependencies>
    <executions>
      <execution>
        <goals>
          <goal>start</goal>
          <goal>admin</goal>
          <goal>deploy</goal>
          <goal>undeploy</goal>
          <goal>stop</goal>
        </goals>
      </execution>
    </executions>
  </plugin>

pom.xml,Liquibase

  <plugin>
    <groupId>org.liquibase</groupId>
    <artifactId>liquibase-maven-plugin</artifactId>
    <version>3.1.1</version>
    <dependencies>
      <dependency>
        <groupId>company.school</groupId>
        <artifactId>school-db</artifactId>
        <version>${project.version}</version>
        <systemPath>../school-db/target</systemPath>
        <type>jar</type>
      </dependency>
      <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
        <version>1.3.176</version>
      </dependency>
    </dependencies>
    <executions>
      <execution>
        <phase>integration-test</phase>
        <configuration>
          <promptOnNonLocalDatabase>false</promptOnNonLocalDatabase>
          <changeLogFile>db.changelog-master.xml</changeLogFile>
          <driver>org.h2.Driver</driver>
          <url>jdbc:h2:~/tmpLB;AUTO_SERVER=TRUE</url>
          <logging>info</logging>
        </configuration>
        <goals>
            <goal>update</goal>
        </goals>
      </execution>
    </executions>
  </plugin>

我在更改日志中有一个变更集,在目标表中插入数据。

  1. 我是否设置了正确的用户?
  2. 有没有办法在与Glassfish相同的过程中运行Liquibase并改为使用mem:数据库?
  3. 感谢和问候, 基督教

1 个答案:

答案 0 :(得分:0)

好的,所以有一个&#34; easy&#34;解决问题。

数据库中没有数据,因为liquibase changelog中的更改集无法完成。我在一个单独的sql文件中使用了<sqlFile> liquibase标记调用了insert语句。但插入内容违反了一些外键约束,并没有被执行。

所以让我失望的是,Liquibase似乎隐藏了包含的sql文件中的任何错误。如果我成功的话,试着尝试重现那个和Jira吧。

/基督教

相关问题