
create table player (
	playerId INTEGER PRIMARY KEY,
	playername TEXT UNIQUE NOT NULL
);

create table image (
	imageId INTEGER PRIMARY KEY,
	imagename TEXT NOT NULL,
	position INTEGER NOT NULL,
	edgedata BLOB NOT NULL,
	originaldata BLOB
);

create table drawing (
	drawingId INTEGER PRIMARY KEY AUTOINCREMENT,
	imageId INTEGER NOT NULL,
	drawingdata BLOB NOT NULL,
	FOREIGN KEY(imageId) REFERENCES image(imageId)
);

create table path (
	pathId INTEGER AUTOINCREMNT PRIMARY KEY,
	imageId INTEGER NOT NULL,
	pathdata BLOB NOT NULL,
	portrait BOOLEAN NOT NULL,
	FOREIGN KEY(imageId) REFERENCES image(imageId)
);

create table scoreimage (
	scoreimageId INTEGER PRIMARY KEY AUTOINCREMENT,
	drawingId INTEGER NOT NULL,
	score DECIMAL(5, 2) NOT NULL,
	scoreimagedata BLOB NOT NULL,
	FOREIGN KEY(drawingId) REFERENCES drawing(drawingId)
);

create table session (
	sessionId INTEGER PRIMARY KEY AUTOINCREMENT,
	trackId INTEGER,
	playerId INTEGER NOT NULL,
	recentScreenOrientation INTEGER,
	FOREIGN KEY(playerId) REFERENCES player(playerId)
)

drop table session;
drop table drawing;
drop table scoreimage;
drop table image;
drop table player;
drop table path