Grails 2.x模式导出或类似命令是否可以为给定数据源的模式更新生成DDL? [英] Can Grails 2.x schema-export, or similar command, generate DDL for schema updates given a datasource?

查看:138
本文介绍了Grails 2.x模式导出或类似命令是否可以为给定数据源的模式更新生成DDL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Grails模式导出在生成DDL为特定数据库创建数据库模式方面做得非常好。然而,我想要做的是Grails只是将DDL更新到已经创建的模式,而不是DDL从头开始创建它。



我是认为它应该是可能的,因为如果您在数据源中指定了 dbCreate =update,grails确实能够更新模式。



但是我只是希望grails能够吐出它将运行的内容,而不是实际执行它,所以我可以通过SQL工具以受控的方式自己执行。

解决方案

正如@GreyBeardedGeek在评论中指出的那样,数据库迁移插件(现在默认包含)可以生成您正在查找的模式差异,并且它的功能远远超过了香草 dbCreate =update,因为Grails的本地数据库更新仅依赖于Hibernate提供的内容,而且它非常保守他更新它可以做。



特别是,您正在寻找的数据库迁移插件的一部分是 dbm-update-sql 脚本,它将为您提供将它运行以更新数据库到当前模式版本的SQL。



一般来说, em> strong 建议使用数据库迁移插件之类的工具,因为它将数据库模式与应用程序代码捆绑在一起,您可以轻松地将它们一起进行版本化,并且还包含大量工具,以便运行更新很多减少痛苦,并允许回滚和自定义脚本根据需要按摩事物。


Grails schema-export does a great job of generating the DDL to create database schemas for a particular database. However what I would like to do, is have grails just output the DDL for updates to an already created schema, not the DDL to create it from scratch.

I'm thinking it should be possible, as grails does have the ability to actually update schemas if you specificy dbCreate = "update" in your datasource.

But I just want grails to spit out what it would run, not actually do it, so I can execute it myself through a SQL tool in a controlled manner.

解决方案

As @GreyBeardedGeek pointed out in a comment, the Database Migration Plugin (which is included by default now) can generate the "schema diff" that you are looking for, and it does substantially more than what the vanilla dbCreate = "update" does, since Grails' native db updating relies only on what Hibernate provides, and it's very conservative in the updates it can do.

In particular, the part of the Database Migration plugin that you are looking for is the dbm-update-sql script, which will give you the SQL that it would run to update the DB to the current schema version.

In general, I would strongly advise using a tool like the Database Migration plugin, since it bundles your DB schema in with your application code and you can easily version them together, and it also includes lots of tooling so that running the updates is much less painful, and allows for rollbacks and custom scripts to massage things as needed.

这篇关于Grails 2.x模式导出或类似命令是否可以为给定数据源的模式更新生成DDL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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