create table user (
	id integer primary key asc,
	name text,
	created timestamp default current_timestamp
);

create table key (
	user integer,
	pubkey text,
	created timestamp default current_timestamp,
	active boolean,
	foreign key(user) references user(id)
);

create table thread (
	id integer primary key asc,
	name text,
	creator integer,
	created timestamp default current_timestamp,
	foreign key(creator) references user(id)
);

create table permission (
	thread integer,
	user integer,
	type text,
	mutable boolean,
	permission text,
	value text,
	foreign key(user) references user(id),
	foreign key(thread) references thread(id)
);

create table member (
	thread integer,
	user integer,
	created timestamp default current_timestamp,
	foreign key(user) references user(id),
	foreign key(thread) references thread(id)
);

create table post (
	id integer primary key asc,
	user integer,
	thread integer,
	content text,
	encrypted bool,
	created timestamp default current_timestamp,
	foreign key(user) references user(id),
	foreign key(thread) references thread(id)
);

create table span (
	id integer primary key asc,
	thread integer,
	deleted bool default false,
	content text,
	x decimal,
	y decimal,
	scale decimal,
	foreign key(thread) references thread(id)
);

insert into thread (name) values ("meow");
insert into permission 
	(thread, type, permission, value) values
	(1, "everyone", "view", "true");
insert into permission 
	(thread, type, permission, value) values
	(1, "everyone", "post", "true");
