usergraphtheory's picture
Sync from erdostack/bench at a7805c45d77258d316383c92bdc9f472498d255f (part 58)
1e5b853 verified
Raw History Blame Contribute Delete
878 Bytes
CREATE TABLE person (
id INTEGER PRIMARY KEY,
first_name TEXT NOT NULL,
last_name TEXT NOT NULL,
creation_date INTEGER NOT NULL
);
CREATE TABLE person_knows_person (
person1_id INTEGER NOT NULL REFERENCES person(id),
person2_id INTEGER NOT NULL REFERENCES person(id),
creation_date INTEGER NOT NULL,
PRIMARY KEY (person1_id, person2_id),
CHECK (person1_id < person2_id)
);
CREATE TABLE message (
id INTEGER PRIMARY KEY,
kind TEXT NOT NULL CHECK (kind IN ('post', 'comment')),
creator_id INTEGER NOT NULL REFERENCES person(id),
reply_of_id INTEGER REFERENCES message(id),
content TEXT,
creation_date INTEGER NOT NULL,
CHECK ((kind = 'post') = (reply_of_id IS NULL))
);
CREATE INDEX message_creator ON message(creator_id, creation_date);
CREATE INDEX message_reply_of ON message(reply_of_id);