drop table if exists mail_templates;
create table mail_templates(
	mail_template_id serial not null,
	site_language_id integer references site_languages( site_language_id ),
	mail_template_type_id integer references mail_template_types( mail_template_type_id ),
	ctstamp timestamp without time zone not null default now(),
	template_name varchar(255) not null,
	template_title varchar(255) not null,
	template_subject varchar(255) not null,
	template_is_html boolean not null default true,
	template_is_raw_html boolean not null default false,
	template_head text,
	template_content text,
	constraint mail_templates_pkey primary key( mail_template_id )
);

comment on table mail_templates is 'storage of mail templates';
comment on column mail_templates.mail_template_id is 'unique id of table';
comment on column mail_templates.site_language_id is 'reference id to site_languages table';
comment on column mail_templates.mail_template_type_id is 'reference to mail_template_types table';
comment on column mail_templates.ctstamp is 'creation timestamp of mail template';
comment on column mail_templates.template_name is 'name of the mail template';
comment on column mail_templates.template_title is 'title of the mail template';
comment on column mail_templates.template_subject is 'subjecf ot the title (smarty string)';
comment on column mail_templates.template_is_html is 'html flag of the template';
comment on column mail_templates.template_is_raw_html is 'raw html flag of the template - prerequisites: is_html = true';
comment on column mail_templates.template_head is 'extra head of the template (if the template is html)';
comment on column mail_templates.template_content is 'content of the template (if the template is html)';

comment on constraint mail_templates_pkey on mail_templates is 'unique constraint of the mail_templates table';
comment on constraint mail_templates_mail_template_type_id_fkey on mail_templates is 'foreign constraint to mail_template_types table';
comment on constraint mail_templates_site_language_id_fkey on mail_templates is 'foreign constraint to site_languages table';

