Reputation:
I can't figure how what the "standard practice" is for modifying a Domain Class after it has automatically created the corresponding database table.
There's no "migration" in Grails, and there's no way that I can find to tell it to output the new SQL it would generate so you can compare it to the previous table definition and manually issue your own ALTER TABLE command (that's what I do in django).
I just got the book "The Definitive Guide to Grails" and it is silent on the subject, and I can't find anything on the Grails website.
Upvotes: 12
Views: 3655
Reputation: 5618
You should try the database-migration plugin which has a good documentation and is actively maintained.
Upvotes: 0
Reputation: 39877
This is a weak point of grails and I don't know a good way to deal with it. What I do is create a copy of the modified domain class, then compare the SQL schema of the table of the modified domain class to that generated by the copy of the domain class. Then you have to manually make what ever alterations are necessary to your original table. I've found that things such as relationships tend to change when the domain class does, but things such as adding a constraint to force a field to be a text type don't always get changed.......
Upvotes: 4
Reputation: 1532
you can also alternatively try 'grails schema-export' command.. which would give you an output sql which has all the create commands for tables and constraints..
With that as reference, you can create your alter scripts. Thats the best currently available I guess..
Do let us know if you find a better way..
Upvotes: 0
Reputation: 14738
perhaps you should think about creating a backup/restore module for your app that is independent of the database (may be serialize to xml or json) - that way, when you change db, you also modify the backup/restore, in such a way that old domain data gets "upgraded" to ne domain data.
I like how django can do this automatically, but theres more magic in django that i dont understand...
Upvotes: 0
Reputation: 9120
If you want to explicitly manage the database schema for a Grails application I suggest you have a look at the Grails Liquibase plugin or the Grails autobase plugin.
Upvotes: 10