开发者

How to integrate a Liquibase migration into my grails build?

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 D开发者_StackOverflowATABASECHANGELOG 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?


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)


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.


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.


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜