我有使用Eclipse Link生成的Postgres数据库。在这些数据库之间没有任何变化,但是当我运行liquibase生成diffChangeLog时,它会使用dropPrimaryKey和addPrimaryKey生成更改集。我不明白为什么它为所有表的所有主键生成这些记录。两个表的名称,列顺序相同。
变更集的示例
<changeSet author="michal2 (generated)" id="1436872322297-8">
<dropPrimaryKey tableName="country_translation"/>
<addPrimaryKey columnNames="country_id, translations_id" constraintName="country_translation_pkey" tableName="country_translation"/>
</changeSet>
原始表的SQL
CREATE TABLE country_translation
(
country_id bigint NOT NULL,
translations_id bigint NOT NULL,
CONSTRAINT country_translation_pkey PRIMARY KEY (country_id, translations_id),
CONSTRAINT fk_country_translation_country_id FOREIGN KEY (country_id)
REFERENCES country (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT fk_country_translation_translations_id FOREIGN KEY (translations_id)
REFERENCES translation (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
)
WITH (
OIDS=FALSE
);
ALTER TABLE country_translation
OWNER TO hotels;
参考表的SQL
CREATE TABLE country_translation
(
country_id bigint NOT NULL,
translations_id bigint NOT NULL,
CONSTRAINT country_translation_pkey PRIMARY KEY (country_id, translations_id),
CONSTRAINT fk_country_translation_country_id FOREIGN KEY (country_id)
REFERENCES country (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT fk_country_translation_translations_id FOREIGN KEY (translations_id)
REFERENCES translation (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
)
WITH (
OIDS=FALSE
);
ALTER TABLE country_translation
OWNER TO hotels;
带参数的Liquibase命令
./liquibase \
--driver=org.postgresql.Driver \
--classpath=/home/michal2/tools/postgresql-jdbc-driver/postgresql-jdbc.jar \
--changeLogFile=changelog-hotels.xml \
--url="jdbc:postgresql://localhost/hotels" \
--username=hotels \
--password=hotels \
--defaultSchemaName=public \
--logLevel=info \
diffChangeLog \
--referenceUrl="jdbc:postgresql://localhost/hotels_liquibase" \
--referenceUsername=hotels \
--referencePassword=hotels \
--referenceDefaultSchemaName=public
我使用的是3.4.0版本