drop table if exists job_attachments;
create table job_attachments(
	job_attachment_id serial,
	job_id integer not null references jobs( job_id ),
	attachment_title varchar(255) not null,
	attachment_type varchar(64) not null,
	attachment_mimetype varchar(128) not null,
	attachment_original_filename varchar(255),
	attachment_path varchar(255) not null,
	attachment_filename varchar(255) not null,
	attachment_filesize integer not null,
	constraint job_attachments_job_attachment_id_pkey primary key( job_attachment_id )
);

comment on table job_attachments is 'storage of file attachments of a job';
comment on column job_attachments.job_attachment_id is 'unique id of table';
comment on column job_attachments.job_id is 'reference id to jobs table';
comment on column job_attachments.attachment_title is 'title of the attachment (e.g. translation preview)';
comment on column job_attachments.attachment_type is 'type of attachment (e.g. translation preview)';
comment on column job_attachments.attachment_mimetype is 'mimetype of attachment (e.g. application/octet-stream)';
comment on column job_attachments.attachment_original_filename is 'original filename from client';
comment on column job_attachments.attachment_path is 'attachment path (directory only) relative to webroot';
comment on column job_attachments.attachment_filename is 'filename of the attachment (for download as well)';
comment on column job_attachments.attachment_filesize is 'size of the attached file';

comment on constraint job_attachments_job_attachment_id_pkey on job_attachments is 'unique constraint of table';
comment on constraint job_attachments_job_id_fkey on job_attachments is 'foreign constraint to jobs table';

create index job_attachments_job_id_ind on job_attachments( job_id );
comment on index job_attachments_job_id_ind is 'index of job_id';
