drop table if exists tasks;
create table tasks(
	task_id serial not null,
	task_ctstamp timestamp without time zone not null default now(),
	task_name varchar(128),
	task_description text,
	task_type varchar(64),
	task_uid integer,
	task_parameters text,
	task_status varchar(16) not null default 'pending',
	task_state text,
	task_priority integer not null default 0,
	task_ptstamp timestamp without time zone not null default now(),
	task_mtstamp timestamp without time zone,
	task_etstamp timestamp without time zone,
	task_error text,
	constraint tasks_task_id_pkey primary key( task_id )
);

comment on table tasks is 'storage of system tasks';
comment on column tasks.task_id is 'unique id of task';
comment on column tasks.task_ctstamp is 'creation timestamp of task';
comment on column tasks.task_name is 'name of the task';
comment on column tasks.task_description is 'description of the task';
comment on column tasks.task_type is 'type of the task';
comment on column tasks.task_uid is 'unique identifier on task';
comment on column tasks.task_parameters is 'other parameters of the task';
comment on column tasks.task_status is 'status of the task';
comment on column tasks.task_state is 'other state parameters of the task';
comment on column tasks.task_priority is 'priority of task (lower is the more prior)';
comment on column tasks.task_ptstamp is 'time to do the task';
comment on column tasks.task_mtstamp is 'last modification timestamp of the task';
comment on column tasks.task_etstamp is 'end timestamp of the task';
comment on column tasks.task_error is 'serialized error if exists';

create index tasks_task_status_ind on tasks( task_status );
comment on index tasks_task_status_ind is 'index on task status';

comment on constraint tasks_task_id_pkey on tasks is 'unique constraint of table';
