用于数据库 diff(ing) 的 C# 库

发布于 2024-12-01 21:07:55 字数 554 浏览 0 评论 0原文

在整理增量数据库更新的迁移脚本时,我发现现成的数据库差异工具(我研究过的)都无法生成我们的开发过程所需的迁移脚本。

与几乎所有其他开发项目一样,我们需要能够在不丢失生产数据的情况下使生产模式与最新的开发模式保持同步。

到目前为止,方法是删除并重新创建任何不是表的对象(注意将序列 nextvals 更新为适当的值),然后通过删除不再存在的列、添加已存在的列来处理表差异。创建,重命名类型或长度已更改的列,添加新的列定义,然后使用适当的类型转换用数据填充更改的列。

当前的方法是完全自动化的,但它没有考虑到刚刚重命名的列。比较表定义 (DBMS_METADATA_DIFF) 不会提供任何机器可理解的线索,表明删除列后添加列实际上是列重命名。对于人类来说,列重命名可能是显而易见的,特别是如果重命名只是语法更正或选择更合适的名称。

我试图通过编写自己的数据库差异脚本生成器并添加用于发现列重命名的逻辑(支持人工干预、确认等)来解决此问题。现在,我很确定我必须重新发明另一个轮子。

有什么好的开源库值得我看一下吗?我更喜欢 C#,但由于我正在使用 Oracle,因此可能有一些很好的 Java 实现。任何指示表示赞赏。

Whilst sorting out migration scripts for incremental database updates, I discovered that none of the off-the-shelf database diff tools (that I have researched) will produce the migration scripts needed by our development process.

In line with pretty much every other development project, we need the ability to bring a production schema up to date with the latest development schema without losing production data.

The approach, so far, is to drop and recreate any object that is not a table (taking care to update sequence nextvals to an appropriate value) and to then deal with table differences by dropping columns that no longer exist, adding columns that have been created, renaming columns whose type or length have changed, adding the new column definitions and then populating changed columns with data using an appropriate type transformation.

The current approach is completely automated but it does not take into account columns that have simply been renamed. Diffing the table definitions (DBMS_METADATA_DIFF) does not give any machine-understandable clues that a column-drop followed by a column-add is actually a column-rename. To a human, a column-rename might be obvious, especially if the rename is simply a grammatical correction or choice of more appropriate name.

I am attempting to resolve this by writing my own database diff script generator and adding logic for spotting column renames (with support for human intervention, confirmation, etc.). Now, I'm quite sure that I must be reinventing another wheel.

Are there any good open source libraries that I should take a look at? I prefer C# but as it's Oracle I'm working with, there is probably some good Java implementations around. Any pointers appreciated.

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

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

发布评论

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

评论(1

抚你发端 2024-12-08 21:07:55

我们使用 RedGate SQL Compare 和 SQL Data Compare API 在安装时在引导数据库和目标(客户端)数据库之间生成差异模式和数据更新脚本。它运作得很好。 RedGate 提供了类似的 Oracle 产品(尚未使用过,因此您的体验可能会有所不同)

http://www.red-gate.com/products/oracle-development/schema-compare-for-oracle/

PS,我知道它不是开源的,但我认为你很难找到像这样易于使用的库。

We use the RedGate SQL Compare and SQL Data Compare APIs to generate differential schema and data update scripts between our bootstrap database and our target (client) databases at install time. It works very well. There's a comparable Oracle product offered by RedGate (haven't used it, so your mileage may vary)

http://www.red-gate.com/products/oracle-development/schema-compare-for-oracle/.

PS, I know it's not open source, but I think you'll be hard pressed to find as easy to use library as this.

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