Seed data for pellet application

What is the best way to load raw or test data into grails application. I am considering 3 options

  • Input of all * BootStrap.groovy files. It is tedious if there are a lot of domain classes and test data.
  • Write custom functions for loading via xml. Can't be too complicated with excellent xml support with groovy, but many switch statements for different domain classes.
  • Use Liquibase LoadData api. I can see that you are loading data from csv files easily.

Choice 3 seems to be the easiest. But I am not familiar with Liquibase. Is it good in this scenario or is it only used for migrations, changes to db, etc. If anyone can provide better evils or provide an example with Liquibase it will be of great help.

+2


a source to share


5 answers


Another answer is to use grails run-script. This will allow you to move whatever you can add to the boot file and store it wherever you want on your filesystem (possibly outside of your codebase). Likewise, you can install the console plugin and load the code through that in the running application.



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

+2


a source


I'm using the Fixtures plugin to load test / raw data, it works for me.



http://www.grails.org/plugin/fixtures

+2


a source


0


a source


take a look at the SeedMe plugin: https://github.com/bertramdev/seed-me

seed = {
    author(meta:[key:'name'], name: 'David', description: 'Author Bio Here')
}

      

0


a source


One of the ways I have created seed data is by using a service. I created a class, let's call it SeederService. I can inject this service into Bootstrap.groovy and call any method I would like to receive.

The beauty of the SeederService is that you can also use the same service in your unit tests. Just inject the service class into your unit test and create seed data.

0


a source







All Articles