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);