【问题标题】:Why does Liquibase want to dropPrimaryKey and addPrimaryKey?为什么 Liquibase 要 dropPrimaryKey 和 addPrimaryKey?
【发布时间】:2015-07-29 02:00:52
【问题描述】:

我有使用 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 版

【问题讨论】:

    标签: postgresql liquibase


    【解决方案1】:

    已针对 Liquibase 3.4.1 https://liquibase.jira.com/browse/CORE-2416 修复此问题

    【讨论】:

      猜你喜欢
      • 2020-11-20
      • 2012-06-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-12
      • 2018-03-30
      • 2021-03-14
      • 2015-01-15
      相关资源
      最近更新 更多