helpers/database_postgresql8_tmpl.sql
author chris <chris@marvin>
Wed, 01 Jul 2009 10:48:22 +0200
changeset 2 1090e2141798
parent 1 6fceb66e1ad7
child 3 2fdc9cc89502
permissions -rw-r--r--
sonews/0.5.1 fixes merged
     1 /*
     2   Create a database at first:
     3     CREATE DATABASE sonews ENCODING 'UTF8';
     4 */
     5 
     6 /* 
     7   flags:
     8   If bit 0 is set, groups is a mirrorred mailing list. 
     9   If not set default newsgroup.
    10 
    11   Normalization: 1NF, 2NF, 3NF
    12 */
    13 CREATE TABLE groups 
    14 (
    15   group_id      SERIAL,
    16   name          VARCHAR(80) NOT NULL,
    17   flags         SMALLINT DEFAULT 0,
    18 
    19   PRIMARY KEY(group_id),
    20   UNIQUE(name)
    21 );
    22 
    23 CREATE TABLE articles 
    24 (
    25   article_id    INT,
    26   body          BYTEA,
    27 
    28   PRIMARY KEY(article_id)
    29 );
    30 
    31 CREATE TABLE article_ids
    32 (
    33   article_id  INT REFERENCES articles(article_id) ON DELETE CASCADE,
    34   message_id  VARCHAR(255),
    35 
    36   PRIMARY KEY(article_id),
    37   UNIQUE(message_id)
    38 );
    39 
    40 CREATE TABLE headers
    41 (
    42   article_id    INT REFERENCES articles(article_id) ON DELETE CASCADE,
    43   header_key    VARCHAR(255),
    44   header_value  TEXT,
    45   header_index  INT,
    46 
    47   PRIMARY KEY(article_id, header_key, header_index)
    48 );
    49 
    50 /*
    51   Normalization: 1NF, 2NF
    52 */
    53 CREATE TABLE postings 
    54 (
    55   group_id      INTEGER,
    56   article_id    INTEGER REFERENCES articles (article_id) ON DELETE CASCADE,
    57   article_index INTEGER NOT NULL, 
    58 
    59   PRIMARY KEY(group_id, article_id)
    60 );
    61 
    62 /* 
    63   Table for association of newsgroups and mailing-lists 
    64 
    65   Normalization: 1NF, 2NF, 3NF
    66 */
    67 CREATE TABLE groups2list
    68 (
    69   group_id   INTEGER REFERENCES groups(group_id) ON DELETE CASCADE,
    70   listaddress VARCHAR(255),
    71 
    72   PRIMARY KEY(group_id, listaddress),
    73   UNIQUE(listaddress)
    74 );
    75 
    76 /* 
    77   Configuration table, containing key/value pairs 
    78 
    79   Normalization: 1NF, 2NF, 3NF
    80 */
    81 CREATE TABLE config
    82 (
    83   config_key     VARCHAR(255),
    84   config_value   TEXT,
    85 
    86   PRIMARY KEY(config_key)
    87 );
    88 
    89 /* 
    90   Newsserver peers 
    91 
    92   Normalization: 1NF (atomic values), 2NF
    93 */
    94 CREATE TABLE peers
    95 (
    96   peer_id     SERIAL,
    97   host        VARCHAR(255),
    98   port        SMALLINT,
    99 
   100   PRIMARY KEY(peer_id),
   101   UNIQUE(host, port)
   102 );
   103 
   104 /* 
   105   List of newsgroups to feed into sonews 
   106 
   107   Normalization: 1NF, 2NF, 3NF
   108 */
   109 CREATE TABLE peer_subscriptions
   110 (
   111   peer_id    INTEGER REFERENCES peers (peer_id) ON DELETE CASCADE, 
   112   group_id   INTEGER REFERENCES groups (group_id) ON DELETE CASCADE,
   113   feedtype   SMALLINT DEFAULT 0, /* 0: pullfeed; 1: pushfeed */
   114 
   115   PRIMARY KEY(peer_id, group_id, feedtype)
   116 );
   117 
   118 /* 
   119    Tables for server event statistics
   120 
   121    Possible statistic keys:
   122    1=CONNECTIONS     (active connections)
   123    2=POSTED_NEWS     (directly to the server posted unique messages)
   124    3=GATEWAYED_NEWS  (posted unique message gateways through the ML-gateway)
   125    4=FEEDED_NEWS     (unique messages feed via NNTP)
   126 
   127    The server will create snapshots of the above data.
   128 
   129    Normalization: 1NF, 2NF
   130 */
   131 CREATE TABLE events
   132 (
   133   event_time         BIGINT,   /* time of this snapshot */
   134   event_key          SMALLINT,  /* which data */
   135   group_id           INT REFERENCES groups(group_id) ON DELETE CASCADE,
   136 
   137   PRIMARY KEY(event_time, event_key)
   138 );