node.jsdatabase-migrationliquibaseliquibase-sql

NodeJS - Liquibase - Postgres is not working


It would be very helpful if anyone provide some insight on the below issue, I'm trying to build a NodeJS sample to update the PG DB using Liquibase changesets.

I've created a a postgres db successfully in my local using below commands,

CREATE DATABASE node_liquibase_testing;
CREATE USER dbmigration WITH ENCRYPTED PASSWORD 'password';
GRANT ALL PRIVILEGES ON DATABASE node_liquibase_testing TO dbmigration;

I've the below files in the same folder(main) level,

changelog.xml

<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" xmlns:pro="http://www.liquibase.org/xml/ns/pro" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/pro http://www.liquibase.org/xml/ns/pro/liquibase-pro-4.0.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.0.xsd">

    <changeSet author="sam" id="158">
        <createTable tableName="test">
            <column name="id" type="INTEGER"></column>
            <column name="name" type="VARCHAR(255)"/>
        </createTable>
    </changeSet>

</databaseChangeLog>

test.js

const LiquibaseTS = require('node-liquibase').Liquibase;
const POSTGRESQL_DEFAULT_CONFIG = require('node-liquibase').POSTGRESQL_DEFAULT_CONFIG;

const myConfig = {
  ...POSTGRESQL_DEFAULT_CONFIG,
  changeLogFile: './changelog.xml',
  url: 'jdbc:postgresql://localhost:5432/node_liquibase_testing',
  username: 'dbmigration',
  password: 'password',
}

const instTs = new LiquibaseTS(myConfig);
instTs.status();

I ran npm i node-liquibase in the terminal followed by node testing.js

I DID NOT SEE the test table created in the node_liquibase_testing database as expected. I see the below message printed in the terminal,

Starting Liquibase at 10:02:30 (version 4.1.1 #10 built at 2020-10-12 19:24+0000)
1 change sets have not been applied to dbmigration@jdbc:postgresql://localhost:5432/node_liquibase_testing
Liquibase command 'status' was executed successfully.

Solution

  • From what it looks, you only ran the status command. For example: instTs.status();

    The status command will just state if there are any pending changes or not.

    Try running/adding the update command to apply the database changes.

    Here are references to the update and status commands: https://docs.liquibase.com/commands/status/status.html https://docs.liquibase.com/change-types/update.html