# Was ist der beste Weg, um die Integrität der Datenbank zu überprüfen?

**URL:** <https://meta.discourse.org/t/what-is-the-best-way-to-check-the-integrity-of-the-database/140670>\
**Category:** Migration\
**Created:** [5. Februar 2020 um 02:40 UTC](https://meta.discourse.org/t/what-is-the-best-way-to-check-the-integrity-of-the-database/140670 "2020-02-05T02:40:07Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![AstonJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/astonj/32/215041_2.png) [@AstonJ](https://meta.discourse.org/u/AstonJ)\
**Post date:** [5. Februar 2020 um 04:26 UTC](https://meta.discourse.org/t/what-is-the-best-way-to-check-the-integrity-of-the-database/140670/2 "2020-02-05T04:26:52Z")

</div>

Ich habe manuell einen Diff der Schemas zwischen einem Discourse-Forum, das vor über 5 Jahren erstellt wurde, und einer frischen Installation durchgeführt. Die Unterschiede können Sie hier einsehen:

[https://www.diffchecker.com/lZrp2jxJ](https://www.diffchecker.com/lZrp2jxJ)

Es handelt sich hauptsächlich um Änderungen von `bigint` zu `integer` und von `character varying(255)` zu `character varying` sowie einige fehlende `NOT NULL`-Einschränkungen. Zudem fehlen einige Indizes.

Hier sind die Zeilen, die diese aufzeigen:

**Zeile 1646 – fehlt:**

```sql
  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"

```

**Zeile 3301 – fehlt:**

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

```

**Zeile 4639 – fehlt:**

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

```

**Zeile 5487 – teilweise fehlt:**

```plaintext
                                       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

```

**Zeile 5506 – fehlt:**

```plaintext
           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

```

**Zeile 6044 – fehlt:**

```plaintext
    "index_user_badges_on_user_id" btree (user_id)

```

Sollte ich mir darüber Sorgen machen? Soll ich die Indizes manuell hinzufügen? Hast du noch andere Gedanken oder fällt dir sonst noch etwas auf? (Es ist hier fast 5 Uhr morgens, und ich kämpfe darum, die Augen offen zu halten 🙈)

---

_[View the full topic](https://meta.discourse.org/t/what-is-the-best-way-to-check-the-integrity-of-the-database/140670)._
