CREATE TABLE IF NOT EXISTS users (
	user_id SERIAL PRIMARY KEY,
	type text,
	op_id text,
	name text,
	email text,
	lfm_name text UNIQUE,
	lfm_password text,
	created timestamptz DEFAULT current_timestamp
);

CREATE TABLE IF NOT EXISTS scrobbling_sessions (
    session_key text PRIMARY KEY,
	lfm_name text REFERENCES users(lfm_name),
    client text,
	client_version text,
    protocol text,
	created timestamptz DEFAULT current_timestamp
);
CREATE TABLE IF NOT EXISTS scrobbles (
	artist text,
	albumartist text,
	trackname text,
	album text,
	tracknumber int,
	duration int,
	time timestamptz,
	chosen bool,
	mbid text,
	mbid_computed text,
	session_key text REFERENCES scrobbling_sessions,
	lfm_name text REFERENCES users(lfm_name)
);

CREATE TABLE IF NOT EXISTS user_sessions (
	id text PRIMARY KEY,
	user_id integer REFERENCES users,
	created timestamptz DEFAULT current_timestamp
);

CREATE TABLE IF NOT EXISTS songs (
	mbid text PRIMARY KEY,
	image text
);
