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,
	user_id int REFERENCES users,
    client text,
	client_version text,
    protocol text,
	created timestamptz DEFAULT current_timestamp
);

CREATE TABLE IF NOT EXISTS songs (
	song_id SERIAL PRIMARY KEY,
	artist text,
	album text,
	name text,
	track_number text,
	duration text,
	mbid text,
	image text
);

CREATE TABLE IF NOT EXISTS scrobbles (
	artist text,
	album_artist text,
	track_name text,
	album text,
	track_number int,
	duration int,
	time timestamptz,
	chosen bool,
	mbid text,
	song_id int REFERENCES songs,
	session_key text REFERENCES scrobbling_sessions,
	user_id int REFERENCES users
);

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