PRAGMA foreign_keys = ON;

drop table if exists login;
drop table if exists user;
drop table if exists userstatus;

create table userstatus(
	status char(1) primary key not null,
	description varchar(32) not null
);

insert into userstatus values( 'U', 'User unknown' );
insert into userstatus values( 'R', 'Currently in registration' );
insert into userstatus values( 'A', 'Registration ok, user active' );
insert into userstatus values( 'D', 'User disabled' );

create table user(
	id integer primary key autoincrement not null,
	username varchar(32) unique not null,
	password varchar(32) not null,
	email varchar(32),
	status char(1) references userstatus(status) default 'U',
	registration_start timestamp,
	code varchar(32)
);

insert into user(username, password, status) values('admin','admin', 'A');

create table login(
	id integer primary key autoincrement not null,
	user_id integer references user(id),
	last_login timestamp
);
