Connect Liquibase with Node.js

Liquibase supports a rich pool of Liquibase Commands to keep your database up-to-date, like update, rollback, and diff. This package exposes both a CLI tool and a library to help you with your database migration efforts.

You can use these commands with NPM as you would with Liquibase by itself with the correct syntax. The NPM CLI tool is used just like Liquibase with node- in front of all commands. This integration allows you to utilize Liquibase in apps designed with JavaScript and TypeScript.

Connect Liquibase with Node.js context

By writing code in a JSON project file and calling it using the CLI, you can reuse the file and run the same commands more than once.

Procedure

1

Create a JSON file that defines your dependencies and commands.

Sample JSON file defining the version of the Liquibase node library and node manager to use and a build command.
loading
2

Enable package manager using the npm run build or run node main.js command in the CLI

Example calling a package.json file and building the package manager
loading
const Liquibase = require('liquibase').Liquibase;
const POSTGRESQL_DEFAULT_CONFIG = require('liquibase').POSTGRESQL_DEFAULT_CONFIG;

const myConfig = {
  ...POSTGRESQL_DEFAULT_CONFIG,
  changeLogFile: './changelog.xml',
  url: 'jdbc:postgresql://localhost:5432/node_liquibase_testing',
  username: 'yourusername',
  password: 'yoursecurepassword',
}
const instTs = new Liquibase(myConfig);

instTs.status();