Selectively disabling automatic table updates (dbCreate="none") on domain class/table level in Grails?
In Grails, is it possible to disable automatic table creation/updates for one doma开发者_如何学JAVAin 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.
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.
精彩评论