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
`
I'm trying to make an unit test pass but don't know don't know how to. How do i implement Flyway the correct way.
I've tried adding ;DATABASE_TO_UPPER=false;DB_CLOSE_ON_EXIT=FALSE and spring.jpa.defer-datasource-initialization=true but did not worked
CodePudding user response:
Flyway works by adding a flyway file into your resources folder. First (in resources) add a folder called db, inside db add a folder called migration. Then in migration add a file called V00X__initial.sql for instance. Replace X with number, like 1. Next is 2. Then write queries into the .sql files. Flyway will then run those queries when the application or tests start.
For tests, you would usually make a V001__make_tables.sql file, with a query that makes tables. Then a V002__insert_data.sql file to insert data, and then see in the tests if said data is added.