Schema related problems with Flyway / Spring and H2 embedded database

前端 未结 6 2045
孤独总比滥情好
孤独总比滥情好 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 11:56

    From what I've tested the whole problem occurs only while mixing flyway and H2 with MySql compatibility mode on (doesn't occur if MySql mode is of). It is caused by case sensitivity inconsistency:

    1. h2 during initialization creates default schema 'PUBLIC' (uppercase!)
    2. when flyway tries to get default schema name it gets 'public' (lowercase!)
    3. when flyway tries to change current schema to 'public' (lowercase!) error is thrown. Even when setting flyway schemas to 'MYSCHEMA', at some point of it migration process it always tries to change to 'public'.

    In my currently developed application we use MySql as a main database and H2 for testing. My workaround involves creating 'public' (lowercase!) schema during h2 initialization:

    spring datasource configuration:

    
     
     
     
     
    
    

    init_tests.sql:

    CREATE SCHEMA IF NOT EXISTS "public";
    

    Isn't beautifull but works - hope that helps!

提交回复
热议问题