github.com/RedHatInsights/insights-results-aggregator@v1.4.1/docs/db_structure.md (about)

     1  ---
     2  layout: page
     3  nav_order: 5
     4  ---
     5  # DB structure
     6  {: .no_toc }
     7  
     8  ### Note
     9  
    10  Please look [at detailed schema
    11  description](https://redhatinsights.github.io/insights-results-aggregator/db-description/)
    12  for more details about tables, indexes, and keys.
    13  
    14  ## Table of contents
    15  {: .no_toc .text-delta }
    16  
    17  1. TOC
    18  {:toc}
    19  
    20  ## List of tables
    21  
    22  ```
    23   Schema |                Name                | Type
    24  --------+------------------------------------+------
    25   public | cluster_rule_toggle                | table
    26   public | cluster_rule_user_feedback         | table
    27   public | cluster_user_rule_disable_feedback | table
    28   public | consumer_error                     | table
    29   public | migration_info                     | table
    30   public | recommendation                     | table
    31   public | report                             | table
    32   public | rule_hit                           | table
    33   public | advisor_ratings                    | table
    34  ```
    35  
    36  ## Table `report`
    37  
    38  This table is used as a cache for reports consumed from broker. Size of this
    39  table (i.e. number of records) scales linearly with the number of clusters,
    40  because only latest valid report for given cluster is stored (it is guarantied
    41  by DB constraints). That table has defined compound key `org_id+cluster`,
    42  additionally `cluster` name needs to be unique across all organizations.
    43  Additionally `kafka_offset` is used to speedup consuming messages from Kafka
    44  topic in case the offset is lost due to issues in Kafka, Kafka library, or
    45  the service itself (messages with lower offset are skipped):
    46  
    47  ```sql
    48  CREATE TABLE report (
    49      org_id          INTEGER NOT NULL,
    50      cluster         VARCHAR NOT NULL UNIQUE,
    51      report          VARCHAR NOT NULL,
    52      reported_at     TIMESTAMP,
    53      last_checked_at TIMESTAMP,
    54      kafka_offset    BIGINT NOT NULL DEFAULT 0,
    55      PRIMARY KEY(org_id, cluster)
    56  )
    57  ```
    58  
    59  We consider a report as valid if it includes all the required fields described
    60  in the [agreed-upon report structure](
    61  https://redhatinsights.github.io/insights-data-schemas/external-pipeline/ccx_data_pipeline.html#format-of-the-report-node).
    62  
    63  If any of those fields is missing, we interpret it as a malformed report, most-
    64  probably due to an error when the Insights Core engine processed the archive. In
    65  that situation, the processing of the archive is aborted without storing any new
    66  information in the databases. Therefore, it is important to understand the
    67  difference between:
    68  - an **empty** report, which is stored in the databases, as it indicates that any
    69  previously found issue in the cluster has been resolved or is no longer happening.
    70  - a **malformed** report, which can be empty but is missing required attributes,
    71  and is not stored in the database as there is no guarantee that it represents the
    72  latest state of the cluster.
    73  
    74  To learn more about Insights Core processing, please refer to the [Red Hat Insights Core](
    75  https://insights-core.readthedocs.io/en/latest/intro.html#id1) documentation.
    76  
    77  
    78  ## Table `rule_hit`
    79  
    80  This table represents the content for Insights rules to be displayed by OCM.
    81  
    82  ```sql
    83  CREATE TABLE rule_hit (
    84      org_id         INTEGER NOT NULL,
    85      cluster_id     VARCHAR NOT NULL,
    86      rule_fqdn      VARCHAR NOT NULL,
    87      error_key      VARCHAR NOT NULL,
    88      template_data  VARCHAR NOT NULL,
    89      PRIMARY KEY(cluster_id, org_id, rule_fqdn, error_key)
    90  )
    91  ```
    92  
    93  ## Table `cluster_rule_user_feedback`
    94  
    95  ```sql
    96  -- user_vote is user's vote,
    97  -- 0 is none,
    98  -- 1 is like,
    99  -- -1 is dislike
   100  CREATE TABLE cluster_rule_user_feedback (
   101      cluster_id  VARCHAR NOT NULL,
   102      rule_id     VARCHAR NOT NULL,
   103      error_key   VARCHAR NOT NULL,
   104      user_id     VARCHAR NOT NULL,
   105      message     VARCHAR NOT NULL,
   106      user_vote   SMALLINT NOT NULL,
   107      added_at    TIMESTAMP NOT NULL,
   108      updated_at  TIMESTAMP NOT NULL,
   109  
   110      PRIMARY KEY(cluster_id, rule_id, user_id, error_key),
   111      CONSTRAINT cluster_rule_user_feedback_cluster_id_fkey
   112      FOREIGN KEY (cluster_id)
   113          REFERENCES report(cluster)
   114          ON DELETE CASCADE,
   115      CONSTRAINT cluster_rule_user_feedback_rule_id_fkey
   116      FOREIGN KEY (rule_id)
   117          REFERENCES rule(module)
   118          ON DELETE CASCADE
   119  )
   120  ```
   121  
   122  ## Table `cluster_rule_toggle`
   123  
   124  ```sql
   125  CREATE TABLE cluster_rule_toggle (
   126      cluster_id  VARCHAR NOT NULL,
   127      rule_id     VARCHAR NOT NULL,
   128      error_key   VARCHAR NOT NULL,
   129      user_id     VARCHAR NOT NULL,
   130      disabled    SMALLINT NOT NULL,
   131      disabled_at TIMESTAMP NULL,
   132      enabled_at  TIMESTAMP NULL,
   133      updated_at  TIMESTAMP NOT NULL,
   134  
   135      disabled_check SMALLINT CHECK (disabled >= 0 AND disabled <= 1),
   136  
   137      PRIMARY KEY(cluster_id, rule_id, user_id)
   138  )
   139  ```
   140  
   141  ## Table `cluster_user_rule_disable_feedback`
   142  
   143  Feedback provided by user while disabling the rule on UI.
   144  
   145  ```sql
   146  CREATE TABLE cluster_user_rule_disable_feedback (
   147      cluster_id  VARCHAR NOT NULL,
   148      user_id     VARCHAR NOT NULL,
   149      rule_id     VARCHAR NOT NULL,
   150      error_key   VARCHAR NOT NULL,
   151      message     VARCHAR NOT NULL,
   152      added_at    TIMESTAMP NOT NULL,
   153      updated_at  TIMESTAMP NOT NULL,
   154  
   155      PRIMARY KEY(cluster_id, user_id, rule_id, error_key)
   156  )
   157  ```
   158  
   159  ## Table `recommendation`
   160  
   161  All recommendations per organization and cluster.
   162  
   163  ```sql
   164  CREATE TABLE recommendations (
   165      org_id      INTEGER NOT NULL,
   166      cluster_id  VARCHAR NOT NULL,
   167      rule_fqdn   VARCHAR NOT NULL,
   168      error_key   VARCHAR NOT NULL,
   169      rule_id     VARCHAR NOT NULL,
   170      created_at  TIMESTAMP WITHOUT TIME ZONE,
   171  
   172      PRIMARY KEY(org_id, cluster_id, rule_fqdn, error_key)
   173  )
   174  ```
   175  
   176  ## Table `advisor_ratings`
   177  
   178  Cluster independent ratings of a recommendation, per user
   179  
   180  ```sql
   181  CREATE TABLE advisor_ratings (
   182      user_id VARCHAR NOT NULL,
   183      org_id VARCHAR NOT NULL,
   184      rule_fqdn VARCHAR NOT NULL,
   185      error_key VARCHAR NOT NULL,
   186      rated_at TIMESTAMP,
   187      last_updated_at TIMESTAMP,
   188      rating SMALLINT,
   189      rule_id VARCHAR NOT NULL,
   190      PRIMARY KEY(user_id, org_id, rule_fqdn, error_key)
   191  )
   192  ```
   193  
   194  ## Table `consumer_error`
   195  
   196  Errors that happen while processing a message consumed from Kafka are logged into this table. This
   197  allows easier debugging of various issues, especially those related to unexpected input data format.
   198  
   199  ```sql
   200  CREATE TABLE consumer_error (
   201      topic           VARCHAR NOT NULL,
   202      partition       INTEGER NOT NULL,
   203      topic_offset    INTEGER NOT NULL,
   204      key             VARCHAR,
   205      produced_at     TIMESTAMP NOT NULL,
   206      consumed_at     TIMESTAMP NOT NULL,
   207      message         VARCHAR,
   208      error           VARCHAR NOT NULL,
   209  
   210      PRIMARY KEY(topic, partition, topic_offset)
   211  )
   212  ```
   213  
   214  ## Table `migration_info`
   215  
   216  This table contains just one record with DB version value.
   217  
   218  ```sql
   219  CREATE TABLE migration_info (
   220      version         VARCHAR NOT NULL
   221  )
   222  ```
   223  
   224  
   225  
   226  ## Schema description
   227  
   228  DB schema description can be generated by `generate_db_schema_doc.sh` script.
   229  Output is written into directory `docs/db-description/`. Its content can be
   230  viewed [at this
   231  address](https://redhatinsights.github.io/insights-results-aggregator/db-description/).