Flyway 5.0.7 warning about using schema_version table

后端 未结 3 1267
闹比i
闹比i 2021-01-17 07:40

We use the Flyway Gradle plugin to do our migrations offline (i.e. we migrate while the system is down). We recently upgraded to Flyway 5.0.7 and we see this warning now fo

3条回答
  •  隐瞒了意图╮
    2021-01-17 08:24

    On PostgreSQL I have solved it with just one migration on top:

    DO $$
      BEGIN
        IF (EXISTS (SELECT 1 FROM information_schema.tables WHERE table_schema = 'public' AND table_name = 'schema_version')
            AND EXISTS (SELECT 1 FROM information_schema.tables WHERE table_schema = 'public' AND table_name = 'flyway_schema_history'))
        THEN
            DROP TABLE schema_version;
        END IF ;
        IF (EXISTS (SELECT 1 FROM information_schema.tables WHERE table_schema = 'public' AND table_name = 'schema_version')
            AND NOT EXISTS (SELECT 1 FROM information_schema.tables WHERE table_schema = 'public' AND table_name = 'flyway_schema_history'))
        THEN
            CREATE TABLE flyway_schema_history AS TABLE schema_version;
        END IF ;
      END
    $$ ;
    

    It works actually in 2 stages:

    • On first reboot it copies history with migration recorded into 'old' history table.
    • On second reboot it drops old history table. Now migration goes into 'new' history and everything is finished.

提交回复
热议问题