Flyway: non-empty schema without metadata table

三世轮回 提交于 2019-11-30 17:00:51

The title is somewhat contradictory, as the database is indeed not virgin as you installed, through the PostGIS extension, a number of objects in the public schema.

You can either

  • set flyway.schemas to a new schema, say my_app, which will then be created automatically by Flyway. Your application should then use this one instead of public (recommended)
  • set flyway.baselineOnMigrate to true or invoke flyway.baseline() against the public schema. This will work, but public will then contain a mix of both your application objects and the PostGIS objects
ruby_newbie

If you are using Gradle you can run

./gradlew -Dflyway.schemas=public flywayClean flywayMigrate

Where public is the name of the database containing the schema_versions table. That should delete the table and metadata as well as running the migrations to get it back up to date.

Caution!

This will delete all data in public schema

Vikky

I think this error comes only with latest version of Flyway i.e. above 4.03. I didn't received in the earlier project but got it when I am using Flyway version 5.07 in my latest project. Putting the code here that resolve my issues

public class FlywayConfig {

    @Autowired
    DataSource dataSource;
    @Autowired
    Config config;

    @Bean
    public Flyway flyway(){
        Flyway flyway = new Flyway();
        flyway.setDataSource(dataSource);
         flyway.setSqlMigrationPrefix("V");
            flyway.setLocations(new String[] { config.getSqlLocation() });
            flyway.setBaselineOnMigrate(true);
            // *******************flyway.clean(); ********************// this will wipe out the DB, be careful
            flyway.migrate();
        return  flyway;

    }

}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!