0

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.

4

1 回答 1

1

这是一个很好的方法,即使对于空表也必须有效 - 如果表是空的,您就没有需要担心验证的遗留数据,对吧?或者,如果您想测试 Grails 约束与 DB 约束的兼容性,请创建该类的新实例并save()在事务中尝试它 - 并始终回滚事务。

如果数据库很小,我什至会去删除max:1-list()以验证每条记录,因为只有一些记录可能违反约束。

我也会替换println "${it}"assert it.validate().

最后一个优化,我会将测试的类限制为我知道可能违反某些约束的类。这将节省此类测试的很大一部分 - 而且测试将花费大量时间,您知道 - 使用 GORM 开销读取所有数据库。

于 2011-06-13T22:34:55.810 回答