npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

grunt-liquibase

v1.1.0

Published

Simple integration of liquibase with grunt - core. Plugins for DB drivers exist for postgresql, mysql

Downloads

169

Readme

grunt-liquibase Build Status Code Climate Issue Count

Simple integration of liquibase with grunt - plugins for DB drivers exist for postgresql, mysql

Getting Started

This plugin requires Grunt >=0.4.0

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

npm install grunt-liquibase --save-dev

Note: In order to be able to use grunt-liquibase you need to install one of the database driver plugins as well: PostgreSQL, MySQL

npm install flocsy/grunt-liquibase-<DRIVER> --save-dev

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks('grunt-liquibase-<DRIVER>');

The "liquibase" task

Overview

In your project's Gruntfile, add a section named liquibase to the data object passed into grunt.initConfig().

grunt.initConfig({
  liquibase: {
    options: {
      username: 'DB_USERNAME',
      password: 'DB_PASSWORD',
      url: 'jdbc:postgresql://DB_HOST:DB_PORT/DB_NAME'
    },
    updateSQL: {
      command: 'updateSQL'
    },
    version: {
      command: 'version'
    }
  },
});

Optionally instead of the url you can pass the hostname and database in driver_options and let the driver-plugin to add the url for you:

grunt.initConfig({
  liquibase: {
    options: {
      username : 'DB_USERNAME',
      password : 'DB_PASSWORD'
    },
    driver_options: {
      hostname: 'localhost',
      database: 'test_db'
    },

    update: {
      command: 'update'
    }
  },
});

Dry Run Support

If running grunt with the --no-write CLI flag, then no liquibase commands will be excuted. This is useful for performing a dry run to verify that the liquibase commands are being formed as you expect.

Example:

grunt liquibase:update --no-write --verbose

Produces:

...
Will excecute:update
Command: java -jar /Users/grunt-liquibase/lib/liquibase.jar --classpath /Users/grunt-liquibase/lib/postgresql-9.3-1100.jdbc41.jar --driver org.postgresql.Driver --logLevel info --username test_username --password test_password --url jdbc:postgresql://DB_HOST:DB_PORT/DB_NAME --changeLogFile changelog.xml update
>> no-write specified, not running command

Options

options.liquibaseJarPath

Type: String Default value: lib/liquibase.jar

Database jar path - passed into the --liquibaseJarPath argument to liquibase.

options.username

Type: String Default value: NONE - required

Database user - passed into the --username argument to liquibase.

options.password

Type: String Default value: NONE - required

Database password - passed into the --password argument to liquibase.

options.url

Type: String Default value: NONE - required

JDBC url - passed into the --url argument to liquibase.

options.changeLogFile

Type: String Default value: changelog.xml

Path to the changelog file for liquibase.

options.classpath

Type: String Default value: postgresql-9.3-1100.jdbc41.jar

Path to the jar file containing the jdbc driver. The module contains this jar file so you don't need it if you are talking to a postgresql database. Passed into the --classpath argument to liquibase.

options.driver

Type: String Default value: org.postgresql.Driver

JDBC driver class. Passed into the --driver argument to liquibase.

options.defaultSchemaName

Type: String Default value: null

Default schema name

options.defaultsFile

Type: String Default value: null

Liquibase properties file path

options.logLevel

Type: String Default value: info

Liquibase logLevel

Supported Commands

update

Runs all changesets in the changeLogFile

dropAll

Drops all database objects owned by the user. Note that functions, procedures and packages are not dropped

rollback

Rollback changesets in the changeLogFile to a specific tag. Must also supply the target tag as the commandAttr.

Example

Rollback to version 0.0.1

grunt.initConfig({
  liquibase: {
    options: {
      username : 'dbuser',
      password : 'passwd',
      url : 'jdbc:postgresql://localhost:5432/test_db'
    },
    rollback: {
      command: 'rollback',
      commandAttr: 'v0.0.1'
    }
  },
});

rollbackCount

Rollback up to N changesets in the changeLogFile. Must also supply the number of changesets to rollback in the commandAttr.

Example

Rollback the last 3 changesets

grunt.initConfig({
  liquibase: {
    options: {
      username : 'dbuser',
      password : 'passwd',
      url : 'jdbc:postgresql://localhost:5432/test_db'
    },
    rollback: {
      command: 'rollbackCount',
      commandAttr: '3'
    }
  },
});

tag

"Tags" the current database state for future rollback. Must also supply the desired tag name in the commadAttr.

Example

Tag the current DB with v0.1.2.

grunt.initConfig({
  liquibase: {
    options: {
      username : 'dbuser',
      password : 'passwd',
      url : 'jdbc:postgresql://localhost:5432/test_db'
    },
    tag: {
      command: 'tag',
      commandAttr: 'v0.1.2'
    }
  },
});

changelogSync

Marks all changesets in the changeLogFile as run in the database. Useful when you are not starting from a empty database.

changelogSyncSQL

Outputs the SQL to mark all changesets in the changeLogFile as run in the database. This allows DBAs to validate the SQL and then run it manually against the necessary database.

clearCheckSums

Clears checksums so they can be recalculated in the next run.

Usage Examples

Default Options

In this example, the default options are used to update a postgresql database called test_db running on localhost at port 5432 using the user dbuser with password passwd with the contents of changelog.xml

grunt.initConfig({
  liquibase: {
    options: {
      username : 'dbuser',
      password : 'passwd',
      url : 'jdbc:postgresql://localhost:5432/test_db'
    },
    command: 'update'
  },
});

Custom Options

In this example, the location of the changelog file is modified.

grunt.initConfig({
  liquibase: {
    options: {
      username : 'dbuser',
      password : 'passwd',
      url : 'jdbc:postgresql://localhost:5432/test_db',
      changelog : 'src/database/dbchangelog.xml'
    },
    command: 'update'
  },
});

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.