1.0.7 • Published 1 year ago

liquibase-node v1.0.7

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Website Website Twitter Follow NPM NPM GitHub repo size


twitterlinkedinstackoverflowgithubyoutube

This is forked project with maintained and updated dependencies

Node and Liquibase Use Node and databases? Want to do smart architecture decisions? Do not invent wheel, use Liquibase. Liquibase is an open-source database-independent library for tracking, managing and applying database schema changes.

Concerned About Install Size?

For a drastically smaller version of this package, be sure to check out our Zero-Dependency Peer-Dependency version. You can access this version under the tag @pd for Peer Dependency. This version of the package boasts an unpacked size of 359 kB. Just be sure to correctly configure your project!

Table of Contents

Installation

There is an easy way to integrate Liquibase power to Node application. All you need is NPM package.

yarn add liquibase

or:

$ NPM install --save liquibase

Sandbox

"If this isn't making sense, it doesn't make it lies." (Cornell, 1994).

We have also provided a Small Sandbox Project where you can easily evaluate Liquibase and node-liquibase against a Postgres Database.

The Sandbox project includes startup scripts, and examples to demonstrate how to use node-liquibase in TypeScript, JavaScript, and as a CLI tool.

Usage

Liquibase support rich pool of commands to keep your database up-to-date, like update, rollback, diff check out full list here: https://docs.liquibase.com/commands/home.html.

This package exposes both a CLI tool and a Library to help you in your Database Migration efforts!

CLI

You can use this NPM package as a CLI tool under the namespace node-liquibase if you wish.

Bundled Liquibase Executable

node-liquibase
--changeLogFile="/path/to/my/changelog.xml"
--url="jdbc:postgresql://localhost:5432/postgres"
--username="yourusername"
--password="yoursecurepassword"
--classpath="/Users/me/path/to/my/db-drivers/postgresql-42.2.8.jar"
status

Liquibase Executable "Peer Dependency"

node-liquibase /Users/me/path/to/my/executable/for/liquibase
 --changeLogFile="/path/to/my/changelog.xml"
 --url="jdbc:postgresql://localhost:5432/postgres"
 --username="yourusername"
 --password="yoursecurepassword"
 --classpath="/Users/me/path/to/my/db-drivers/postgresql-42.2.8.jar"
 status

In Your Project Files

TypeScript

import {
	LiquibaseConfig,
	Liquibase,
	POSTGRESQL_DEFAULT_CONFIG,
} from 'liquibase';

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

async function doEet() {
	await instance.status();
	// await instance.update();
	// await instance.dropAll();
}

doEet();

JavaScript

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();

Features

TypeScript

Before

The previous project did not have the greatest experience for TypeScript environments. In addition, one of our goals was improving the DX for JavaScript engineers as well. Luckily, a lot of popular Text Editors are improving their IntelliSense featuresets.

Now

With the new package you can will get:

  • Liquibase command documentation right at your fingertips
  • Liquibase command Parameter documentation
  • Liquibase CLI Command API Parity

https://user-images.githubusercontent.com/32392635/115454680-ac49cd80-a1e6-11eb-85fa-df91caf4a7f6.mp4

Library and CLI

In order to keep the DX as smooth as possible without deprecating the project that inspired the re-write, we've provided both an NPM package and a CLI tool. We did this by transpiling both an ES Module and a Common JS module in the dist code. The Node CLI of this package can be used with node-liquibase.

However, when importing the modules to use them in a JavaScript or TypeScript file, be sure to import from the correct module name: liquibase. We are forced to keep this package name for now due to dependent projects.

Liquibase CLI Command API Parity

We were careful to ensure that all 'top level' Liquibase commands are implemented in this package. No more magic strings!

Here's a complete listing of commands that have been implemented.

Liquibase CLI Peer Dependency (Optional)

WIP

WTR!? (Why The Re-write!?)

The original fork of this project has been left intact to give credit where credit is due. As an Organization, Liquibase can be summarized as follows: No punks, no jerks. Because of this, we cannot ignore pablodenadai/node-liquibase. It was these efforts that ultimately led to the decision to improve on that project.

TypeScript

At Liquibase we are avid TypeScript users, so naturally we expect the developer experience we're accustomed to out of our own packages. In order to provide the DX we would want, we needed to rethink how this library was implemented.

Adding TypeScript support was at the core of this.

No Magic Strings!

Magic strings, while functional, are error prone. Instead of passing a string of the command and parameters to Liquibase, we've replicated the top level Liquibase CLI API within this package.

Our aim is to provide a more stable and guided API for new Liquibase users operating in a Node context.

This means no more of this:

liquibase.run('status');

and more of this:

liquibase.status();

Bundled Releases

In order to make installation of Liquibase easier for people who are new to the Liquibase toolset, we've chosen to release 'bundled' versions of this project, node-liquibase. This means that if you are beholden to a particular version of Liquibase Core you will be able to install a related specific version of node-liquibase and have Liquibase Core ready at your fingertips.

This makes the assumption that a consumer of node-liquibase wants that. If this is not true and you prefer to make use of a more peer dependency type of experience, we offer a version of node-liquibase that DOES NOT bundle an associated version of Liquibase Core.

Bundled Version Numbers

Because Liquibase Core and node-liquibase both use a similar versioning strategy, and because NPM requires a version number bump for even the smallest change, there will not be 100% alignment between the version numbers of each project.

It is safe to assume that the Major and Minor version numbers between the two projects will match on any given npm installation of node-liquibase.

For example:

  • Let's assume you are required to use Liquibase Core v4.3.3
  • node-liquibase released 4.3.3 alongside Liquibase Core, but needed to update documentation after the fact
  • node-liquibase patches its version number and releases 4.3.4
  • As a User, you could run yarn add liquibase@4.3 which would install the latest patch version of 4.3 in this case 4.3.4
  • The "Bundled Liquibase" version would still be 4.3.3 but node-liquibase would be 4.3.4

If you wish to opt-out of the "Bundled Version" you can check out our Peer Dependency release.

Peer Dependency (@pd)

Install

In order to use this p[eer]-d[ependency] version of node-liquibase you can install with:

yarn add liquibase@pd

or

npm i liquibase@pd

Depending on your implementation method of choice (TS, JS, or CLI), you will need to let node-liquibase know where it can find your liquibase executable. This should be an absolute path to the executable.

Additionally, we removed the bundled drivers from the @pd release to further reduce the size of your node_modules. There is a chance you will need to update your configurations to provide an absolute path on the classpath property to the drivers you need.

Configuration Updates (TS or JS)

Using the liquibase property on your config object.

Before

import { Liquibase, LiquibaseConfig, POSTGRESQL_DEFAULT_CONFIG } from 'liquibase';

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

inst.status();

After

import { Liquibase, LiquibaseConfig, POSTGRESQL_DEFAULT_CONFIG } from 'liquibase';

const myConfig: LiquibaseConfig = {
  ...POSTGRESQL_DEFAULT_CONFIG,
  changeLogFile: './changelog.xml',
  url: 'jdbc:postgresql://localhost:5432/node_liquibase_testing',
  username: 'yourusername',
  password: 'yoursecurepassword',
  liquibase: 'Users/me/absolute/path/to/executable/directory'
}
const inst = new Liquibase(myConfig);

inst.status();

Configuration Updates (CLI)

Using the --liquibase flag on your CLI command.

Before

yarn node-liquibase --changeLogFile="changelog.xml" --url="jdbc:postgresql://localhost:5432/node_liquibase_testing" --username="yourusername" --password="yoursecurepassword" --classpath="/Users/me/path/to/my/db-drivers/postgresql-42.2.8.jar" status

After

yarn node-liquibase --liquibase="Users/me/absolute/path/to/executable/directory" --changeLogFile="changelog.xml" --url="jdbc:postgresql://localhost:5432/node_liquibase_testing" --username="yourusername" --password="yoursecurepassword" --classpath="/Users/me/path/to/my/db-drivers/postgresql-42.2.8.jar" status

Sandbox: @pd

If you'd like to see a working setup of liquibase@pd be sure to check out the peer-dependency branch of the Node Liquibase Sandbox. You can see a diff of the two approaches (Bundled v. Peer) Here

Want to Help?

This project needs some work on the infrastructure and build tooling side. For now the workflow to test an 'end user ready' version of the project, you'll first need to build/compile the code, and then you can run it using the Node CLI's REPL node path/to/something.js.

There is an issue in path resolution within THIS application code in addition to the complexities in Liquibase Core. Until this is resolved the resolved path for the Liquibase executable will differ between compiled and source code. This will affect your experience if you try to transpile the code on the fly using ts-node. I have not resolved the issue yet.

Build

To build all of the things:

yarn build

Tests

Run tests with:

yarn test

Env Vars

To substitute your own user/pass for a given environment, make a copy of .env.example in root directory as .env and update accordingly.

Getting More Knowledge About Liquibase

Liquibase CLI

Download Liquibase CLI

1.0.7

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago