[英]Spring Boot Application Tests with H2 Database and Flyway Fails to Seed
I have an application I am trying to test using H2. 我有一个应用程序正在尝试使用H2进行测试。
Here's my application.yml: 这是我的application.yml:
spring:
datasource:
url: jdbc:h2:mem:appdb;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false
jpa:
database-platform: org.hibernate.dialect.H2Dialect
flyway:
url: jdbc:h2:mem:appdb;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false
user: "root"
password: ""
locations: classpath:/db/migration, classpath:/db/seed
Flyway successfully runs the migrations (or at least it appears to), and the tables are created successfully as evidenced by the startup: Flyway成功运行了迁移(或至少看起来如此),并且启动成功证明了表已成功创建:
2018-04-03 08:47:42.956 INFO 17980 --- [ main] o.f.core.internal.command.DbMigrate : Migrating schema "PUBLIC" to version 0
...
It even seems my seeds are "working": 甚至我的种子似乎在“起作用”:
2018-04-03 08:47:43.162 INFO 17980 --- [ main] o.f.core.internal.command.DbMigrate : Migrating schema "PUBLIC" with repeatable migration Seed sample
It tells me it worked: 它告诉我它有效:
2018-04-03 08:47:43.188 INFO 17980 --- [ main] o.f.core.internal.command.DbMigrate : Successfully applied 18 migrations to schema "PUBLIC" (execution time 00:00.283s)
My SQL files are written in PostgreSQL's SQL dialect. 我的SQL文件是用PostgreSQL的SQL方言编写的。 However, I've read that leaving hibernate on H2Dialect is fine.
但是,我读到H2Dialect上保持休眠状态很好。
When the tests go to run, it appears by the time the tests finish running there's nothing in the database, so the tests fail. 当测试开始运行时,它会在测试完成运行时显示,数据库中没有任何内容,因此测试失败。
My thoughts are that H2 is closing out the DB before the tests finish, but that seems strange to me. 我的想法是H2在测试完成之前就关闭了数据库,但这对我来说似乎很奇怪。 The seeds and the tables are working correctly.
种子和表格正常工作。
Is there anything I can do to verify everything is working here, or options I have not yet tried? 我有什么办法可以验证这里一切正常,或者我还没有尝试过的选项?
Try setting the Flyway schemas to your database name: 尝试将Flyway模式设置为您的数据库名称:
flyway:
schemas: appdb
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.