drop table if exists user_templates cascade;
create table user_templates(
	user_template_id serial,
	owner_user_id integer not null references users( user_id ),
	user_template_title varchar(128),
	ctstamp timestamp without time zone not null default now(),
	mtstamp timestamp without time zone not null default now(),
	constraint user_templates_user_template_id_pkey primary key( user_template_id ) );

comment on table user_templates is 'storage of user templates';
comment on column user_templates.user_template_id is 'unique id of table';
comment on column user_templates.owner_user_id is 'owner user of the template';
comment on column user_templates.user_template_title is 'title of the template';
comment on column user_templates.ctstamp is 'creation timestamp of user template';
comment on column user_templates.mtstamp is 'last modification of user template';

drop table if exists user_template_users;
create table user_template_users( 
	user_template_id integer not null references user_templates( user_template_id ),
	user_id integer not null references users( user_id )
);
