在 Grails 中的域类/表级别有选择地禁用自动表更新(dbCreate=“none”)?
在 Grails 中,是否可以仅为一个域类禁用自动表创建/更新?
假设我有域类 Foo
、Bar
和 Zonk
。我希望自动更新 Foo
和 Bar
表,而我不希望对 Zonk
表进行自动更改。
这可能吗?
为什么需要有选择地禁用表更新?其中一种情况是,Zonk 后面的表包含数百万行,因此对该表所做的任何更改(例如添加对外键的引用)都需要几天时间才能完成。
In Grails, is it possible to disable automatic table creation/updates for one domain class only?
Let's say I have domain classes Foo
, Bar
and Zonk
. I want automatic table updates for Foo
and Bar
, whereas I want no automatic changes at all made to the Zonk
table.
Is that possible?
Why the need to selectively disable table updates? One such case is when the table behind Zonk
contains millions of rows, so that any change made to that table (such as adding a reference to a foreign key) would take days to complete.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没有直接支持,但您可以修复。但您实际上甚至不希望自动更新“安全”表。几个例子 - 如果您重命名一列或表,它会添加新列或表,但不会删除旧列或表。如果添加不允许为空的新列,它将被添加为可为空,否则旧行将无效。如果您扩大列,即使不会丢失数据,它也不会更新。
使用数据库迁移会更好,Liquibase 是目前最好的选择。 数据库迁移插件是 Grails 的官方迁移插件,并使用 Liqibase。
There's no direct support but you could hack in a fix. But you really don't even want automatic updates for the "safe" tables. A few examples - if you rename a column or table, it'll add a new one but not delete the old one. If you add a new column that shouldn't allow nulls, it'll be added as nullable since otherwise old rows won't be valid. And if you widen a column it won't be updated even though there would be no data loss.
You'd be much better off using database migrations, and Liquibase is the best option currently. The Database Migration plugin is the official migrations plugin for Grails and uses Liqibase.