CREATE TABLE IF NOT EXISTS files (
	id TEXT PRIMARY KEY,
	filename TEXT NOT NULL,
	original TEXT NOT NULL,
	archive TEXT,
	paths TEXT,
	hash TEXT NOT NULL,
	size INTEGER NOT NULL,
	created INTEGER NOT NULL
);

CREATE TABLE IF NOT EXISTS access (
	id TEXT PRIMARY KEY,
	slug TEXT UNIQUE NOT NULL,
	file TEXT NOT NULL,
	user TEXT,
	created INTEGER NOT NULL,
	expires INTEGER NOT NULL,
	paid INTEGER DEFAULT 0,
	url TEXT UNIQUE NOT NULL,
	service TEXT,
	downloads INTEGER DEFAULT 0,
	FOREIGN KEY(file) REFERENCES files(id),
	FOREIGN KEY(user) REFERENCES users(id)
);

CREATE TABLE IF NOT EXISTS metadata (
	id TEXT PRIMARY KEY,
	file TEXT REFERENCES files(id),
	type TEXT,
	width INTEGER,
	height INTEGER,
	length REAL,
	format TEXT,
	preview TEXT
);

CREATE TABLE IF NOT EXISTS users (
	id TEXT PRIMARY KEY,
	email TEXT UNIQUE,
	name TEXT,
	created INTEGER
);