views:

329

answers:

4

I have a Liquibase migration that I manually run to load seed data from several CSV files into my database. I would like to run this migration each time I run grails run-app.

I think I have two questions in one:

  1. How to I integrate the migrate command into my grails run-app ?
  2. How do I clear the DATABASECHANGELOG to allow me to run the same migration over and over?

Or, is there a better way to load a lot of data into a DB from CSV files?

+1  A: 

Question 1 - To integrate migrate command into run-app, you should listen for events thrown in run-app scripts. This is explained here, and a more complete article is here.

Question 2 - For clearing the database, perhaps you can write a migration that clears the db for you? The way I do it is use a little script I wrote that just drops and creates a db. It's for MySQL:

target(dropdb: "The description of the script goes here!") {
   def x = 'mysql -u root --password=XXXX -e "drop database yourdb; create database yourdb default character set utf8; " '.execute(); 
   x.waitFor()
    println "Exit Value ${x.exitValue()}"
}

setDefaultTarget(dropdb)
Jean Barmash
Great answer, and thanks for the links.
Mike Sickler
+1  A: 

Hi,

you should use the autobase plugin. It will run your migrations when the application starts. It has a script to convert from an xml changelog to a groovy one as well so you don't have to manually convert it.

cheers

Lee

leebutts
Its Helpful to know that Autobase is a light Groovy wrapper around Liquibase that provides a slick DSL for changesets that is more flexible than an XML file :-)
Colin Harrington
+1  A: 

Question #2: If you have particular changeSets you want to run every time, there is an "alwaysRun" attribute you can set on the changeSet tag.

Nathan Voxland
+1  A: 

For my money, it's easier to read the Liquibase Gant scripts and replicate what they do. They're simple and you'll have more insight into what's happening.

John Stoneham