Peters_
Peters_

Reputation: 647

how to introduce flyway into spring-boot project using h2 database and yaml properties?

I am trying to integrate flyway library into the spring-boot project using h2 and yaml properties. Unfortunately while starting the application I did not receive any logs that the Flyway is started and also I cannot see the table under the h2-console. (I see another tables created by hibernate)

This is my code:

pom.xml

<plugin>
    <groupId>org.flywaydb</groupId>
    <artifactId>flyway-maven-plugin</artifactId>
    <version>6.5.0</version>
</plugin>

application.yml

spring:
    h2:
        console:
            enabled: true
            path: /h2-console
    datasource:
        url: jdbc:h2:file:~/testdb
        username: sa
        password:
        driverClassName: org.h2.Driver
    jpa:
        hibernate.ddl-auto: none
        show-sql: true
    flyway:
        enabled: true
        locations: filesystem:/db/migration

V1_0__init.sql under src/main/resources/db/migration

CREATE TABLE TEST_USERS (ID INT AUTO_INCREMENT PRIMARY KEY, USERID VARCHAR(45));
INSERT INTO USERS (ID, USERID) VALUES (1, 'TEST.com');

Any ideas what is wrong?

Upvotes: 0

Views: 2539

Answers (1)

Cem Ikta
Cem Ikta

Reputation: 1450

  1. To automatically run Flyway database migrations on startup, you should add flyway dependency in your pom.xml:
    <dependency>
      <groupId>org.flywaydb</groupId>
      <artifactId>flyway-core</artifactId>
    </dependency>
  1. Add your db migrations in application.yml:
  flyway:
    locations: classpath:/db/migration

Then youshould see flyway logs on startup.

For more informations: 10.6.1. Execute Flyway Database Migrations on Startup

Upvotes: 1

Related Questions