onkami
onkami

Reputation: 9441

Spring Boot 2 + Flyway + H2: can't see generated migration in H2 Console

I have h2 and flyway enabled in my Spring Boot 2 project.

I have properties as follows:

spring.datasource.url: jdbc:h2:mem:mydatabasename
spring.datasource.driverClassName: org.h2.Driver
spring.datasource.username: sa
spring.datasource.password:
spring.jpa.database-platform: org.hibernate.dialect.H2Dialect
spring.h2.console.enabled: true
spring.h2.console.path: /h2
spring.flyway.url: ${spring.datasource.url}
spring.flyway.schemas : mydatabasename
spring.flyway.user: ${spring.datasource.username}
spring.flyway.password : ${spring.datasource.password}

db.migration file is usual (resources/db/migration/V1__Initial_version.sql)

CREATE TABLE PRODUCT
(
    ID VARCHAR(200) PRIMARY KEY,
    PRODUCTID VARCHAR(30)
);

and it works:

 o.f.c.internal.license.VersionPrinter    : Flyway Community Edition 5.2.4 by Boxfuse
 o.f.c.internal.database.DatabaseFactory  : Database: jdbc:h2:mem:mydatabasename (H2 1.4)
 o.f.c.internal.database.base.Database    : Flyway upgrade recommended: H2 1.4.199 is newer than this version of Flyway and support has not been tested.
 o.f.core.internal.command.DbSchemas      : Creating schema "mydatabasename" ...
 o.f.c.i.s.JdbcTableSchemaHistory         : Creating Schema History table: "mydatabasename"."flyway_schema_history"
 o.f.core.internal.command.DbMigrate      : Current version of schema "mydatabasename": null
 o.f.core.internal.command.DbMigrate      : Migrating schema "mydatabasename" to version 1 - Initial version
 o.f.core.internal.command.DbMigrate      : Successfully applied 1 migration to schema "mydatabasename" (execution time 00:00.021s)

However when I log in to the H2 console (I use exactly the same url,jdbc:h2:mem:mydatabasename) I do log in, but I do not see anything, only INFORMATION_SCHEMA. Additionally, 'show schemas' show INFORMATION_SCHEMA and PUBLIC, and PUBLIC not present in the left-hand column also.

Upvotes: 4

Views: 3047

Answers (1)

onkami
onkami

Reputation: 9441

I found the fix myself:

making this instruction

spring.datasource.url: "jdbc:h2:mem:mydatabasename;DB_CLOSE_DELAY=-1;"

made the newly created schema and table to appear.

Additionally, if I remove

spring.flyway.schemas : mydatabasename // remove

then the tables created at "root" level when viewing from the console.

Upvotes: 3

Related Questions