开发者

validate grails domain classes against a database

What's the best way to validate that the grails domain classes are in sync with a database? It's legacy database and i can't build it开发者_如何转开发 from the domain classes. An interesting idea here which implies fetching one row of each of the domains. However, it doesn't feel like a complete solution mainly because the test database against which I validate may not be so data rich as to have data in all tables.

Thanks in advance for taking time to read/reply.


That's a nice approach and must work even for empty tables - if a table is empty, you have no legacy data to worry about validating, right? Or, if you want to test Grails constraints for compatibility with DB constraints, create a new instance of the class and try to save() it in transaction - and always roll the transaction back.

If the database is small, I'd even go and remove max:1 from list() - to validate every record, because only some of the records may violate constraints.

I'd also replace println "${it}" with assert it.validate().

One last optimization, I'd limit the classes tested only to those that I know can violate some constraints. This will save a good part of such a test - and the test is going to take a plenty of time, you know - reading all the database with GORM overhead.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜