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.
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!
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
"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.
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!
You can use this NPM package as a CLI tool under the namespace node-liquibase
if you wish.
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.4.2.jar"
status
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.4.2.jar"
status
import {
LiquibaseConfig,
Liquibase,
} from 'liquibase';
const myConfig: LiquibaseConfig = {
changeLogFile: './changelog.xml',
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();
const Liquibase = require('liquibase').Liquibase;
const myConfig = {
changeLogFile: './changelog.xml',
url: 'jdbc:postgresql://localhost:5432/node_liquibase_testing',
username: 'yourusername',
password: 'yoursecurepassword',
}
const instTs = new Liquibase(myConfig);
instTs.status();
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.
With the new package you can will get:
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.
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.
WIP
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.
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.
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();
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.
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:
v4.3.3
node-liquibase
released 4.3.3
alongside Liquibase Core, but needed to update documentation after the factnode-liquibase
patches its version number and releases 4.3.4
yarn add liquibase@4.3
which would install the latest patch version of 4.3
in this case 4.3.4
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.
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.
Using the liquibase
property on your config object.
import { Liquibase, LiquibaseConfig, POSTGRESQL_DEFAULT_CONFIG } from 'liquibase';
const myConfig: LiquibaseConfig = {
changeLogFile: './changelog.xml',
url: 'jdbc:postgresql://localhost:5432/node_liquibase_testing',
username: 'yourusername',
password: 'yoursecurepassword',
}
const inst = new Liquibase(myConfig);
inst.status();
import { Liquibase, LiquibaseConfig, POSTGRESQL_DEFAULT_CONFIG } from 'liquibase';
const myConfig: LiquibaseConfig = {
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();
Using the --liquibase
flag on your CLI command.
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.4.2.jar" status
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.4.2.jar" status
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
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.
To build all of the things:
npm run build
Run tests with:
npm run test
To substitute your own user/pass for a given environment, make a copy of .env.example
in root directory as .env
and update accordingly.
This guide outlines the process for adding or modifying Liquibase commands in the Liquibase Node package. It's designed for developers who want to extend the functionality of the package.
Files to be Changed:
src/commands-with-positional-arguments.ts
src/liquibase-commands.enum
node-liquibase/src/models/commands
(corresponding command file)node-liquibase/src/liquibase.spec.ts
node-liquibase/src/liquibase.ts
Follow these steps carefully to extend the functionality of the Liquibase Node package according to your requirements.
Note: Ensure you follow proper coding conventions and thoroughly test your changes before deploying them.
This guide assumes familiarity with TypeScript and the Liquibase Node package structure. If you encounter any issues, refer to the Liquibase Node package documentation or seek assistance from the community.
commands-with-positional-arguments.ts
and liquibase-commands.enum
src
directory of the Liquibase Node package.commands-with-positional-arguments.ts
and liquibase-commands.enum files
.node-liquibase/src/models/commands
node-liquibase/src/models/commands
directory.node-liquibase/src/liquibase.spec.ts
node-liquibase/src
directory.liquibase.spec.ts
file.node-liquibase/src/liquibase.ts
node-liquibase/src
directory.liquibase.ts
file.liquibase.spec.ts
.There is GitHub action executed on every Liquibase release. This GitHub Action automates the generation of Liquibase command list and protobuf files for a specified Liquibase version.
protobuf-compiler
and npm packages.liquibase-protobuf-generator
specific to the provided Liquibase version.JSON
file containing a list of Liquibase commands supported by the specified version.JSON
file, executes Docker commands to generate protobuf files for each command, and then moves the generated TypeScript files to a directory named proto-commands
.This action streamlines the process of updating Liquibase-related files and creating pull requests for version updates.
After the PR is created you can see potential new/modified liquibase commands and proced to update this module following the steps shown at Extending Liquibase Node Package: Step-by-Step Guide