gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 14:18:27 25 4
gpt4 key购买 nike

我在我的 Spring Boot 2 项目中启用了 h2 和 flyway。

我有如下属性:

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 文件是普通的(resources/db/migration/V1__Initial_version.sql)

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

它有效:

 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)

然而,当我登录到 H2 控制台时(我使用完全相同的 url,jdbc:h2:mem:mydatabasename)我确实登录了,但我没有看到任何东西,只有 INFORMATION_SCHEMA。此外,“显示模式”显示 INFORMATION_SCHEMA 和PUBLIC,并且 PUBLIC 也未出现在左侧列中。

最佳答案

我自己找到了修复:

制定这条指令

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

使新创建的模式和表出现。

此外,如果我删除

spring.flyway.schemas : mydatabasename // remove

然后是从控制台查看时在“根”级别创建的表。

关于Spring Boot 2 + Flyway + H2 : can't see generated migration in H2 Console,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57820240/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com