检查数据库完整性的最佳方法是什么?

我想将一个论坛的用户、主题和帖子合并到另一个论坛中。虽然论坛在开发环境中恢复时没有问题,但在尝试合并时(目前是在全新安装中)却遇到了 PG::ForeignKeyViolation 错误。因此,我想知道是否有 Discourse 工具可以检查数据库的完整性?如果没有,是否有任何其他提示或建议?

(关于数据库问题也有过一些讨论,因此我在想,如果目前还没有这样的工具,DC 团队是否认为有必要开发这样一个工具?)

我手动对比了一个运营超过 5 年的 Discourse 论坛的架构和一个全新安装的架构,差异如下:

https://www.diffchecker.com/lZrp2jxJ

主要是将 bigint 改为 integer,将 character varying(255) 改为 character varying,以及缺少了一些 not null 约束,但也缺少了一些索引。

以下是指出这些差异的行:

第 1646 行 - 缺失:

  Index "public.index_badges_on_badge_type_id"
 Column |          Type          | Key? | Definition 		    Column     |  Type   | Key? |  Definition   
--------+------------------------+------+------------		---------------+---------+------+---------------
 name   | character varying(255) | yes  | name		 badge_type_id | integer | yes  | badge_type_id
btree, for table "public.badges"

第 3301 行 - 缺失:

	Index "public.index_user_badges_on_user_id"
 Column  |  Type   | Key? | Definition 
---------+---------+------+------------
 user_id | integer | yes  | user_id
btree, for table "public.user_badges"

第 4639 行 - 缺失:

	      Index "public.schema_migrations_pkey"
 Column  |       Type        | Key? | Definition 
---------+-------------------+------+------------
 version | character varying | yes  | version
primary key, btree, for table "public.schema_migrations"

第 5487 行 - 部分缺失:

                                       Table "public.topic_search_data"
   Column    |          Type          | Collation | Nullable | Default 		   Column    |       Type        | Collation | Nullable |                       Default                       
-------------+------------------------+-----------+----------+---------		-------------+-------------------+-----------+----------+-----------------------------------------------------
 topic_id    | integer                |           | not null | 		 topic_id    | integer           |           | not null | nextval('topic_search_data_topic_id_seq'::regclass)
 raw_data    | text                   |           |          | 		 raw_data    | text              |           |          | 
 locale      | character varying(255) |           | not null | 		 locale      | character varying |           | not null | 
 search_data | tsvector               |           |          | 		 search_data | tsvector          |           |          | 
 version     | integer                |           |          | 0		 version     | integer           |           |          | 0

第 5506 行 - 缺失:

           Sequence "public.topic_search_data_topic_id_seq"
  Type   | Start | Minimum |  Maximum   | Increment | Cycles? | Cache 
---------+-------+---------+------------+-----------+---------+-------
 integer |     1 |       1 | 2147483647 |         1 | no      |     1
Owned by: public.topic_search_data.topic_id

第 6044 行 - 缺失:

    "index_user_badges_on_user_id" btree (user_id)

我需要对这些问题担心吗?我应该手动添加这些索引吗?还有其他想法或有什么特别需要注意的地方吗(这里快凌晨 5 点了,我快撑不住眼皮了 :see_no_evil:)