[英]Split columns out of MySQL table using Liquibase
I have an existing table with data in it. 我有一个已有数据的表。
foobar_table
foo
bar
baz
I want to split the baz
column out of the foobar_table
table and create a new table called baz_table
that contains it. 我想从
foobar_table
表中拆分出baz
列,并创建一个包含它的名为baz_table
的新表。 After the operation is done I would have the following structure with each column containing the data it had before the operation started: 操作完成后,我将具有以下结构,每列包含操作开始之前的数据:
foobar_table
foo
bar
baz_table
baz
How can I do this with Liquibase ? 如何使用Liquibase做到这一点 ?
PS Using Liquibase via the Grails Database Migration plugin . PS通过Grails数据库迁移插件使用Liquibase。 The grailsChange tag gives me hope, but lack of example documentation leave me wanting.
grailsChange标记给了我希望,但是缺少示例文档让我无所适从 。
Update: 更新:
I wasn't aware of the sql
that can be used in change sets. 我不知道可以在变更集中使用的
sql
。 I found out about it in the example here and I think it is what I needed. 我在这里的示例中发现了它,我认为这是我所需要的。
As you already found out, you can run arbitary SQL queries as a part of changeset. 如您所知,您可以在变更集的一部分中运行任意SQL查询。 I go over common caveats in my blog post .
我在博客文章中介绍了一些常见的警告。
So for your example: 因此,对于您的示例:
<changeset>
<createTable tableName="baz_table"/>
<sql>insert into baz_table(baz) select baz from foobar</sql>
<dropColumn tableName="foobar_table" columName="baz"/>
</changeset>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.