Grails应用程序的种子数据 [英] Seed data for grails application

查看:157
本文介绍了Grails应用程序的种子数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将种子(初始或测试)数据加载到grails应用程序的最佳方式是什么?我正在考虑3个选项

What is the best way to load seed (initial or test) data into grails application. I'm considering 3 options


  1. 将所有内容放入* BootStrap.groovy文件中。如果域类和测试数据很多,这是很乏味的。

  2. 编写自定义功能以通过xml加载它。 groovy可以提供优秀的xml支持,但不会太困难,但是对于不同的域类,很多switch语句。

  3. 使用Liquibase LoadData api。我发现你可以很容易地从csv文件加载数据。

Choice 3似乎是最简单的。但是,我不熟悉Liquibase。在这种情况下它是好的,还是只用于迁移,数据库更改等。如果任何人都可以提供更好的解决方案,或指向Liquibase的例子,这将是很好的帮助..

Choice 3 seems the easiest. But, I'm not familiar with Liquibase. Is it good in this scenario, or only used for migration, db changes etc. If anyone could provide a better sol, or point to an example with Liquibase, it would be great help..

推荐答案

另一个答案是利用grails运行脚本。这将允许您移动自举程序并将其保留在文件系统上的所需位置(可能位于代码库之外)。同样,您可以通过运行的应用程序安装控制台插件和加载代码。

Another answer would be to leverage grails run-script. This would allow you to move what you might put in bootstrap and keep it where you want on your file system (possibly outside of the codebase). Similarly, you could install the console plugin and load code through that on a running application.

根据您的数据需求,查看伟大的build-test-data插件,好。

Depending on your data needs, check out the great build-test-data plugin as well.

这篇关于Grails应用程序的种子数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆