DROP TABLE config;
CREATE TABLE config (
  salt VARCHAR(255)
);

INSERT INTO config VALUES (
  "NeVeRcHaN"    -- salt for tripcode, keep secret.
);

DROP TABLE discussions;
CREATE TABLE discussions (
  id        INTEGER NOT NULL PRIMARY KEY,
  post_id   INTEGER,
  title     VARCHAR(255),
  last_age  DATETIME,
  channel   VARCHAR(255),

  FOREIGN KEY (post_id) REFERENCES posts(id)
--FOREIGN KEY (channel) REFERENCES channels(name)
);

CREATE INDEX discussion_by_post_id ON discussions (post_id);


DROP TABLE posts;
CREATE TABLE posts (
  id        INTEGER NOT NULL PRIMARY KEY,
  content   TEXT,
  author    VARCHAR(64),
  tripcode  CHAR(6),
  created   DATETIME,
  parent    INTEGER,
  discussion_id INTEGER,
  ipaddress CHAR(16) NOT NULL,
  sage      BOOL DEFAULT FALSE,

  FOREIGN KEY (parent) REFERENCES posts(id),
  FOREIGN KEY (discussion_id) REFERENCES discussions(id)
);

CREATE INDEX post_by_disussion_id ON posts (discussion_id);


