将视图回滚到同一视图的先前版本

发布于 2024-11-07 09:23:17 字数 485 浏览 0 评论 0原文

我正在使用 FM 部署数据库。作为部署的一部分,我正在推出一个视图。更改如下所示:

R1:创建视图

R2:不对视图进行任何更改

R3:向视图添加列

R4:不进行更改

R5:从视图中删除列

该视图是由源代码管理中的脚本创建的。假设我部署了 R3,然后决定应该回滚到 R2(我正在考虑一个我不想让其处于奇怪状态的生产站点)。因此视图的脚本(删除/创建)位于本地文件中。我无法再次使用该脚本,因为本地版本位于 R3,但我希望它返回到 R1(或 R2)。

如何使用 FluentMigrator 可靠地将视图回滚到之前的版本?我能想到的唯一选择是将视图创建脚本保留在我的迁移类中的字符串中。但似乎我需要在我的班级中将它的每个版本都放在一个字符串中 - 非常笨拙并且很难向团队推销。

我能想到的每一个现实的解决方案都违背了源代码控制的理念——在本地拥有一个事物的单一版本并随着时间的推移跟踪它的变化。

I'm using FM to deploy a database. As a part of that deploy, I'm rolling out a view. The changes go like this:

R1: create view

R2: no change to view

R3: add a column to the view

R4: no change

R5: remove the column from the view

The view is created by a script that is in source control. Let's say that I deploy R3 and then decide that I should roll back to R2 (I'm thinking of a production site that I don't want to leave in an odd state). So the view's script (drop/create) is in a local file. I can't use that script again because the local version is at R3 but I want it to go back to R1 (or R2).

How can I roll the view back to the previous version reliably using FluentMigrator? The only option I can think of is keeping the view create script in a string in my Migration class. But it seems like I'd need to have every version of it in a string in my class -- very unwieldy and a hard sell to the team.

Every realistic solution to this that I can think of sort of goes against the idea of source control -- having a single version of a thing locally and keeping track of its changes over time.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

浊酒尽余欢 2024-11-14 09:23:17

我将此功能添加到 FluentMigrator 中——能够直接从源代码执行脚本。你可以在这里获取:

https://github.com/jcollum/fluencemigrator

目前仅支持 SVN。尚未集成到主分支。

I added this feature into FluentMigrator -- ability to execute a script straight from source. You can get it here:

https://github.com/jcollum/fluentmigrator

Currently only supports SVN. Hasn't been integrated into the main branch yet.

西瑶 2024-11-14 09:23:17

一种非常简单的方法是执行以下操作:

if (object_id('dbo.myView', 'V')) is not null
   drop view [dbo].[myView]
go
create view [dbo].[myView] as

select foo, bar
from dbo.Orders

现在,如果您需要更改该视图,则可以对此脚本进行更改并部署它们。如果视图存在,它将删除它并重新创建它。从源代码控制的角度来看,您所做的只是对文本文件进行更改,因此您应该能够有效地存储它,非常简单地查看差异等。换句话说,您可以执行源代码控制的所有操作效果非常好,因为它只是文本。

One very simple way is to do something like:

if (object_id('dbo.myView', 'V')) is not null
   drop view [dbo].[myView]
go
create view [dbo].[myView] as

select foo, bar
from dbo.Orders

Now, if you need to need to alter that view, you make your changes to this script and deploy them. It'll drop the view if it exists and create it fresh. From a source control standpoint, all you're doing is making changes to a text file so you should be able to store it efficiently, look at the differences pretty simply, etc. In other words, you can do all the things that source control does really well because it's just text.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文