Can Grails 2.x schema-export, or similar command, generate DDL for schema updates given a datasource?

一曲冷凌霜 提交于 2019-12-23 13:17:09

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/12432203/can-grails-2-x-schema-export-or-similar-command-generate-ddl-for-schema-update

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!