CREATE TABLE IF NOT EXISTS users (
	id			INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE,
	userident	VARCHAR(90) NOT NULL
);

CREATE TABLE IF NOT EXISTS userdata (
	user_id	INTEGER KEY NOT NULL UNIQUE,
	data	TEXT DEFAULT NULL
);

CREATE TABLE IF NOT EXISTS settings (
	user_id	INTEGER KEY NOT NULL,
	ident	VARCHAR(90) NOT NULL,
	created	DATE NOT NULL DEFAULT (datetime('now','localtime')),
	value	TEXT DEFAULT NULL
);

CREATE UNIQUE INDEX IF NOT EXISTS idx_settings_user_ident ON settings(user_id, ident);

CREATE TABLE IF NOT EXISTS datastrore (
	user_id	INTEGER KEY NOT NULL,
	ident	VARCHAR(90) NOT NULL,
	ds_id	INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE,
	created	DATE NOT NULL DEFAULT (datetime('now','localtime')),
	data	TEXT DEFAULT NULL
);

CREATE INDEX IF NOT EXISTS idx_datastrore_user_ident ON datastrore(user_id, ident);
CREATE UNIQUE INDEX IF NOT EXISTS idx_datastrore_user_ident_dsid ON datastrore(user_id, ident, ds_id);
