Liquibase does not generate consistent data difference of two databases

青春壹個敷衍的年華 提交于 2019-12-07 08:24:01

问题


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') ?

来源:https://stackoverflow.com/questions/57839809/liquibase-does-not-generate-consistent-data-difference-of-two-databases

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!