drop table if exists forum_topics cascade;
create table forum_topics(
	forum_topic_id serial not null,
	forum_topic_parentid integer references forum_topics( forum_topic_id ),
	owner_user_id integer references users( user_id ),
	forum_topic_level integer default 1,
	forum_topic_ordering integer,
	is_topic_post_thread boolean default true,
	ctstamp timestamp without time zone,
	mtstamp timestamp without time zone,
	forum_topic_title varchar(255),
	forum_topic_aliasname varchar(255),
	is_public boolean default false,
	is_active boolean default false,
	is_deleted boolean default false,
	is_admin_acknowledged boolean default true,
	forum_topic_meta_l integer,
	forum_topic_meta_r integer,
	cache_last_poster_name varchar(255),
	cache_number_of_posts integer default 0,
	oldid integer,
	constraint forum_topics_pkey primary key( forum_topic_id )
);

comment on table forum_topics is 'storage of forum topics';
comment on column forum_topics.forum_topic_id is 'unique id of table';
comment on column forum_topics.forum_topic_parentid is 'parental id of topic (if no parent then NULL)';
comment on column forum_topics.owner_user_id is 'owner id of the topic';
comment on column forum_topics.forum_topic_level is 'cache field of level (1 if parentid is NULL)';
comment on column forum_topics.forum_topic_ordering is 'ordering on the level';
comment on column forum_topics.is_topic_post_thread is 'is topic post thread flag (true = posts , false = subtopics )';
comment on column forum_topics.ctstamp is 'creation timestamp of the topic';
comment on column forum_topics.mtstamp is 'last modification timestamp of the topic';
comment on column forum_topics.forum_topic_title is 'title of the topic';
comment on column forum_topics.forum_topic_aliasname is 'aliasname of the topic (google seo-frendly)';
comment on column forum_topics.is_public is 'is forum publically accessible (not only for subscribers';
comment on column forum_topics.is_active is 'is the topic active flag';
comment on column forum_topics.is_deleted is 'is the topic deleted flag';
comment on column forum_topics.is_admin_acknowledged is 'is the admin acknowledged the topic (if user_created)';
comment on column forum_topics.forum_topic_meta_l is 'nested tree metadata - left';
comment on column forum_topics.forum_topic_meta_r is 'nested tree metadata - right';
comment on column forum_topics.cache_last_poster_name is 'cache field of the last poster';
comment on column forum_topics.cache_number_of_posts is 'number of posts in thread';
comment on column forum_topics.oldid is 'migrational data';

comment on constraint forum_topics_pkey on forum_topics is 'unique constraint of table';
comment on constraint forum_topics_forum_topic_parentid_fkey on forum_topics is 'parental constraint';
comment on constraint forum_topics_owner_user_id_fkey on forum_topics is 'foreign constraint to users table';
