This project is an example to show that sequence usage in <loadData />
with PostgreSQL is not working properly.
Liquibase will generate a proper SQL statement in migrate.sql but it can not execute the changeset correctly by itself.
-
Start a PostgreSQL instance. If you have docker installed on you machine, you can make use of the
docker-compose.yml
file withdocker-compose up -d
. This will start a PostgreSQL container on port9876
with default credentials. You can remove / reset this container by usingdocker-compose down
. To reset and immediately restart you can usedocker compose down && docker-compose up -d
. -
(Optional) If you don't use the
docker-compose.yml
file or changed the file please adaptliquibase.properties
to match your DB settings. -
Run
./mvnw clean compile liquibase:updateSQL
and checktarget/migrate.sql
it contains the following line, which is what I expected:INSERT INTO "user" (id, name) VALUES (nextval('id_seq'), 'user1'),(nextval('id_seq'), 'user2');
-
Run
./mvnw clean compile liquibase:update
and you will get an error stating that you wanted to insertNULL
as the value forid
, which is not allowed by a constraint:[ERROR] Change Set db/changelog/db.changelog.xml::3::d3ns0n failed. Error: java.sql.BatchUpdateException: Batch entry 0 INSERT INTO "user"(id, name) VALUES(NULL, 'user1') was aborted: ERROR: null value in column "id" violates not-null constraint Detail: Failing row contains (null, user1). Call getNextException to see other errors in the batch.