drop table if exists newsletter_newsletters cascade;
create table newsletter_newsletters(
	newsletter_newsletter_id serial,
	newsletter_group_id integer not null references newsletter_groups( newsletter_group_id ),
	nl_title varchar(255),
	nl_subject varchar(255),
	nl_head text,
	nl_body text,
	nl_is_html boolean default false,
	nl_is_activated boolean default false,
	nl_is_sent boolean default false,
	nl_senttstamp timestamp without time zone,
	activate_task_id integer references tasks( task_id ),
	send_task_id integer references tasks( task_id ),
	constraint newsletter_newsletters_newsletter_newsletter_id_pkey primary key( newsletter_newsletter_id )
);

comment on table newsletter_newsletters is 'storage of newsletters';
comment on column newsletter_newsletters.newsletter_newsletter_id is 'unique id of table';
comment on column newsletter_newsletters.newsletter_group_id is 'reference to newsletter groups table';
comment on column newsletter_newsletters.nl_title is 'title of newsletter';
comment on column newsletter_newsletters.nl_subject is 'subject of newsletter';
comment on column newsletter_newsletters.nl_head is '(optional) extra head of html newsletter';
comment on column newsletter_newsletters.nl_body is 'body of the newsletter';
comment on column newsletter_newsletters.nl_is_html is 'is_html flag of newsletter';
comment on column newsletter_newsletters.nl_is_activated is 'is_activated flag of newsletter';
comment on column newsletter_newsletters.nl_is_sent is 'is_sent flag of newsletter';
comment on column newsletter_newsletters.nl_senttstamp is 'sent timestamp of newsletter';
comment on column newsletter_newsletters.activate_task_id is 'activation task id of newsletter';
comment on column newsletter_newsletters.send_task_id is 'sending task id of newsletter';
