CREATE TABLE stories (
    sid char(16) NOT NULL,
    tid smallint UNSIGNED NOT NULL,
    uid mediumint UNSIGNED NOT NULL,
    title varchar(100) DEFAULT '' NOT NULL,
    dept varchar(100),
    time datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
    hits mediumint UNSIGNED DEFAULT '0' NOT NULL,
    section varchar(30) DEFAULT '' NOT NULL,
    displaystatus tinyint DEFAULT '0' NOT NULL,
    commentstatus tinyint,
    discussion mediumint UNSIGNED,
    submitter mediumint UNSIGNED NOT NULL,
    commentcount smallint UNSIGNED DEFAULT '0' NOT NULL,
    hitparade varchar(64) DEFAULT '0,0,0,0,0,0,0' NOT NULL,
    writestatus ENUM("ok","delete","dirty","archived") DEFAULT 'ok' NOT NULL,
    PRIMARY KEY (sid),
    FOREIGN KEY (uid) REFERENCES users(uid),
    FOREIGN KEY (tid) REFERENCES tid(topic),
    FOREIGN KEY (section) REFERENCES sections(section),
    INDEX frontpage (time, displaystatus, writestatus),
    INDEX time (time),
    INDEX submitter (submitter)
) TYPE = myisam;

CREATE TABLE story_text (
    sid char(16) NOT NULL,
    introtext text,
    bodytext text,
    relatedtext text,
    FOREIGN KEY (sid) REFERENCES stories(sid),
    PRIMARY KEY (sid)
) TYPE = myisam;

CREATE TABLE story_param (
    param_id mediumint UNSIGNED NOT NULL auto_increment,
    sid char(16) NOT NULL,
    name varchar(32) DEFAULT '' NOT NULL,
    value text DEFAULT '' NOT NULL,
    UNIQUE story_key (sid,name),
    PRIMARY KEY (param_id)
) TYPE = myisam;