除某些表外,还有什么方法可以运行Flyway任务? [英] Is there any way to run Flyway task excluding some tables?

查看:314
本文介绍了除某些表外,还有什么方法可以运行Flyway任务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用Flyway来管理使用Postgis(PostgreSQL地理空间扩展)的应用程序上的迁移.

I'm currently using Flyway to manage migrations on an application which uses Postgis (PostgreSQL geospatial extension).

此插件使用名为spatial_ref_sys的表,该表也位于应用程序使用的同一模式中,当我调用mvn flyway:clean时,我收到一条错误消息,指示Flyway无法删除此表(该表是使用用户postgres);如果我将所有者更改为我的应用程序数据库用户,则错误将更改为:

This plugin uses a table called spatial_ref_sys which is located in the same schema the application uses too, when I call mvn flyway:clean I'm getting an error indicating that Flyway was unable to delete this table (it was created using user postgres); if I change the owner to my application database user, then the error changes to:

错误:由于扩展名postgis需要它,所以无法删除表spatial_ref_sys

ERROR: cannot drop table spatial_ref_sys because extension postgis requires it

[错误]提示:您可以改用扩展名postgis.

[ERROR] Hint: You can drop extension postgis instead.

但是,我不想删除这些项,它们只是我的应用程序逻辑的辅助,而这些项在我的应用程序逻辑之外.

However, I don't want to drop these items, which are external to my application logic, as they are just "auxiliars".

我看到了两个问题,其中Axel Fontaine表示不支持忽略某些表的功能(两个问题已经使用了两年或两年以上),我什至克隆了GitHub存储库,以将这个功能自己添加到Flyway中. ,并且我一直在阅读可以实现此更改的代码的某些部分;但是我怀疑它会影响代码的几个部分,而我对此的不了解可能会使事情变得更困难.

I have seen two questions where Axel Fontaine said the feature of ignore some table(s) is not supported (both questions are two or more years old), I even have cloned the GitHub repo to add this feature to Flyway by myself, and I've been reading some parts of the code where this change could be implemented; but I'm suspecting it will affect several parts of the code, and my unknowledgement about it could make the things harder..

因此,我正在寻求一些帮助实施更改,或者寻求一些解决此问题的方法.

So, I'm looking some help to implement the change, or maybe some ideas to do a work-around this issue..

我在考虑简单地对整个数据库进行DROP,然后重新创建它,然后重新创建地理空间扩展(Postgis,PGRouting等),并使用Flyway进行迁移,但是如果我必须这样做,这将不太合适.在开发过程中要做几次.

I'm thinking in simply do DROP of the entire database and recreate it, then recreate the geospatial extensions (Postgis, PGRouting, etc), and make the migration using Flyway, but this will be not much suitable if I have to do it several times during the development process..

推荐答案

我在测试环境中遇到了这个问题,我想通过运行方式删除架构.我通过操纵flyway spring bean序列来修复它.首先,我在flyway.clean()之前删除了postgis扩展名,然后在V1__init.sql的第一行中添加CREATE EXTENSION postgis SCHEMA public;:

I had this problem for test environment and i wanted to delete schema by flyway. I fixed it by manipulating flyway spring bean sequence. First, I dropped postgis extension before flyway.clean() and then at the first line of V1__init.sql add CREATE EXTENSION postgis SCHEMA public;:

@Bean
@Profile("test")
public Flyway flyway(DataSource dataSource) {
    Flyway flyway = new Flyway();
    flyway.setDataSource(dataSource);
    flyway.setLocations("classpath:db/migration");

    runSql("drop extension IF EXISTS postgis CASCADE;", dataSource);

    flyway.clean();
    flyway.migrate();

    return flyway;
}

这篇关于除某些表外,还有什么方法可以运行Flyway任务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆