BEGIN TRANSACTION;

PRAGMA foreign_keys = ON;

DROP TABLE IF EXISTS config;
CREATE TABLE config (
	name TEXT UNIQUE,
	value ANY
);

DROP TABLE IF EXISTS users;
CREATE TABLE users (
	user_id INTEGER PRIMARY KEY,
	username TEXT UNIQUE COLLATE NOCASE,
	password_hash TEXT,
	timezone TEXT DEFAULT 'America/Los_Angeles'
);

DROP TABLE IF EXISTS posts;
CREATE TABLE posts (
	body TEXT,
	created INTEGER,
	author_id INTEGER NOT NULL,
	FOREIGN KEY (author_id) REFERENCES users (user_id)
);

INSERT INTO config (name, value) VALUES ('schema_version', '20230107');

COMMIT;
