CREATE TABLE rex (
	rex_id INTEGER PRIMARY KEY AUTO_INCREMENT,
	ppl_id INTEGER,
	subj_id INTEGER,
	period_id INTEGER,
	info VARCHAR(256),
	timestamp INTEGER,
	UNIQUE ( ppl_id, subj_id, period_id )
);
CREATE INDEX rex0 ON rex ( ppl_id, period_id );
CREATE INDEX rex1 ON rex ( subj_id, period_id );
CREATE INDEX rex2 ON rex ( period_id );

CREATE TABLE paper (
	paper_id INTEGER PRIMARY KEY AUTO_INCREMENT,
	paper_name VARCHAR(64),
	paper_format VARCHAR(16),
	paper_num_x INTEGER,
	paper_num_y INTEGER,
	paper_origin_x INTEGER,
	paper_origin_y INTEGER,
	paper_step_x INTEGER,
	paper_step_y INTEGER,
	paper_window_x INTEGER,
	paper_window_y INTEGER
);

CREATE TABLE periods (
	period_id INTEGER PRIMARY KEY AUTO_INCREMENT,
	period_desc VARCHAR(128),
	period_deadline INTEGER,
	period_maxrexs INTEGER,
	year_id INTEGER
);

CREATE TABLE period2grp (
	period_id INTEGER NOT NULL,
	grp_id INTEGER NOT NULL,
	UNIQUE (period_id, grp_id)
);
CREATE INDEX period2grp0 ON period2grp ( period_id );
CREATE INDEX period2grp1 ON period2grp ( grp_id );

CREATE TABLE config (
	config_key VARCHAR(32) PRIMARY KEY,
	config_value VARCHAR(64)
);
