首页 > 解决方案 > Flyway 是否有我们可以在 SQL 迁移中使用的“数据库名称”占位符?

问题描述

我想知道 flyway 是否有某种预定义的占位符,我们可以在我们的 SQL 迁移脚本中使用?

我想要做的是master在切换回数据库之前在数据库中执行一些命令,迁移是为了运行。

我的脚本看起来像这样:

USE master

-- Create things, make a small dynamic SQL string and run it in the context of my DB

${myMigrationDB}..sp_executesql @myDynamicSQL;

USE ${myMigrationDB}

-- Execute something else in the context of the db defined in flyway.url that will use what has been created previously

我知道我可以创建自己的占位符来保存数据库名称,但在我看来,我会重复一些已经可用的东西,因为它在我的配置文件中flyway.url

我也知道我可以在单独的迁移中运行第二部分,但我仍然需要使用${myMigrationDB}..sp_executesql @myDynamicSQL;

标签: sql-serverdatabase-migrationflyway

解决方案


对此有一个开放的功能请求:https ://github.com/flyway/flyway/issues/2297


推荐阅读