Search code examples
springpostgresqlh2flyway

Spring boot properties for compability h2 in memory with posgresql


everyone. I have some trouble with compatibility h2 in-memory and postgresql. I tried to found my solution in stack overflow and google, but everyone uses Gradle or another config file. In my case, I use the application.properties file and I get a Syntax error in SQL statement.

My errors: enter image description here

My structure of the resources: enter image description here

For example, part of my sql script:

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)
);

My application.properties file:

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

Solution

  • H2 can parse TIMESTAMP(6) WITHOUT TIME ZONE only since the version 1.4.197 (current version is 1.4.200).

    Please also note that DATABASE_TO_UPPER=FALSE should only be used in 1.4.197 and older versions. In newer versions you need DATABASE_TO_LOWER=TRUE for this compatibility mode.