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 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) {
  		shell: {
	        liquibase: {
	            options: {
	                stdout: true,
	                stderr : true
	            command: 'java -jar liquibase.jar ' +
	                     '--changeLogFile changelog.xml '+
	                     '--username DB_USERNAME ' +
	                     '--password DB_PASSWORD ' +
	                     '--url jdbc:postgresql://DB_HOST:DB_PORT/DB_NAME ' +
	                     '--driver org.postgresql.Driver '+
	                     '--classpath postgresql-9.3-1100.jdbc41.jar ' +

I’ve downloaded the liquibase.jar and postgresql jdbc driver already.

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

$ grunt shell:liquibase
Running "shell:liquibase" (shell) task
Liquibase Update Successful

Done, without errors.

Next step will be to try and package up liquibase in a proper grunt task. We should also probably be reading our database settings from somewhere as well (I’ve hard coded mine for now). But that’s a job for tomorrow…

Why not subscribe to my mailing list - I'll send out regular emails with new content (don't worry I won't spam you!)

* indicates required
Blog Logo

Chris Greening



Chris Greening

Blogging about random stuff

Back to Overview