Flyway migrations are not stored in the H2 embedded database

I am actually writing a small web application with spring boot and wanted to use the (built-in) H2 database along with spring Data JPA and Flyway to migrate the database.

This is my application.properties application:

spring.datasource.url=jdbc:h2:~/database;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=-1; spring.datasource.username=admin spring.datasource.password=admin spring.datasource.driver-class-name=org.h2.Driver 

In the main () method of my @SpringBootApplication class, I do the following:

 ResourceBundle applicationProperties = ResourceBundle.getBundle("application"); Flyway flyway = new Flyway(); flyway.setDataSource(applicationProperties.getString("spring.datasource.url"), applicationProperties.getString("spring.datasource.username"), applicationProperties.getString("spring.datasource.password")); flyway.migrate(); 

I added a script that creates the USER table in the database, Flyway says that it was correctly ported, but if I connect to the database, only the schema_versions table will be shown in the PUBLIC.

If I add another script that inserts the underlying data into the USER table, the migration fails because the table is missing after restarting my spring boot application.

Can someone tell me if there is any in my configuration? Or if there are some incorrect assumptions in my setup ...

+4
source share
1 answer

I have insufficient data about your configuration

  • Hint: See the migration file must be part of dicrectory / db / migration

  • Hint use a template similar to V1.0.1__name.sql 2 under ratings

  • The hint depending on the version of Flyway you should start with the sql file version in excess of 1.0, 1.0.1.

  • The default spring boot jpa tip reduces your database content if you use a database in memory. See http://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-sql.html section 28.3.3.

+9
source

All Articles