繁体   English   中英

Flyway / Springboot 和 H2 内存数据库的模式相关问题

[英]Schema related problems with Flyway / Springboot and H2 in-memory database

org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [INSERT INTO merchant_rating_detail (order_id, shop_id, user_id, rating, created_datetime, feedback_ids) VALUES(?, ?, ?, ?, ?, ?);]; nested exception is org.h2.jdbc.JdbcSQLSyntaxErrorException: Table "merchant_rating_detail" not found (this database is empty); SQL statement: INSERT INTO merchant_rating_detail (order_id, shop_id, user_id, rating, created_datetime, feedback_ids) VALUES(?, ?, ?, ?, ?, ?); [42104-214] org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [INSERT INTO merchant_rating_detail (order_id, shop_id, user_id, rating, created_datetime, feedback_ids) VALUES(?, ?, ?, ?, ?, ?);]; nested exception is org.h2.jdbc.JdbcSQLSyntaxErrorException: Table "merchant_rating_detail" not found (this database is empty); SQL statement: INSERT INTO merchant_rating_detail (order_id, shop_id, user_id, rating, created_datetime, feedback_ids) VALUES(?, ?, ?, ?, ?, ?); [42104-214] `


# Flyway
spring.flyway.enabled= false

# H2
spring.datasource.url=jdbc:h2:mem:testdb;DATABASE_TO_UPPER=false;DB_CLOSE_ON_EXIT=FALSE
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=password
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.jpa.defer-datasource-initialization=true

`

我正在尝试通过单元测试,但不知道如何去做。 我如何以正确的方式实施 Flyway。

我尝试添加;DATABASE_TO_UPPER=false;DB_CLOSE_ON_EXIT=FALSE 和 spring.jpa.defer-datasource-initialization=true 但没有用

Flyway 通过将 flyway 文件添加到资源文件夹中来工作。 首先(在资源中)添加一个名为 db 的文件夹,在 db 中添加一个名为 migration 的文件夹。 然后在迁移中添加一个名为 V00X__initial.sql 的文件。 将 X 替换为数字,例如 1。接下来是 2。然后将查询写入 .sql 文件。 Flyway 将在应用程序或测试启动时运行这些查询。

对于测试,您通常会创建一个 V001__make_tables.sql 文件,其中包含一个生成表的查询。 然后一个V002__insert_data.sql文件插入数据,然后在测试中查看是否添加了所述数据。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM