drop table if exists jobs cascade;
create table jobs(
	job_id serial,
	ctstamp timestamp without time zone not null default now(),
	job_version float default 3.0,
	poster_user_id integer,
	poster_name varchar(128),
	poster_email varchar(128),
	poster_phone varchar(128),
	poster_cellular varchar(192),
	poster_show_phone boolean default false,
	job_title varchar(192),
	job_quote_deadline timestamp without time zone,
	job_deadline timestamp without time zone,
	job_description text,
	job_mainaspects text,
	job_qualitypreference varchar(16) default 'normal',
	job_specialty integer references specialties( specialty_id ),
	job_custom_specialty varchar(64),
	job_recipients varchar(16),
	poster_acknowledged boolean default false,
	admin_acknowledged boolean default false,
	is_closed boolean default false,
	closed_at timestamp without time zone,
	is_revoked boolean default false,
	revoked_at timestamp without time zone,
	is_sent boolean default false,
	sent_at timestamp without time zone,
	ipaddress varchar(16),
	useragent text,
	hash char(32),
	send_status char(1),
	source varchar(64),
	activate_task_id integer references tasks( task_id ),
	send_task_id integer references tasks( task_id ),
	tech_mtstamp timestamp without time zone not null default now(),
	oldid integer,
	constraint jobs_job_id_pkey primary key( job_id )
);

comment on table jobs is 'storage of translation jobs';
comment on column jobs.job_id is 'unique id of table';
comment on column jobs.ctstamp is 'creational tstamp';
comment on column jobs.job_version is 'version number of the job';
comment on column jobs.poster_user_id is '(optional) id referencing the users table - (only on oldschool)';
comment on column jobs.poster_name is 'name of the job poster';
comment on column jobs.poster_email is 'email address of the job poster';
comment on column jobs.poster_phone is 'phone of the job poster';
comment on column jobs.poster_cellular is 'cellular of the job poster';
comment on column jobs.poster_show_phone is 'show the phone number on the job';
comment on column jobs.job_title is 'title of the job';
comment on column jobs.job_quote_deadline is 'quote deadline of the job';
comment on column jobs.job_deadline is 'deadline of the job';
comment on column jobs.job_description is 'detailed description of the job';
comment on column jobs.job_mainaspects is 'main aspects of the job (v2)';
comment on column jobs.job_qualitypreference is 'quality preference of the job (normal/high_quality/low_price)';
comment on column jobs.job_specialty is 'specialty of the job (optional)';
comment on column jobs.job_custom_specialty is 'custom specialty of the job (mandatory if job_specialty is null)';
comment on column jobs.job_recipients is 'recipients of the job (freelancers/agencies/all/custom)';
comment on column jobs.poster_acknowledged is 'boolean flag if poster is acknowledged';
comment on column jobs.admin_acknowledged is 'boolean flag if admin is acknowledged';
comment on column jobs.is_closed is 'closed flag';
comment on column jobs.closed_at is 'datetime of closure';
comment on column jobs.is_revoked is 'revoked flag';
comment on column jobs.revoked_at is 'datetime of revokation';
comment on column jobs.is_sent is 'sent flag';
comment on column jobs.sent_at is 'datetime of sending';
comment on column jobs.ipaddress is 'ip address';
comment on column jobs.useragent is 'user agent (browser type)';
comment on column jobs.hash is 'hash of the job';
comment on column jobs.send_status is 'sending status (0/S)';
comment on column jobs.source is 'source of the job (fordit.hu,hungarian-translation.hu)';
comment on column jobs.activate_task_id is 'activation task id of job';
comment on column jobs.send_task_id is 'sending task id of job';
comment on column jobs.tech_mtstamp is 'technical modification timestamp';
comment on column jobs.oldid is 'old id';

comment on constraint jobs_job_id_pkey on jobs is 'unique constraint of table';
comment on constraint jobs_activate_task_id_fkey on jobs is 'foreign constraint to tasks table (on activate task)';
comment on constraint jobs_job_specialty_fkey on jobs is 'foreign constraint to specialties table';
comment on constraint jobs_send_task_id_fkey on jobs is 'foreign constraint to specialties table (on send task)';


create index jobs_job_title_ind on jobs( job_title );
comment on index jobs_job_title_ind is 'index on title field';
create index jobs_ctstamp_ind on jobs( ctstamp );
comment on index jobs_ctstamp_ind is 'index on ctstamp field';
create index jobs_poster_name_ind on jobs( poster_name );
comment on index jobs_poster_name_ind is 'index on poster name';
create index jobs_poster_acknowledged_ind on jobs( poster_acknowledged );
comment on index jobs_poster_acknowledged_ind is 'index on poster_acknowledged';
create index jobs_admin_acknowledged_ind on jobs( admin_acknowledged );
comment on index jobs_admin_acknowledged_ind is 'index on admin_acknowledged';
create index jobs_is_sent_ind on jobs( is_sent );
comment on index jobs_is_sent_ind is 'index on is_sent';
create index jobs_job_deadline_ind on jobs( job_deadline );
comment on index jobs_job_deadline_ind is 'index on job_deadline field';
create index jobs_job_quote_deadline_ind on jobs( job_quote_deadline );
comment on index jobs_job_quote_deadline_ind is 'index on job_quote_deadline field';

