create table settings( id integer, import_path varchar, last_import_date float, constraint pk_settings_id primary key(id) );

create table files( id integer, name varchar(128), size_MB integer, type varchar(20), path_prefix varchar(256), hash varchar(34), thumbnail varchar,
    constraint pk_photos_id primary key(id) );

create table person ( id integer, tag varchar(48), firstname varchar(48), surname varchar(48),
    constraint pk_person_id primary key(id) );

create table refimg ( id integer, fname varchar(256), constraint pk_refimg_id primary key(id) );

create table file_person_link ( file_id integer, person_id integer,
    constraint pk_fpl PRIMARY KEY(file_id, person_id), 
    constraint fk_fpl_file_id FOREIGN KEY (file_id) REFERENCES files(id), 
    constraint fk_fpl_person_id FOREIGN KEY (person_id) REFERENCES person(id) );

create table person_refimg_link ( person_id integer, refimg_id integer,
    constraint pk_prl PRIMARY KEY(person_id, refimg_id), 
    constraint fk_prl_person_id FOREIGN KEY (person_id) REFERENCES person(id), 
    constraint fk_prl_refimg_id FOREIGN KEY (refimg_id) REFERENCES refimg(id), 
    constraint u_prl_refimg_id unique(refimg_id) );

create table job ( 
    id integer, start_time timestamptz, last_update timestamptz, state varchar(128), 
    num_passes integer, current_pass integer, num_files integer, current_file_num integer, current_file integer, 
    constraint pk_job_id primary key(id) );

create table joblog ( id integer, job_id integer, log_date timestamptz, log varchar, 
    constraint pk_jl_id primary key(id), constraint fk_jl_job_id foreign key(job_id) references job(id) );

create sequence files_id_seq;
create sequence ill_id_seq;
create sequence importlog_id_seq;
create sequence person_id_seq;
create sequence refimg_id_seq;
create sequence settings_id_seq;
