DROP TABLE IF EXISTS user;
DROP TABLE IF EXISTS post;

CREATE TABLE users (
	id INTEGER PRIMARY KEY AUTOINCREMENT,
	username TEXT UNIQUE NOT NULL,
	password TEXT UNIQUE NOT NULL
);

CREATE TABLE posts (
	id INTEGER PRIMARY KEY AUTOINCREMENT,
	author_id INTEGER NOT NULL,
	created TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
	title TEXT NOT NULL,
	body TEXT NOT NULL,
	FOREIGN KEY (author_id) REFERENCES users (id)
);

CREATE TABLE comments (
	id INTEGER PRIMARY KEY AUTOINCREMENT,
	post_id INTEGER NOT NULL,
	author_id INTEGER NOT NULL,
	created TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
	body TEXT NOT NULL,
	FOREIGN KEY (post_id) REFERENCES posts (id)
	FOREIGN KEY (author_id) REFERENCES users (id)
)
