如何在使用flywaydb时对版本控制存储过程进行版本控制? [英] How can I version control Stored Procedures while using flywaydb?

查看:864
本文介绍了如何在使用flywaydb时对版本控制存储过程进行版本控制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有一个使用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时对版本控制存储过程进行版本控制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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