Update is executing a changeset that was marked as executed when using Node

I have run

liquibase --changelog-file=changelog.postgresql.sql changelog-sync 

against an existing DB.

That worked fine and it did populate the databasechangelog table with the correct IDs and the correct number of changes, in my case 8. So there were 8 records in the table that did match the generated changelog from the sync. All looks perfect.

When I run update from the CLI it works:

liquibase update --changelog-file=changelog.postgresql.sql

But when I run update from Node with package require('liquibase').Liquibase

I get

ERROR: relation "mytable" already exists.

My Node code works when I don’t do changelog sync and just use the output from generate-changelog.

So node and liquibase do work in my code. If I add a column, update does it. All works good.

BUT if I do a Node update after changelog-sync it says file already exists, and if I do a CLI update it works.

1 Like

There are a few StackOverflow posts with a similar relation already exists error. This one suggests

You could use IF NOT EXISTS clause

Another says:

There will be a primary key with the same table name, try creating a table with serial as the primary key.

CREATE TABLE some_table ( some_table_id serial PRIMARY KEY, col1 integer NOT NULL, col2 integer NOT NULL );

refer:PostgreSQL Error: Relation already exists

If neither of these suggestions work, please copy and paste the entire output that you see when you run the commands using the “preformatted text” code block option in the editing tools so we can look into it further.

Thanks for your response. Yes this does solve my problem (if not exists). Thank you.