CREATE TABLE IF NOT EXISTS answers (
	id INT PRIMARY KEY AUTO_INCREMENT,
	question_id INT NOT NULL,
	creation_date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
	content TEXT NOT NULL,
	cw VARCHAR(255) NOT NULL DEFAULT ''
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS questions (
	id INT PRIMARY KEY AUTO_INCREMENT,
	from_who VARCHAR(255) NOT NULL,
	creation_date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
	content TEXT NOT NULL,
	answered BOOLEAN NOT NULL DEFAULT FALSE,
	answer_id INT,
	pinned BOOLEAN NOT NULL DEFAULT FALSE,
	cw VARCHAR(255) NOT NULL DEFAULT '',
	unread BOOLEAN NOT NULL DEFAULT TRUE
	-- below is reserved for version 1.7.0 or later
	-- private BOOLEAN NOT NULL DEFAULT FALSE,
	-- user_ip VARBINARY(16) NOT NULL DEFAULT ''
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

ALTER TABLE questions
ADD CONSTRAINT fk_answer_id FOREIGN KEY (answer_id) REFERENCES answers(id) ON DELETE CASCADE;

ALTER TABLE answers
ADD CONSTRAINT fk_question_id FOREIGN KEY (question_id) REFERENCES questions(id) ON DELETE CASCADE;
