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
) 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
	-- below is reserved for version 1.5.0 or later
	-- private BOOLEAN NOT NULL DEFAULT FALSE
) 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;
