I’ve been playing around with node.js quite a lot recently and learning about the tools ecosystem. One tool that seems to be getting a lot of attention recently is Grunt - which is billed as “The JavaScript Task Runner”. This seems to be the tool that people are suggesting should be used for automating node.js builds and other tasks.

In the little project that I’ve been playing around with I want to have a database. One of the things that we’ve found really useful developing Vollow.me has been liquibase. Liquibase has proved invaluable as we’ve made modifications and updates to our database schema and we’ve integrated it into our continuous build and deployment system.

This experience makes me want to integrate liquibase into my node project and to do that I think I need to get it working with grunt.

There currently isn’t a grunt plugin or a node module for calling liquibase - at some point I’ll probably get round to creating one - but for now I just want to get it up and running with grunt.

Reading through what plugins are available for grunt, the simplest integration I can see is to use grunt-shell to call out to liquibase jar and run my changelog file.

First off we need grunt-shell installed:

npm install --save-dev grunt-shell


And now we can create a Gruntfile with a task definition to call liquibase:

module.exports = function(grunt) {
grunt.initConfig({
shell: {
liquibase: {
options: {
stdout: true,
stderr : true
},
command: 'java -jar liquibase.jar ' +
'--changeLogFile changelog.xml '+
'--url jdbc:postgresql://DB_HOST:DB_PORT/DB_NAME ' +
'--driver org.postgresql.Driver '+
'--classpath postgresql-9.3-1100.jdbc41.jar ' +
'update'
}
}
});
};


Now we can run grunt and apply our changeset to our database:

\$ grunt shell:liquibase