【问题标题】:Spring boot properties for compability h2 in memory with posgresql用于与 postgresql 在内存中兼容 h2 的 Spring Boot 属性
【发布时间】:2021-06-05 10:48:22
【问题描述】:

每个人。 我在兼容 h2 in-memory 和 postgresql 时遇到了一些麻烦。我试图在堆栈溢出和谷歌中找到我的解决方案,但每个人都使用 Gradle 或其他配置文件。就我而言,我使用了 application.properties 文件,但在 SQL 语句中出现语法错误。

我的错误: enter image description here

我的资源结构: enter image description here

比如我的部分sql脚本:

CREATE TABLE candle_1day
(
    id          serial primary key NOT NULL,
    created_at  timestamp(6) without time zone, --> not compability type
    open_price  numeric(35, 15) CHECK ( open_price >= 0 ),
    close_price numeric(35, 15) CHECK ( close_price >= 0 ),
    high_price  numeric(35, 15) CHECK ( high_price >= 0 ),
    low_price   numeric(35, 15) CHECK ( low_price >= 0 ),
    volume      numeric(35, 15) CHECK ( volume >= 0 ),
    currency_id integer            NOT NULL,
    CONSTRAINT unq_candle_1day_currency_id_created_at_idx UNIQUE (currency_id, created_at),
    CONSTRAINT fk_candle_1day_currency_id_to_currency_info_id
        FOREIGN KEY (currency_id) REFERENCES currency_info (id)
);

我的 application.properties 文件:

spring.datasource.driver-class-name=org.h2.Driver
spring.flyway.user=sa
spring.flyway.password=sa
spring.flyway.schemas=testdb
spring.flyway.url=jdbc:h2:mem:testdb;MODE=PostgreSQL;database_to_upper=false
spring.flyway.locations=filesystem:migration

【问题讨论】:

    标签: spring postgresql h2 flyway


    【解决方案1】:

    H2 只能从 1.4.197 版本开始解析TIMESTAMP(6) WITHOUT TIME ZONE(当前版本为 1.4.200)。

    还请注意,DATABASE_TO_UPPER=FALSE 只能用于 1.4.197 和更早的版本。在较新的版本中,您需要 DATABASE_TO_LOWER=TRUE 来实现此兼容模式。

    【讨论】:

      猜你喜欢
      • 2021-05-14
      • 2018-03-03
      • 2020-09-03
      • 2018-02-01
      • 2015-10-13
      • 2017-09-27
      • 1970-01-01
      • 2015-02-14
      • 2018-05-07
      相关资源
      最近更新 更多