为什么Liquibase要dropPrimaryKey和addPrimaryKey?
Why does Liquibase want to dropPrimaryKey and addPrimaryKey?
我有使用 Eclipse 生成的 Postgres 数据库 Link。这些数据库之间没有任何变化,但是当我 运行 liquibase 用于生成 diffChangeLog 时,它会生成带有 dropPrimaryKey 和 addPrimaryKey 的变更集。我不明白为什么它会为所有 table 的所有主键生成这些记录。 table 的名称、列顺序相同。
变更集示例
<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 原来 table
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 参考 table
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 版本
Liquibase 3.4.1 已修复此问题https://liquibase.jira.com/browse/CORE-2416
我有使用 Eclipse 生成的 Postgres 数据库 Link。这些数据库之间没有任何变化,但是当我 运行 liquibase 用于生成 diffChangeLog 时,它会生成带有 dropPrimaryKey 和 addPrimaryKey 的变更集。我不明白为什么它会为所有 table 的所有主键生成这些记录。 table 的名称、列顺序相同。
变更集示例
<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 原来 table
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 参考 table
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 版本
Liquibase 3.4.1 已修复此问题https://liquibase.jira.com/browse/CORE-2416