简体   繁体   English

如何正确地将主键添加到 Liquibase 的 databasechangelog(PostgreSQL)?

[英]How to correctly add a primary key to databasechangelog(PostgreSQL) for Liquibase?

I try to migrate database from old PostgreSQL (9.3) to new PostgreSQL(9.5, 9.6) by Bucardo.我尝试通过 Bucardo 将数据库从旧的 PostgreSQL (9.3) 迁移到新的 PostgreSQL(9.5, 9.6)。

Bucardo used Primary key for migrate. Bucardo 使用主键进行迁移。

I have many databases with public.databasechangelog without Primary key.我有很多没有主键的带有 public.databasechangelog 的数据库。 How correct add primary key to databasechangelog(PostgreSQL) for Liquibase?如何正确地将主键添加到 Liquibase 的 databasechangelog(PostgreSQL)?

Update answer: I can add Primary Key by SQL, but may be Liquibase have setting for added Primary key in XML?更新答案:我可以通过 SQL 添加主键,但 Liquibase 可能设置了在 XML 中添加主键的设置?

Safely added Primary Key by SQL to public.databasechangelog ?通过 SQL 安全地将主键添加到 public.databasechangelog ?

The Liquibase developers decided to remove the primary key on that table because apparently some DBMS have a problem with creating an index on those three columns due to limits on the maximum size of an index entry. Liquibase 开发人员决定删除该表上的主键,因为显然某些 DBMS 由于对索引条目的最大大小的限制而无法在这三列上创建索引。

See eg this discussion: http://forum.liquibase.org/topic/why-does-databasechangelog-not-have-a-primary-key参见例如这个讨论: http : //forum.liquibase.org/topic/why-does-databasechangelog-not-have-a-primary-key

Postgres is not subject to those limits, so you should be fine just adding one: Postgres 不受这些限制的限制,因此您只需添加一个就可以了:

alter table databasechangelog add primary key (id, author, filename);

I create DATABASECHANGELOG table at the beginning with primary key.我在开始时使用主键创建了 DATABASECHANGELOG 表。 This may not the correct way, but it will help这可能不是正确的方法,但它会有所帮助

CREATE TABLE "DATABASECHANGELOG" (
  "ID" varchar(255) NOT NULL,
  "AUTHOR" varchar(255) NOT NULL,
  "FILENAME" varchar(255) NOT NULL,
  "DATEEXECUTED" datetime NOT NULL,
  "ORDEREXECUTED" varchar(10) NOT NULL,
  "EXECTYPE" varchar(45) NOT NULL,
  "MD5SUM" varchar(35) DEFAULT NULL,
  "DESCRIPTION" varchar(255) DEFAULT NULL,
  "COMMENTS" varchar(255) DEFAULT NULL,
  "TAG" varchar(255) DEFAULT NULL,
  "LIQUIBASE" varchar(20) DEFAULT NULL,
  "CONTEXTS" varchar(255) DEFAULT NULL,
  "LABELS" varchar(255) DEFAULT NULL,
  "DEPLOYMENT_ID" varchar(10) DEFAULT NULL,
  PRIMARY KEY ("ID")
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Liquibase databasechangelog xml 文件 - 如何在 postgresql 中创建枚举 - Liquibase databasechangelog xml file - how to create enum in postgresql 如何将 id 添加到 postgresql 中的主键? - How to add id to a primary key in postgresql? Liquibase maven 插件:找不到数据库更改日志表,PostgreSQL - Liquibase maven plugin: cannot find the databasechangelog table, PostgreSQL Liquibase / PostgreSQL:如何正确保存表格案例? - Liquibase/PostgreSQL: how to preserve table case correctly? 如何在 PostgreSQL 中向现有表添加自动递增主键? - How to add an auto-incrementing primary key to an existing table, in PostgreSQL? 如何使用 Liquibase 将生成的列添加到 PostgreSQL 表中? - How to add a generated column to a PostgreSQL table with Liquibase? Python中的PostgreSQL表添加自增主键 - Add Autoincrement primary key to PostgreSQL table in Python Postgresql 使用约束将主键添加为串行 - Postgresql add primary key as serial using contraint Postgresql将现有列添加到复合主键 - Postgresql add existing column to composite primary key 尝试通过liquibase,postgresql,spring boot创建新数据库。 结果->“数据库更改日志”不存在 - Trying to create new database via liquibase, postgresql, spring boot. Result-> “databasechangelog” does not exist
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM