如何使用Flyway 2.0.1处理Oracle同义词? [英] How to handle Oracle synonyms with Flyway 2.0.1?

查看:140
本文介绍了如何使用Flyway 2.0.1处理Oracle同义词?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用了很长时间的飞行.非常好/完整的工具!

I'm using flyway for a long time now. Very nice/complete tool!

我实际上正面临着意外情况……我有两种模式:

I'm actually facing an unexpected situation... I have two schemas:

  • 处理表格和序列的所有者
  • 使用同义词访问所有者对象的用户

该习俗不希望我授予所有者授予创建任何同义词/删除任何同义词"的权利. 但是我可以为用户提供授予创建同义词".

The custom does not want me to give the 'grant create any synonym / drop any synonym' rights to the Owner. But I can provide the 'grant create synonym' to the User.

所以我需要

  1. 创建表格/序列(与所有者连接)
  2. 授予选择,删除...到我的用户模式(与所有者连接)
  3. 为用户创建同义词以访问所有者对象(与用户连接)

第3点是我的问题.

如果我给所有者授予任何同义词"并使用flyway占位符,则可以执行以下操作:

If I give the 'grant any synonym' to the owner and using the flyway placeholders, I can do something like that:

CREATE OR REPLACE SYNONYM ${user}.WORKITEMINFO FOR WORKITEMINFO;

但我不能;)

因此,我实现的解决方案是使用Java迁移,该迁移使用连接到User模式的另一个DataSource. (我的MigrationUtils.replacePlaceholders允许我以占位符的形式访问任何flyway.properties属性)

So the solution I implemented is to use java migrations using another DataSource connected to the User schema. (My MigrationUtils.replacePlaceholders allows me to get access to any of the flyway.properties properties as placeholder)

private final static String[] queries =
        {"CREATE OR REPLACE SYNONYM TASK_COMMENT FOR ${flyway.user}.TASK_COMMENT"}

@Override
public void migrate(final Connection connection) throws Exception {

    final DataSource dataSource = MigrationUtils.getUserDataSource();

    final Connection connectionForMigrations = dataSource.getConnection();

    final JdbcTemplate jdbcTemplate = new JdbcTemplate(connectionForMigrations);
    new TransactionTemplate(connectionForMigrations).execute(new TransactionCallback<Void>() {

        @Override
        public Void doInTransaction() {

            try {
                for (final String query : queries) {
                    final String replacedQuery = MigrationUtils.replacePlaceholders(query);
                    LOG.debug("Executing SQL: " + replacedQuery);
                    jdbcTemplate.executeStatement(replacedQuery);
                }
            } catch (final SQLException exc) {
                throw new FlywayException("Could not drop synonym", exc);
            }
            return null;
        }
    });

}

还有另一种方法可以解决这种情况吗?

Is there another way to resolve this situation?

谢谢!

推荐答案

在飞行时使用-Dflyway.schemas=OWNER_NAME.

这篇关于如何使用Flyway 2.0.1处理Oracle同义词?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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