1

I'm trying to generate migration with diffChangeLog. And it looks like Liquibase detects data changes only when table schema was modified. In other words if you have two DBs with same table, and you will insert or update rows in this table, Liquibase do nothing on diffChangeLog event with --diffTypes="data" parameter. But if toy create new table and insert rows in this table Liquibase generate inserts perfectly.

Here are steps that I have made during my research:

1) Run two DBs:

>sudo docker run --rm --name pg-docker1 -e POSTGRES_PASSWORD=123 -d -p 5432:5432 -v $HOME/docker/volumes/postgres1:/var/lib/postgresql/data  postgres

>sudo docker run --rm --name pg-docker2 -e POSTGRES_PASSWORD=123 -d -p 5431:5432 -v $HOME/docker/volumes/postgres2:/var/lib/postgresql/data  postgres

2) Run SQL on first DB

create schema test_schema;
create table test_schema.table1
(
    id bigint not null
        constraint table1_pk
            primary key,
    description text
);

alter table test_schema.table1 owner to postgres;

insert into test_schema.table1 values(1, 'descr1');

3) Download liquibase and add posgress driver jar to lib

4) Generate changeLog and sync the Dbs

./liquibase --url="jdbc:postgresql://localhost:5432/postgres?currentSchema=test_schema" \
--username=postgres --password=123 \
--changeLogFile="./data-diff-1.xml" \
--diffTypes="data,tables,columns,views,primaryKeys,uniqueConstraints,indexes,foreignKeys,sequences" \
--includeSchema=true \
 generateChangelog

./liquibase --url="jdbc:postgresql://localhost:5431/postgres?currentSchema=test_schema" \
--username=postgres --password=123 \
--changeLogFile="./data-diff-1.xml" \
update

5) First DB modification:

update test_schema.table1 set description = 'descr1 modified' where id =1;

insert into test_schema.table1 values(2, 'descr2');

create table test_schema.table2
(
    id bigint not null
        constraint table2_pk
            primary key,
    field1 text
);

alter table test_schema.table2 owner to postgres;

insert into test_schema.table2 values(1, 'value1');

6) I'm trying to generate new migration with updates and inserts

./liquibase --url="jdbc:postgresql://localhost:5431/postgres?currentSchema=test_schema" \
--username=postgres --password=123 \
--changeLogFile="./data-diff-2.postgresql.sql" \
--diffTypes="data,tables,columns,views,primaryKeys,uniqueConstraints,indexes,foreignKeys,sequences" \
--includeSchema=true \
--referenceUrl="jdbc:postgresql://localhost:5432/postgres?currentSchema=test_schema" \
--referenceUsername=postgres --referencePassword=123 \
diffChangeLog

7) Result:

--changeset 1567884982174-1
CREATE TABLE test_schema.table2 (id BIGINT NOT NULL, field1 TEXT, CONSTRAINT table2_pk PRIMARY KEY (id));

--changeset 1567884982174-2
INSERT INTO test_schema.table2 (id, field1) VALUES (1, 'value1');

Question is: where are update test_schema.table1 and second insert into test_schema.table1 (values 2, 'descr2') ?

i.bondarenko
  • 3,442
  • 3
  • 11
  • 21

0 Answers0