drop table if exists member_attachments;
create table member_attachments(
	member_attachment_id serial,
	member_id integer not null references members( member_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 member_attachments_member_attachment_id_pkey primary key( member_attachment_id )
);

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

comment on constraint member_attachments_member_attachment_id_pkey on member_attachments is 'unique constraint of table';
comment on constraint member_attachments_member_id_fkey on member_attachments is 'foreign constraint to members table';

create index member_attachments_member_id_ind on member_attachments( member_id );
comment on index member_attachments_member_id_ind is 'index of member_id';
