是否建议使用 Liquibase 将生产数据从旧数据库模式迁移到新数据库模式?

发布于 2024-09-17 12:40:16 字数 985 浏览 2 评论 0原文

我是数据迁移领域的新手,正在研究如何将使用 OurApp 1.0 的客户数据迁移到具有与 OurApp 2.0 兼容架构的新数据库。我见过很多人推荐 Liquibase 进行数据库变更管理和数据库重构任务,对于我的新手来说,这听起来可能很接近我们的需要。

然而,在阅读了 www.liquibase.org 上的材料后,我感觉 Liquibase 更多的是为了保持模式的最新,而不是转换大量现有的数据,以便将其保留在新的模式中。

假设我想将 Employee 表中名为 name 的列拆分为名字和姓氏列。 Liquibase 可以通过删除名称列并添加名字和姓氏列来更改表。然而,我感觉 Liquibase 并不是真正为我构建的,可以插入转换代码,将数据库中现有记录的名称字段解析为名字和姓氏,并将它们存储在各自的列中。

例如,假设我的表如下所示,

id | name             | position
*********************************
12   Horace Slughorn    Professor
13   Albus Dumbledore   Headmaster

在运行 Liquibase 后,名称列将被名字和姓氏列替换,因此我的数据库架构将是正确的。但我猜测 Liquibase 不是一个允许我插入一些代码来将“Horace Slughorn”解析为“Horace”和“Slughorn”并将这些值存储在该记录的名字和姓氏列中的框架。

id | firstname   |  lastname  | position
*****************************************
12   Horace         Slughorn         Professor
13   Albus          Dumbledore       Headmaster

因此,Liquibase 可以使您的架构保持最新状态,但其设计目的并不是帮助您转换现有数据以使其与新架构匹配。是这样吗?

I'm new to the world of data migration and looking into ways to migrate the data of customers using OurApp 1.0 to a new database with a schema compatible with OurApp 2.0. I've seen a more than a few people recommending Liquibase for database change management and database refactoring tasks, which to my newbie ears sounds like it may be close to what we need.

However, after reading through the material on www.liquibase.org, I get the feeling that Liquibase is more about keeping the schema up to date than it is about converting lots of already existing data so that it can be persisted in the new schema.

Say I wanted to split a column in my Employee table called name into a firstname and lastname column. Liquibase would be able to alter the table by dropping the name column and adding a firstname and lastname column. However, I get the feeling Liquibase isn't really built for me to plug in conversion code that would parse the name field of existing records in the database into a firstname and lastname and store those in their respective columns.

For example, say my table looked like this

id | name             | position
*********************************
12   Horace Slughorn    Professor
13   Albus Dumbledore   Headmaster

After I ran Liquibase the name column would be replaced by a firstname and lastname column so my database schema would be correct. But I'm guessing Liquibase is NOT a framework that lets me plug in some code that parses "Horace Slughorn" into "Horace" and "Slughorn" and stores these values in the firstname and lastname columns for that record.

id | firstname   |  lastname  | position
*****************************************
12   Horace         Slughorn         Professor
13   Albus          Dumbledore       Headmaster

So Liquibase keeps your schema up to date, but isn't designed to help you convert your existing data so that it it matches the new schema. Is that right?

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

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

发布评论

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

评论(2

迷乱花海 2024-09-24 12:40:17

Liquibase 的目标是允许您将数据库从一个版本移动到新版本。它有许多内置的数据库“重构”,但它没有一个可以按照您所描述的方式分割数据,因为如何分解现有字符串非常依赖于您的实现。

Liquibase 确实允许您创建自定义更改类(http://www.liquibase.org/manual/custom_refactoring_class)在 1.9 中以及在 2.0 中提供更强大的自定义更改支持(http://liquibase.org/extensions)。它是基于java的,所以你的脚本需要用java编写,但是你可以做任何你需要的数据读取和操作。

注意:如果你有很多数据,将记录读入java,然后将它们写回会很慢。在这种情况下,您可以使用 liquibase 的标签并创建基于数据库的 sql 语句和/或存储过程来执行数据库内的拆分。 Liquibase 仍然非常有助于跟踪分割已经完成且不应再次进行。

The goal of Liquibase is to allow you to move your database from one version to the new version. It has many built in database "refactorings", but it does not have one to split your data as you are describing because how you break up existing strings is so dependent on your implementation.

Liquibase does allow you to create custom change classes (http://www.liquibase.org/manual/custom_refactoring_class) in 1.9 as well as a much more powerful custom change support in 2.0 (http://liquibase.org/extensions). It is java based, so your script would need to be written in java, but you can do any data reading and manipulation you need.

Note: if you have a lot of data, reading the records into java, then writing them back out will be slow. In that case, you can use liquibase's tag and create database-based sql statement(s) and/or stored procedure(s) that will do the splitting in-database. Liquibase will still be very helpful to track that the splitting has been done and should not be done again.

魂归处 2024-09-24 12:40:17

如果您想编写自定义 SQL,也可以使用 dbdeploy。 Liquibase也支持编写自定义SQL,有DBMaintain或iBatis Migrator。

You can also use dbdeploy if you want to write custom SQL. Liquibase supports writing custom SQL too, there is DBMaintain or iBatis Migrator.

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