Schema related problems with Flyway / Spring and H2 embedded database

前端 未结 6 2027
孤独总比滥情好
孤独总比滥情好 2020-12-15 11:05

I am building a Spring 3 MVC app that uses a MySQL database and have recently integrated Flyway into the solution to manage the database migrations. I have successfully conf

6条回答
  •  有刺的猬
    2020-12-15 12:03

    I had a similar issue, although I'm not using Spring. I'm adding H2 in-memory DB for tests on top of an existing setup with jOOQ + Flyway + PostgreSQL.

    The solution for me was a combination of changes:

    1. From @Omid's answer above, add ;DATABASE_TO_UPPER=false to the startup URL
    2. From @Tom's answer, add the schema creation to an init SQL script: CREATE SCHEMA IF NOT EXISTS public; (I didn't need to use the backticks).
    3. Finally in the same script, add a 2nd line of SET SCHEMA public; after schema creation.

    Note that I wasn't able to add ;SCHEMA=public to the init URL, because this was throwing an error before the schema was being created. Alternatively:

    1. Add ;DATABASE_TO_UPPER=false;INIT=CREATE SCHEMA IF NOT EXISTS public; to the startup URL.
    2. Then add SET SCHEMA public; to your init SQL script.

提交回复
热议问题