Datasets:
File size: 878 Bytes
1e5b853 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | 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);
|