我目前有一个使用Microsoft SQL Server后端的Java Web应用程序。数据库迁移目前由sqlcmd手动完成,它使用:r命令引用我们的存储过程和视图的脚本文件。
I currently have a Java web app which uses a Microsoft SQL Server back end. Database migrations are currently being done manually by sqlcmd which makes use of the :r command to reference script files of our stored procedures and views.
这样每个存储过程都有他的自己的文件proc_someprocedure.sql迁移是由升级脚本6.1 upgrade.sql完成的,该脚本将proc文件引用为drop并在其当前版本中重新创建。
This way each stored procedure has his own file "proc_someprocedure.sql" The migration is done by an upgrade script "6.1 upgrade.sql" which refrences the proc file to drop and recreate it in it's current version.
我们希望迁移到flyway并让应用程序在部署时迁移它自己的数据库。但是,我找不到任何简单的方法来为每个存储过程维护单个源代码文件。如果存储过程发生更改,我需要在版本控制中对V_6_1__change.sql文件和proc_someprocedure.sql文件进行更改。
We're looking to migrate to flyway and have the application migrate it's own database upon deployment. However, I can't find any easy way to maintain a single source code file for each stored procedure. In the event that a stored procedure is changed, I need to make the change in both a V_6_1__change.sql file and the proc_someprocedure.sql file in version control.
我'我试图避免复制/粘贴的sql代码,因为它在过去困扰我们。其他人如何处理这种情况?
I'm trying to avoid copy/pasted sql code as it's haunted us in the past.. How are others handling this situation?
推荐答案从3.0开始,没有一流的支持。但是有三种方法可以达到这个目的:
As of 3.0 there is no first class support for this. There are however 3 ways to achieve this:
- 使用自定义MigrationResolver挂钩到你使用的任何源控件并检测那些方式的改变
- 使用通过afterMigrate重新创建所有存储过程的FlywayCallback
- 在单独的模式中使用单独的Flyway实例并将cleanOnValidationError设置为true。每次校验和更改时,都会清除架构并重新运行该Flyway实例管理的所有迁移
更多推荐
如何在使用flywaydb时对版本控制存储过程进行版本控制?
发布评论