
# This is a fix for InnoDB in MySQL >= 4.1.x
# It "suspends judgement" for fkey relationships until are tables are set.
SET FOREIGN_KEY_CHECKS = 0;

#-----------------------------------------------------------------------------
#-- tag
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `tag`;


CREATE TABLE `tag`
(
	`tid` INTEGER(11)  NOT NULL AUTO_INCREMENT,
	`status` INTEGER(11) default 0 NOT NULL,
	`culture` VARCHAR(7)  NOT NULL,
	`name` VARCHAR(255)  NOT NULL,
	`created_at` DATETIME  NOT NULL,
	`updated_at` DATETIME  NOT NULL,
	PRIMARY KEY (`tid`),
	KEY `t_i_name`(`name`),
	KEY `t_i_name_culture`(`name`, `culture`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- tag_tag
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `tag_tag`;


CREATE TABLE `tag_tag`
(
	`tid` INTEGER(11)  NOT NULL,
	`tid_parent` INTEGER(11)  NOT NULL,
	PRIMARY KEY (`tid`,`tid_parent`),
	KEY `tt_i_tid`(`tid`),
	KEY `tt_i_tid_parent`(`tid_parent`),
	CONSTRAINT `tt_fk_tid`
		FOREIGN KEY (`tid`)
		REFERENCES `tag` (`tid`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- tag_title
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `tag_title`;


CREATE TABLE `tag_title`
(
	`ttid` INTEGER(11)  NOT NULL AUTO_INCREMENT,
	`status` INTEGER(11) default 0 NOT NULL,
	`culture` VARCHAR(7)  NOT NULL,
	`name` VARCHAR(255)  NOT NULL,
	`created_at` DATETIME  NOT NULL,
	`updated_at` DATETIME  NOT NULL,
	PRIMARY KEY (`ttid`),
	KEY `tti_i_name`(`name`),
	KEY `tti_i_name_culture`(`name`, `culture`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- config
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `config`;


CREATE TABLE `config`
(
	`setting` VARCHAR(255)  NOT NULL,
	`value` TEXT,
	PRIMARY KEY (`setting`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- statictext
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `statictext`;


CREATE TABLE `statictext`
(
	`sid` INTEGER(11)  NOT NULL AUTO_INCREMENT,
	`culture` VARCHAR(7)  NOT NULL,
	`title` VARCHAR(255),
	`content` TEXT  NOT NULL,
	`created_at` DATETIME  NOT NULL,
	`updated_at` DATETIME  NOT NULL,
	PRIMARY KEY (`sid`),
	KEY `s_i_culture`(`culture`),
	KEY `s_i_sid_culture`(`sid`, `culture`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- webcontent
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `webcontent`;


CREATE TABLE `webcontent`
(
	`wid` INTEGER(11)  NOT NULL,
	`culture` VARCHAR(7)  NOT NULL,
	`sid` INTEGER(11)  NOT NULL,
	`type` INTEGER(11)  NOT NULL,
	`status` INTEGER(11) default 0 NOT NULL,
	`created_at` DATETIME  NOT NULL,
	`updated_at` DATETIME  NOT NULL,
	PRIMARY KEY (`wid`,`culture`),
	KEY `wc_i_sid`(`sid`),
	CONSTRAINT `wc_fk_sid`
		FOREIGN KEY (`sid`)
		REFERENCES `statictext` (`sid`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- slide
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `slide`;


CREATE TABLE `slide`
(
	`sid` INTEGER(11)  NOT NULL AUTO_INCREMENT,
	`culture` VARCHAR(7)  NOT NULL,
	`title` VARCHAR(255),
	`text` TEXT  NOT NULL,
	`picture_filename` VARCHAR(255),
	`mid` INTEGER(11),
	`weight` INTEGER(11) default 0 NOT NULL,
	`status` INTEGER(11) default 0 NOT NULL,
	`created_at` DATETIME  NOT NULL,
	`updated_at` DATETIME  NOT NULL,
	PRIMARY KEY (`sid`),
	INDEX `FI_fk_mid` (`mid`),
	CONSTRAINT `sl_fk_mid`
		FOREIGN KEY (`mid`)
		REFERENCES `media` (`mid`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- message
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `message`;


CREATE TABLE `message`
(
	`meid` INTEGER(11)  NOT NULL AUTO_INCREMENT,
	`uid` INTEGER(11)  NOT NULL,
	`recipient_uid` INTEGER(11)  NOT NULL,
	`sender_uid` INTEGER(11)  NOT NULL,
	`meaid` INTEGER(11),
	`read` TINYINT(1) default 0 NOT NULL,
	`status` INTEGER(11) default 0 NOT NULL,
	`subject` VARCHAR(255)  NOT NULL,
	`message` TEXT  NOT NULL,
	`created_at` DATETIME  NOT NULL,
	PRIMARY KEY (`meid`),
	KEY `me_uid`(`uid`),
	KEY `me_recipient`(`recipient_uid`),
	KEY `me_sender`(`sender_uid`),
	KEY `me_meaid`(`meaid`),
	CONSTRAINT `me_fk_uid`
		FOREIGN KEY (`uid`)
		REFERENCES `user` (`uid`),
	CONSTRAINT `me_fk_recipient`
		FOREIGN KEY (`recipient_uid`)
		REFERENCES `user` (`uid`),
	CONSTRAINT `me_fk_sender`
		FOREIGN KEY (`sender_uid`)
		REFERENCES `user` (`uid`),
	CONSTRAINT `me_fk_meaid`
		FOREIGN KEY (`meaid`)
		REFERENCES `message_attachment` (`meaid`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- notification
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `notification`;


CREATE TABLE `notification`
(
	`nid` INTEGER(11)  NOT NULL AUTO_INCREMENT,
	`uid` INTEGER(11)  NOT NULL,
	`read` TINYINT(1) default 0 NOT NULL,
	`status` INTEGER(11) default 0 NOT NULL,
	`subject` VARCHAR(255)  NOT NULL,
	`message` TEXT  NOT NULL,
	`created_at` DATETIME  NOT NULL,
	PRIMARY KEY (`nid`),
	KEY `no_uid`(`uid`),
	CONSTRAINT `no_fk_uid`
		FOREIGN KEY (`uid`)
		REFERENCES `user` (`uid`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- mail_template
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `mail_template`;


CREATE TABLE `mail_template`
(
	`mtid` INTEGER(11)  NOT NULL AUTO_INCREMENT,
	`culture` VARCHAR(7)  NOT NULL,
	`type` VARCHAR(50)  NOT NULL,
	`subject` VARCHAR(255)  NOT NULL,
	`text` TEXT  NOT NULL,
	`created_at` DATETIME  NOT NULL,
	`updated_at` DATETIME  NOT NULL,
	PRIMARY KEY (`mtid`),
	UNIQUE KEY `mt_u_template` (`type`, `culture`),
	KEY `mt_i_culture`(`culture`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- message_attachment
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `message_attachment`;


CREATE TABLE `message_attachment`
(
	`meaid` INTEGER(11)  NOT NULL AUTO_INCREMENT,
	`meid` INTEGER(11)  NOT NULL,
	`filename` VARCHAR(255)  NOT NULL,
	`filesize` VARCHAR(255)  NOT NULL,
	`created_at` DATETIME  NOT NULL,
	PRIMARY KEY (`meaid`),
	KEY `ma_meid`(`meid`),
	CONSTRAINT `ma_fk_meid`
		FOREIGN KEY (`meid`)
		REFERENCES `message` (`meid`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- media
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `media`;


CREATE TABLE `media`
(
	`mid` INTEGER(11)  NOT NULL AUTO_INCREMENT,
	`uid` INTEGER(11)  NOT NULL,
	`mediakey` VARCHAR(32)  NOT NULL,
	`mediahash` VARCHAR(128)  NOT NULL,
	`mediatype` INTEGER(11)  NOT NULL,
	`mediasubtype` INTEGER(11)  NOT NULL,
	`spritemap` VARCHAR(255),
	`spritemap_count` INTEGER(11) default 0,
	`first` TINYINT(1) default 0 NOT NULL,
	`hidden` TINYINT(1) default 0 NOT NULL,
	`secret` TINYINT(1) default 0 NOT NULL,
	`status` INTEGER(11) default 0 NOT NULL,
	`featured` TINYINT(1) default 0 NOT NULL,
	`culture` VARCHAR(7)  NOT NULL,
	`properties` TEXT  NOT NULL,
	`childwelfare` TINYINT(1) default 0,
	`title` VARCHAR(255)  NOT NULL,
	`title_clean` VARCHAR(255)  NOT NULL,
	`sid` INTEGER(11),
	`duration` INTEGER(11) default 0 NOT NULL,
	`filesize` BIGINT(20) default 0 NOT NULL,
	`thumbnail_filename` VARCHAR(255),
	`thumbnail_custom_filename` VARCHAR(255),
	`source_filename` VARCHAR(255),
	`original_filename` VARCHAR(255),
	`scrambled_filename` VARCHAR(255),
	`server` VARCHAR(255),
	`transcoder` VARCHAR(255),
	`file_extension` VARCHAR(4)  NOT NULL,
	`meta_title` VARCHAR(255),
	`meta_description` TEXT,
	`meta_keywords` TEXT,
	`meta_author` VARCHAR(255),
	`meta_copyright` VARCHAR(255),
	`conversion_notice` VARCHAR(255),
	`sum_rating` FLOAT(8,2) default 0 NOT NULL,
	`sum_likes` INTEGER(11) default 0 NOT NULL,
	`count_views` INTEGER(11) default 0 NOT NULL,
	`count_views_embed` INTEGER(11) default 0 NOT NULL,
	`count_views_webtv` INTEGER(11) default 0 NOT NULL,
	`count_rating` INTEGER(11) default 0 NOT NULL,
	`count_likes` INTEGER(11) default 0 NOT NULL,
	`count_favorites` INTEGER(11) default 0 NOT NULL,
	`count_comments` INTEGER(11) default 0 NOT NULL,
	`count_flags` INTEGER(11) default 0 NOT NULL,
	`accept_comment` TINYINT(1) default 1 NOT NULL,
	`accept_rating` TINYINT(1) default 1 NOT NULL,
	`exported_to_youtube` TINYINT(1) default 0,
	`price` FLOAT(8,2) default 0 NOT NULL,
	`with_costs` TINYINT(1) default 0 NOT NULL,
	`preview_length` INTEGER(11) default 0,
	`enable_download` TINYINT(1) default 0,
	`enable_download_for_users` TINYINT(1) default 1,
	`priority_transcode` TINYINT default 0,
	`smil_exists` TINYINT(1) default 0,
	`created_at` DATETIME  NOT NULL,
	`updated_at` DATETIME  NOT NULL,
	`uploaded_at` DATETIME  NOT NULL,
	`converted_at` DATETIME,
	PRIMARY KEY (`mid`),
	KEY `m_i_uid`(`uid`),
	KEY `m_i_created_at`(`created_at`),
	KEY `m_i_uploaded_at`(`created_at`),
	KEY `m_i_type_status_hidden`(`mediatype`, `status`, `hidden`),
	KEY `m_i_status`(`status`),
	KEY `m_i_status_created`(`status`, `created_at`),
	KEY `m_i_status_uploaded`(`status`, `uploaded_at`),
	KEY `m_i_key_status`(`mediakey`, `status`),
	CONSTRAINT `m_fk_uid`
		FOREIGN KEY (`uid`)
		REFERENCES `user` (`uid`),
	INDEX `FI_k_sid` (`sid`),
	CONSTRAINT `m_fk_sid`
		FOREIGN KEY (`sid`)
		REFERENCES `statictext` (`sid`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- media_file
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `media_file`;


CREATE TABLE `media_file`
(
	`mfiid` INTEGER(11)  NOT NULL AUTO_INCREMENT,
	`mid` INTEGER(11)  NOT NULL,
	`filetype` VARCHAR(20)  NOT NULL,
	`mfoid` INTEGER(11),
	`status` INTEGER(11) default 0 NOT NULL,
	`preview` TINYINT(1) default 0 NOT NULL,
	`title` VARCHAR(255)  NOT NULL,
	`filename` VARCHAR(255)  NOT NULL,
	`created_at` DATETIME  NOT NULL,
	`updated_at` DATETIME  NOT NULL,
	`converted_at` DATETIME,
	PRIMARY KEY (`mfiid`),
	KEY `mfi_i_mid`(`mid`),
	KEY `mfi_i_mfoid`(`mfoid`),
	KEY `mfi_i_mid_mfoid`(`mid`, `mfoid`),
	CONSTRAINT `mfi_fk_mid`
		FOREIGN KEY (`mid`)
		REFERENCES `media` (`mid`),
	CONSTRAINT `mfi_fk_mfoid`
		FOREIGN KEY (`mfoid`)
		REFERENCES `media_format` (`mfoid`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- media_format
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `media_format`;


CREATE TABLE `media_format`
(
	`mfoid` INTEGER(11)  NOT NULL AUTO_INCREMENT,
	`status` INTEGER(11) default 0 NOT NULL,
	`title` VARCHAR(255)  NOT NULL,
	`resolution` VARCHAR(20)  NOT NULL,
	`bitrate_video` INTEGER(11)  NOT NULL,
	`bitrate_audio` INTEGER(11)  NOT NULL,
	`bitrate_video_mobile` INTEGER(11)  NOT NULL,
	`bitrate_audio_mobile` INTEGER(11)  NOT NULL,
	`weight` INTEGER(11) default 0 NOT NULL,
	`created_at` DATETIME  NOT NULL,
	`updated_at` DATETIME  NOT NULL,
	PRIMARY KEY (`mfoid`),
	KEY `mfo_i_resolution`(`resolution`),
	KEY `mfo_i_vbitrate`(`bitrate_video`),
	KEY `mfo_i_abitrate`(`bitrate_audio`),
	KEY `mfo_i_res_vrate`(`resolution`, `bitrate_video`),
	KEY `mfo_i_res_arate`(`resolution`, `bitrate_audio`),
	KEY `mfo_i_res_vrate_arate`(`resolution`, `bitrate_video`, `bitrate_audio`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- media_category
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `media_category`;


CREATE TABLE `media_category`
(
	`mid` INTEGER(11)  NOT NULL,
	`cid` INTEGER(11)  NOT NULL,
	PRIMARY KEY (`mid`,`cid`),
	KEY `mc_i_mid`(`mid`),
	KEY `mc_i_cid`(`cid`),
	CONSTRAINT `mc_fk_mid`
		FOREIGN KEY (`mid`)
		REFERENCES `media` (`mid`),
	CONSTRAINT `mc_fk_cid`
		FOREIGN KEY (`cid`)
		REFERENCES `category` (`cid`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- media_tag
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `media_tag`;


CREATE TABLE `media_tag`
(
	`mid` INTEGER(11)  NOT NULL,
	`tid` INTEGER(11)  NOT NULL,
	`pos` INTEGER(3)  NOT NULL,
	PRIMARY KEY (`mid`,`tid`),
	KEY `mt_i_mid`(`mid`),
	KEY `mt_i_tid`(`tid`),
	CONSTRAINT `mt_fk_mid`
		FOREIGN KEY (`mid`)
		REFERENCES `media` (`mid`),
	CONSTRAINT `mt_fk_tid`
		FOREIGN KEY (`tid`)
		REFERENCES `tag` (`tid`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- media_tag_title
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `media_tag_title`;


CREATE TABLE `media_tag_title`
(
	`mid` INTEGER(11)  NOT NULL,
	`ttid` INTEGER(11)  NOT NULL,
	`pos` INTEGER(3)  NOT NULL,
	PRIMARY KEY (`mid`,`ttid`),
	KEY `mtt_i_mid`(`mid`),
	KEY `mtt_i_ttid`(`ttid`),
	CONSTRAINT `mtt_fk_mid`
		FOREIGN KEY (`mid`)
		REFERENCES `media` (`mid`),
	CONSTRAINT `mtt_fk_ttid`
		FOREIGN KEY (`ttid`)
		REFERENCES `tag_title` (`ttid`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- media_rating
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `media_rating`;


CREATE TABLE `media_rating`
(
	`mid` INTEGER(11)  NOT NULL,
	`uid` INTEGER(11)  NOT NULL,
	`hostname` VARCHAR(255)  NOT NULL,
	`rating` INTEGER(3)  NOT NULL,
	`created_at` DATETIME  NOT NULL,
	`updated_at` DATETIME  NOT NULL,
	PRIMARY KEY (`mid`,`uid`,`hostname`,`created_at`),
	KEY `mr_i_mid`(`mid`),
	KEY `mr_i_uid`(`uid`),
	CONSTRAINT `mr_fk_mid`
		FOREIGN KEY (`mid`)
		REFERENCES `media` (`mid`),
	CONSTRAINT `mr_fk_uid`
		FOREIGN KEY (`uid`)
		REFERENCES `user` (`uid`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- media_like
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `media_like`;


CREATE TABLE `media_like`
(
	`mid` INTEGER(11)  NOT NULL,
	`uid` INTEGER(11)  NOT NULL,
	`hostname` VARCHAR(255)  NOT NULL,
	`like` INTEGER(3)  NOT NULL,
	`created_at` DATETIME  NOT NULL,
	`updated_at` DATETIME  NOT NULL,
	PRIMARY KEY (`mid`,`uid`,`hostname`,`created_at`),
	KEY `ml_i_mid`(`mid`),
	KEY `ml_i_uid`(`uid`),
	CONSTRAINT `ml_fk_mid`
		FOREIGN KEY (`mid`)
		REFERENCES `media` (`mid`),
	CONSTRAINT `ml_fk_uid`
		FOREIGN KEY (`uid`)
		REFERENCES `user` (`uid`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- media_comment
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `media_comment`;


CREATE TABLE `media_comment`
(
	`mcid` INTEGER(11)  NOT NULL AUTO_INCREMENT,
	`mid` INTEGER(11)  NOT NULL,
	`pid` INTEGER(11) default 0 NOT NULL,
	`uid` INTEGER(11)  NOT NULL,
	`ano_username` VARCHAR(255),
	`text` TEXT  NOT NULL,
	`status` INTEGER(11) default 0 NOT NULL,
	`created_at` DATETIME  NOT NULL,
	`updated_at` DATETIME  NOT NULL,
	PRIMARY KEY (`mcid`),
	KEY `mco_i_mid`(`mid`),
	KEY `mco_i_pid`(`pid`),
	KEY `mco_i_uid`(`uid`),
	CONSTRAINT `mco_fk_mid`
		FOREIGN KEY (`mid`)
		REFERENCES `media` (`mid`),
	CONSTRAINT `mco_fk_uid`
		FOREIGN KEY (`uid`)
		REFERENCES `user` (`uid`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- media_view
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `media_view`;


CREATE TABLE `media_view`
(
	`mvid` INTEGER(11)  NOT NULL AUTO_INCREMENT,
	`mid` INTEGER(11)  NOT NULL,
	`uid` INTEGER(11)  NOT NULL,
	`context` INTEGER(11)  NOT NULL,
	`sessid` VARCHAR(128)  NOT NULL,
	`hostname` VARCHAR(244)  NOT NULL,
	`external` TINYINT(1) default 0 NOT NULL,
	`external_url` VARCHAR(1024),
	`created_at` DATETIME  NOT NULL,
	PRIMARY KEY (`mvid`),
	KEY `mv_i_mid`(`mid`),
	KEY `mv_i_context`(`context`),
	KEY `mv_i_uid`(`uid`),
	KEY `mv_i_created_at`(`created_at`),
	KEY `mv_i_mid_context`(`mid`, `context`),
	KEY `mv_i_user_views`(`uid`, `context`, `sessid`(128)),
	KEY `mv_i_externals`(`mid`, `external_url`(128), `external`),
	CONSTRAINT `mv_fk_mid`
		FOREIGN KEY (`mid`)
		REFERENCES `media` (`mid`),
	CONSTRAINT `mv_fk_uid`
		FOREIGN KEY (`uid`)
		REFERENCES `user` (`uid`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- media_history
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `media_history`;


CREATE TABLE `media_history`
(
	`mid` INTEGER(11)  NOT NULL,
	`uid` INTEGER(11)  NOT NULL,
	`created_at` DATETIME  NOT NULL,
	PRIMARY KEY (`mid`,`uid`,`created_at`),
	KEY `mh_i_mid`(`mid`),
	KEY `mh_i_uid`(`uid`),
	CONSTRAINT `mh_fk_mid`
		FOREIGN KEY (`mid`)
		REFERENCES `media` (`mid`),
	CONSTRAINT `mh_fk_uid`
		FOREIGN KEY (`uid`)
		REFERENCES `user` (`uid`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- media_flag
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `media_flag`;


CREATE TABLE `media_flag`
(
	`flagid` INTEGER(11)  NOT NULL AUTO_INCREMENT,
	`mid` INTEGER(11)  NOT NULL,
	`uid` INTEGER(11)  NOT NULL,
	`reason` TEXT  NOT NULL,
	`status` INTEGER(11) default 0 NOT NULL,
	`created_at` DATETIME  NOT NULL,
	`updated_at` DATETIME  NOT NULL,
	PRIMARY KEY (`flagid`),
	KEY `mf_i_mid`(`mid`),
	KEY `mf_i_uid`(`uid`),
	KEY `mf_i_status`(`status`),
	CONSTRAINT `mf_fk_mid`
		FOREIGN KEY (`mid`)
		REFERENCES `media` (`mid`),
	CONSTRAINT `mf_fk_uid`
		FOREIGN KEY (`uid`)
		REFERENCES `user` (`uid`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- media_favorite
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `media_favorite`;


CREATE TABLE `media_favorite`
(
	`uid` INTEGER(11)  NOT NULL,
	`mid` INTEGER(11)  NOT NULL,
	`created_at` DATETIME  NOT NULL,
	`updated_at` DATETIME  NOT NULL,
	PRIMARY KEY (`uid`,`mid`),
	KEY `mfav_i_uid_mid`(`uid`, `mid`),
	KEY `mfav_i_uid`(`uid`),
	KEY `mfav_i_mid`(`mid`),
	CONSTRAINT `mfav_fk_uid`
		FOREIGN KEY (`uid`)
		REFERENCES `user` (`uid`),
	CONSTRAINT `mfav_fk_mid`
		FOREIGN KEY (`mid`)
		REFERENCES `media` (`mid`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- blog
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `blog`;


CREATE TABLE `blog`
(
	`blogid` INTEGER(11)  NOT NULL AUTO_INCREMENT,
	`uid` INTEGER(11)  NOT NULL,
	`status` INTEGER(11) default 0 NOT NULL,
	`title` VARCHAR(255)  NOT NULL,
	`teaser` TEXT  NOT NULL,
	`text` TEXT  NOT NULL,
	`sum_rating` FLOAT(8,2) default 0 NOT NULL,
	`sum_likes` INTEGER(11) default 0 NOT NULL,
	`count_views` INTEGER(11) default 0 NOT NULL,
	`count_rating` INTEGER(11) default 0 NOT NULL,
	`count_likes` INTEGER(11) default 0 NOT NULL,
	`count_favorites` INTEGER(11) default 0 NOT NULL,
	`count_comments` INTEGER(11) default 0 NOT NULL,
	`updated_by_user` VARCHAR(40),
	`created_at` DATETIME  NOT NULL,
	`updated_at` DATETIME  NOT NULL,
	PRIMARY KEY (`blogid`),
	KEY `blog_i_uid`(`uid`),
	CONSTRAINT `blog_fk_uid`
		FOREIGN KEY (`uid`)
		REFERENCES `user` (`uid`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- blog_tag
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `blog_tag`;


CREATE TABLE `blog_tag`
(
	`blogid` INTEGER(11)  NOT NULL,
	`tid` INTEGER(11)  NOT NULL,
	`pos` INTEGER(3)  NOT NULL,
	PRIMARY KEY (`blogid`,`tid`),
	KEY `bt_i_blogid`(`blogid`),
	KEY `bt_i_tid`(`tid`),
	CONSTRAINT `bt_fk_blogid`
		FOREIGN KEY (`blogid`)
		REFERENCES `blog` (`blogid`),
	CONSTRAINT `bt_fk_tid`
		FOREIGN KEY (`tid`)
		REFERENCES `tag` (`tid`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- blog_rating
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `blog_rating`;


CREATE TABLE `blog_rating`
(
	`blogid` INTEGER(11)  NOT NULL,
	`uid` INTEGER(11)  NOT NULL,
	`hostname` VARCHAR(255)  NOT NULL,
	`rating` INTEGER(3)  NOT NULL,
	`created_at` DATETIME  NOT NULL,
	`updated_at` DATETIME  NOT NULL,
	PRIMARY KEY (`blogid`,`uid`,`hostname`,`created_at`),
	KEY `br_i_blogid`(`blogid`),
	KEY `br_i_uid`(`uid`),
	CONSTRAINT `br_fk_blogid`
		FOREIGN KEY (`blogid`)
		REFERENCES `blog` (`blogid`),
	CONSTRAINT `br_fk_uid`
		FOREIGN KEY (`uid`)
		REFERENCES `user` (`uid`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- blog_like
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `blog_like`;


CREATE TABLE `blog_like`
(
	`blogid` INTEGER(11)  NOT NULL,
	`uid` INTEGER(11)  NOT NULL,
	`hostname` VARCHAR(255)  NOT NULL,
	`like` INTEGER(3)  NOT NULL,
	`created_at` DATETIME  NOT NULL,
	`updated_at` DATETIME  NOT NULL,
	PRIMARY KEY (`blogid`,`uid`,`hostname`,`created_at`),
	KEY `bl_i_blogid`(`blogid`),
	KEY `bl_i_uid`(`uid`),
	CONSTRAINT `bl_fk_blogid`
		FOREIGN KEY (`blogid`)
		REFERENCES `blog` (`blogid`),
	CONSTRAINT `bl_fk_uid`
		FOREIGN KEY (`uid`)
		REFERENCES `user` (`uid`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- blog_comment
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `blog_comment`;


CREATE TABLE `blog_comment`
(
	`bcid` INTEGER(11)  NOT NULL AUTO_INCREMENT,
	`blogid` INTEGER(11)  NOT NULL,
	`pid` INTEGER(11) default 0 NOT NULL,
	`uid` INTEGER(11)  NOT NULL,
	`ano_username` VARCHAR(255),
	`text` TEXT  NOT NULL,
	`status` INTEGER(11) default 0 NOT NULL,
	`updated_by_user` VARCHAR(40),
	`created_at` DATETIME  NOT NULL,
	`updated_at` DATETIME  NOT NULL,
	PRIMARY KEY (`bcid`),
	KEY `blogc_i_blogid`(`blogid`),
	KEY `blogc_i_pid`(`pid`),
	KEY `blogc_i_uid`(`uid`),
	CONSTRAINT `blogc_fk_blogid`
		FOREIGN KEY (`blogid`)
		REFERENCES `blog` (`blogid`),
	CONSTRAINT `blogc_fk_uid`
		FOREIGN KEY (`uid`)
		REFERENCES `user` (`uid`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- blog_view
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `blog_view`;


CREATE TABLE `blog_view`
(
	`bvid` INTEGER(11)  NOT NULL AUTO_INCREMENT,
	`blogid` INTEGER(11)  NOT NULL,
	`uid` INTEGER(11)  NOT NULL,
	`sessid` VARCHAR(128)  NOT NULL,
	`hostname` VARCHAR(244)  NOT NULL,
	`external` TINYINT(1) default 0 NOT NULL,
	`external_url` VARCHAR(1024),
	`created_at` DATETIME  NOT NULL,
	PRIMARY KEY (`bvid`),
	KEY `bv_i_blogid`(`blogid`),
	KEY `bv_i_uid`(`uid`),
	CONSTRAINT `bv_fk_blogid`
		FOREIGN KEY (`blogid`)
		REFERENCES `blog` (`blogid`),
	CONSTRAINT `bv_fk_uid`
		FOREIGN KEY (`uid`)
		REFERENCES `user` (`uid`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- blog_favorite
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `blog_favorite`;


CREATE TABLE `blog_favorite`
(
	`blogid` INTEGER(11)  NOT NULL,
	`uid` INTEGER(11)  NOT NULL,
	`created_at` DATETIME  NOT NULL,
	`updated_at` DATETIME  NOT NULL,
	PRIMARY KEY (`blogid`,`uid`),
	KEY `fb_i_uid`(`uid`),
	KEY `fb_i_blogid`(`blogid`),
	CONSTRAINT `fb_fk_uid`
		FOREIGN KEY (`uid`)
		REFERENCES `user` (`uid`),
	CONSTRAINT `fb_fk_blogid`
		FOREIGN KEY (`blogid`)
		REFERENCES `blog` (`blogid`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- media_field
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `media_field`;


CREATE TABLE `media_field`
(
	`mfid` INTEGER(11)  NOT NULL AUTO_INCREMENT,
	`fieldtype` INTEGER(11)  NOT NULL,
	`fieldname` VARCHAR(255)  NOT NULL,
	`required` TINYINT(1) default 0 NOT NULL,
	`payment_only` TINYINT(1) default 0 NOT NULL,
	`hidden` TINYINT(1) default 0 NOT NULL,
	`readonly` TINYINT(1) default 0 NOT NULL,
	`defaultvalue` VARCHAR(255),
	`maxlength` INTEGER(11),
	`min` VARCHAR(255),
	`max` VARCHAR(255),
	`weight` INTEGER(11) default 0 NOT NULL,
	`status` INTEGER(11) default 0 NOT NULL,
	`open_in_new_tab` TINYINT(1) default 0 NOT NULL,
	`created_at` DATETIME  NOT NULL,
	`updated_at` DATETIME  NOT NULL,
	PRIMARY KEY (`mfid`),
	KEY `mfi_i_mfid`(`mfid`),
	KEY `mfi_i_fieldtype`(`fieldtype`),
	KEY `mfi_i_fieldname`(`fieldname`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- media_field_i18n
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `media_field_i18n`;


CREATE TABLE `media_field_i18n`
(
	`mfid` INTEGER(11)  NOT NULL,
	`culture` VARCHAR(7)  NOT NULL,
	`name` VARCHAR(255)  NOT NULL,
	`description` TEXT,
	PRIMARY KEY (`mfid`,`culture`),
	KEY `mfii_i_mfid`(`mfid`),
	KEY `mfii_i_culture`(`culture`),
	CONSTRAINT `mfii_fk_mfid`
		FOREIGN KEY (`mfid`)
		REFERENCES `media_field` (`mfid`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- media_field_option
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `media_field_option`;


CREATE TABLE `media_field_option`
(
	`mfoid` INTEGER(11)  NOT NULL AUTO_INCREMENT,
	`mfid` INTEGER(11)  NOT NULL,
	`value` VARCHAR(255)  NOT NULL,
	`weight` INTEGER(11) default 0 NOT NULL,
	`created_at` DATETIME  NOT NULL,
	`updated_at` DATETIME  NOT NULL,
	PRIMARY KEY (`mfoid`),
	KEY `mfo_i_mfid`(`mfid`),
	KEY `mfo_i_value`(`value`),
	CONSTRAINT `mfo_fk_ufid`
		FOREIGN KEY (`mfid`)
		REFERENCES `media_field` (`mfid`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- media_field_option_i18n
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `media_field_option_i18n`;


CREATE TABLE `media_field_option_i18n`
(
	`mfoid` INTEGER(11)  NOT NULL,
	`culture` VARCHAR(7)  NOT NULL,
	`name` VARCHAR(255)  NOT NULL,
	PRIMARY KEY (`mfoid`,`culture`),
	KEY `mfoi_i_mfoid`(`mfoid`),
	KEY `mfoi_i_culture`(`culture`),
	CONSTRAINT `mfoi_fk_mfoid`
		FOREIGN KEY (`mfoid`)
		REFERENCES `media_field_option` (`mfoid`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- media_field_value
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `media_field_value`;


CREATE TABLE `media_field_value`
(
	`mid` INTEGER(11)  NOT NULL,
	`mfid` INTEGER(11)  NOT NULL,
	`value` TEXT,
	`created_at` DATETIME  NOT NULL,
	`updated_at` DATETIME  NOT NULL,
	PRIMARY KEY (`mid`,`mfid`),
	KEY `mfv_i_mfid`(`mfid`),
	KEY `mfv_i_mid`(`mid`),
	CONSTRAINT `mfv_fk_mfid`
		FOREIGN KEY (`mfid`)
		REFERENCES `media_field` (`mfid`),
	CONSTRAINT `mfv_fk_mid`
		FOREIGN KEY (`mid`)
		REFERENCES `media` (`mid`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- menu
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `menu`;


CREATE TABLE `menu`
(
	`menuid` INTEGER(11)  NOT NULL AUTO_INCREMENT,
	`pid` INTEGER(11) default 0 NOT NULL,
	`menutype` INTEGER(11)  NOT NULL,
	`status` INTEGER(11) default 0 NOT NULL,
	`weight` INTEGER(11) default 0 NOT NULL,
	`submenu` TINYINT(1) default 0 NOT NULL,
	`page` INTEGER(11),
	`external_url` VARCHAR(1024),
	`target` INTEGER(11) default 0 NOT NULL,
	`cssid` VARCHAR(30),
	`created_at` DATETIME  NOT NULL,
	`updated_at` DATETIME  NOT NULL,
	PRIMARY KEY (`menuid`),
	KEY `mnu_i_pid`(`pid`),
	KEY `mnu_i_type`(`menutype`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- menu_i18n
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `menu_i18n`;


CREATE TABLE `menu_i18n`
(
	`menuid` INTEGER(11)  NOT NULL,
	`culture` VARCHAR(7)  NOT NULL,
	`name` VARCHAR(255)  NOT NULL,
	`description` TEXT,
	PRIMARY KEY (`menuid`,`culture`),
	KEY `mi_i_menuid`(`menuid`),
	KEY `mi_i_culture`(`culture`),
	CONSTRAINT `mi_fk_menuid`
		FOREIGN KEY (`menuid`)
		REFERENCES `menu` (`menuid`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- session
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `session`;


CREATE TABLE `session`
(
	`sessid` VARCHAR(128)  NOT NULL,
	`uid` INTEGER(11)  NOT NULL,
	`hostname` VARCHAR(244)  NOT NULL,
	`session` LONGTEXT,
	`created_at` DATETIME  NOT NULL,
	PRIMARY KEY (`sessid`,`uid`),
	KEY `sess_i_sessid`(`sessid`),
	KEY `sess_i_uid`(`uid`),
	CONSTRAINT `sess_fk_uid`
		FOREIGN KEY (`uid`)
		REFERENCES `user` (`uid`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- activity
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `activity`;


CREATE TABLE `activity`
(
	`aid` INTEGER(11)  NOT NULL AUTO_INCREMENT,
	`uid` INTEGER(11)  NOT NULL,
	`type` VARCHAR(80)  NOT NULL,
	`objectid` INTEGER(11)  NOT NULL,
	`data` LONGTEXT,
	`created_at` DATETIME  NOT NULL,
	PRIMARY KEY (`aid`),
	KEY `a_i_uid`(`uid`),
	KEY `a_i_type`(`type`),
	CONSTRAINT `a_fk_uid`
		FOREIGN KEY (`uid`)
		REFERENCES `user` (`uid`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- watchdog
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `watchdog`;


CREATE TABLE `watchdog`
(
	`wid` INTEGER(11)  NOT NULL AUTO_INCREMENT,
	`uid` INTEGER(11)  NOT NULL,
	`type` VARCHAR(20)  NOT NULL,
	`severity` INTEGER(3) default 0 NOT NULL,
	`message` LONGTEXT  NOT NULL,
	`hostname` VARCHAR(244)  NOT NULL,
	`referer` VARCHAR(1024),
	`created_at` DATETIME  NOT NULL,
	PRIMARY KEY (`wid`,`type`),
	KEY `w_i_wid`(`wid`),
	KEY `w_i_uid`(`uid`),
	KEY `w_i_type`(`type`),
	CONSTRAINT `w_fk_uid`
		FOREIGN KEY (`uid`)
		REFERENCES `user` (`uid`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- stopword
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `stopword`;


CREATE TABLE `stopword`
(
	`sid` INTEGER(11)  NOT NULL,
	`status` INTEGER(1) default 1 NOT NULL,
	`culture` VARCHAR(7)  NOT NULL,
	`name` VARCHAR(25)  NOT NULL,
	PRIMARY KEY (`sid`),
	KEY `sw_i_name`(`name`),
	KEY `sw_i_culture`(`culture`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- catalogue
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `catalogue`;


CREATE TABLE `catalogue`
(
	`cat_id` INTEGER(11)  NOT NULL AUTO_INCREMENT,
	`name` VARCHAR(100),
	`source_lang` VARCHAR(100),
	`target_lang` VARCHAR(100),
	`date_created` DATETIME,
	`date_modified` DATETIME,
	`author` VARCHAR(255),
	PRIMARY KEY (`cat_id`),
	KEY `target_lang`(`target_lang`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- trans_unit
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `trans_unit`;


CREATE TABLE `trans_unit`
(
	`msg_id` INTEGER(11)  NOT NULL AUTO_INCREMENT,
	`cat_id` INTEGER(11)  NOT NULL,
	`id` VARCHAR(255),
	`source` TEXT,
	`target` TEXT,
	`comments` TEXT,
	`date_added` DATETIME,
	`date_modified` DATETIME,
	`author` VARCHAR(255),
	`translated` INTEGER(1) default 0 NOT NULL,
	PRIMARY KEY (`msg_id`),
	KEY `source`(`cat_id`, `source`(255)),
	CONSTRAINT `tu_fk_cat_id`
		FOREIGN KEY (`cat_id`)
		REFERENCES `catalogue` (`cat_id`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- forum
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `forum`;


CREATE TABLE `forum`
(
	`forumid` INTEGER(11)  NOT NULL AUTO_INCREMENT,
	`forumtype` INTEGER(11) default 0 NOT NULL,
	`forumkey` VARCHAR(32)  NOT NULL,
	`status` INTEGER(11) default 0 NOT NULL,
	`sid` INTEGER(11)  NOT NULL,
	`count_threads` INTEGER(11) default 0 NOT NULL,
	`count_thread_users` INTEGER(11) default 0 NOT NULL,
	`last_thread` DATETIME,
	`count_comments` INTEGER(11) default 0 NOT NULL,
	`count_comment_users` INTEGER(11) default 0 NOT NULL,
	`last_comment` DATETIME,
	`created_at` DATETIME  NOT NULL,
	`updated_at` DATETIME  NOT NULL,
	PRIMARY KEY (`forumid`),
	KEY `forum_i_forumkey`(`forumkey`),
	KEY `forum_i_forumtype`(`forumtype`),
	KEY `forum_i_sid`(`sid`),
	CONSTRAINT `forum_fk_sid`
		FOREIGN KEY (`sid`)
		REFERENCES `statictext` (`sid`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- forum_thread
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `forum_thread`;


CREATE TABLE `forum_thread`
(
	`threadid` INTEGER(11)  NOT NULL AUTO_INCREMENT,
	`forumid` INTEGER(11)  NOT NULL,
	`uid` INTEGER(11)  NOT NULL,
	`sid` INTEGER(11)  NOT NULL,
	`status` INTEGER(11) default 0 NOT NULL,
	`count_comments` INTEGER(11) default 0 NOT NULL,
	`count_comment_users` INTEGER(11) default 0 NOT NULL,
	`last_comment` DATETIME,
	`created_at` DATETIME  NOT NULL,
	`updated_at` DATETIME  NOT NULL,
	PRIMARY KEY (`threadid`),
	KEY `ft_i_uid`(`uid`),
	KEY `ft_i_sid`(`sid`),
	INDEX `FI_fk_forumid` (`forumid`),
	CONSTRAINT `ft_fk_forumid`
		FOREIGN KEY (`forumid`)
		REFERENCES `forum` (`forumid`),
	CONSTRAINT `ft_fk_uid`
		FOREIGN KEY (`uid`)
		REFERENCES `user` (`uid`),
	CONSTRAINT `ft_fk_sid`
		FOREIGN KEY (`sid`)
		REFERENCES `statictext` (`sid`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- forum_comment
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `forum_comment`;


CREATE TABLE `forum_comment`
(
	`commentid` INTEGER(11)  NOT NULL AUTO_INCREMENT,
	`threadid` INTEGER(11)  NOT NULL,
	`sid` INTEGER(11)  NOT NULL,
	`uid` INTEGER(11)  NOT NULL,
	`pid` INTEGER(11) default 0 NOT NULL,
	`ano_username` VARCHAR(255),
	`status` INTEGER(11) default 0 NOT NULL,
	`created_at` DATETIME  NOT NULL,
	`updated_at` DATETIME  NOT NULL,
	PRIMARY KEY (`commentid`),
	KEY `fc_i_threadid`(`threadid`),
	KEY `fc_i_sid`(`sid`),
	KEY `fc_i_uid`(`uid`),
	KEY `fc_i_pid`(`pid`),
	CONSTRAINT `fc_fk_threadid`
		FOREIGN KEY (`threadid`)
		REFERENCES `forum_thread` (`threadid`),
	CONSTRAINT `fc_fk_sid`
		FOREIGN KEY (`sid`)
		REFERENCES `statictext` (`sid`),
	CONSTRAINT `fc_fk_uid`
		FOREIGN KEY (`uid`)
		REFERENCES `user` (`uid`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- forum_view
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `forum_view`;


CREATE TABLE `forum_view`
(
	`fvid` INTEGER(11)  NOT NULL AUTO_INCREMENT,
	`threadid` INTEGER(11)  NOT NULL,
	`uid` INTEGER(11)  NOT NULL,
	`sessid` VARCHAR(128)  NOT NULL,
	`hostname` VARCHAR(244)  NOT NULL,
	`external` TINYINT(1) default 0 NOT NULL,
	`external_url` VARCHAR(1024),
	`created_at` DATETIME  NOT NULL,
	PRIMARY KEY (`fvid`),
	KEY `fv_i_threadid`(`threadid`),
	KEY `fv_i_uid`(`uid`),
	CONSTRAINT `fv_fk_threadid`
		FOREIGN KEY (`threadid`)
		REFERENCES `forum_thread` (`threadid`),
	CONSTRAINT `fv_fk_uid`
		FOREIGN KEY (`uid`)
		REFERENCES `user` (`uid`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- user
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `user`;


CREATE TABLE `user`
(
	`uid` INTEGER(11)  NOT NULL AUTO_INCREMENT,
	`hidden` TINYINT(1) default 0 NOT NULL,
	`status` INTEGER(11) default 0 NOT NULL,
	`culture` VARCHAR(7)  NOT NULL,
	`username` VARCHAR(40)  NOT NULL,
	`password` VARCHAR(128)  NOT NULL,
	`email` VARCHAR(255)  NOT NULL,
	`validation_code` VARCHAR(40)  NOT NULL,
	`reset_pass_validation_code` VARCHAR(40),
	`deletion_code` VARCHAR(40),
	`avatar_filename` VARCHAR(255),
	`cover_filename` VARCHAR(255),
	`last_login_at` DATETIME,
	`last_access_at` DATETIME,
	`count_views` INTEGER(11) default 0 NOT NULL,
	`count_comments` INTEGER(11) default 0 NOT NULL,
	`count_flags` INTEGER(11) default 0 NOT NULL,
	`count_media_views` INTEGER(11) default 0 NOT NULL,
	`count_video_views` INTEGER(11) default 0 NOT NULL,
	`count_photo_views` INTEGER(11) default 0 NOT NULL,
	`count_audio_views` INTEGER(11) default 0 NOT NULL,
	`count_document_views` INTEGER(11) default 0 NOT NULL,
	`count_youtube_views` INTEGER(11) default 0 NOT NULL,
	`count_vimeo_views` INTEGER(11) default 0 NOT NULL,
	`count_own_media_views` INTEGER(11) default 0 NOT NULL,
	`count_friends` INTEGER(11) default 0 NOT NULL,
	`count_favorites` INTEGER(11) default 0 NOT NULL,
	`count_blog_comments` INTEGER(11) default 0 NOT NULL,
	`count_own_blog_comments` INTEGER(11) default 0 NOT NULL,
	`count_forum_comments` INTEGER(11) default 0 NOT NULL,
	`count_own_forum_comments` INTEGER(11) default 0 NOT NULL,
	`count_groups` INTEGER(11) default 0 NOT NULL,
	`count_own_groups` INTEGER(11) default 0 NOT NULL,
	`count_own_media` INTEGER(11) default 0 NOT NULL,
	`count_own_media_videos` INTEGER(11) default 0 NOT NULL,
	`count_own_media_photos` INTEGER(11) default 0 NOT NULL,
	`count_own_media_audios` INTEGER(11) default 0 NOT NULL,
	`count_own_media_documents` INTEGER(11) default 0 NOT NULL,
	`count_own_media_youtube` INTEGER(11) default 0 NOT NULL,
	`count_own_media_vimeo` INTEGER(11) default 0 NOT NULL,
	`count_favorite_albums` INTEGER(11) default 0 NOT NULL,
	`count_albums` INTEGER(11) default 0 NOT NULL,
	`count_rating` INTEGER(11) default 0 NOT NULL,
	`sum_rating` FLOAT(8,2) default 0 NOT NULL,
	`terms_confirmed` DATETIME default '' NOT NULL,
	`password_date` DATETIME default '' NOT NULL,
	`last_site` TEXT,
	`created_at` DATETIME  NOT NULL,
	`updated_at` DATETIME  NOT NULL,
	PRIMARY KEY (`uid`),
	KEY `u_i_username`(`username`),
	KEY `u_i_email`(`email`),
	KEY `u_i_validation_code`(`validation_code`),
	KEY `u_i_created_at`(`created_at`),
	KEY `u_i_status`(`status`),
	KEY `u_i_status_created`(`status`, `created_at`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- user_role
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `user_role`;


CREATE TABLE `user_role`
(
	`uid` INTEGER(11)  NOT NULL,
	`rid` INTEGER(11)  NOT NULL,
	PRIMARY KEY (`uid`,`rid`),
	KEY `ur_i_uid`(`uid`),
	KEY `ur_i_rid`(`rid`),
	CONSTRAINT `ur_fk_uid`
		FOREIGN KEY (`uid`)
		REFERENCES `user` (`uid`),
	CONSTRAINT `ur_fk_rid`
		FOREIGN KEY (`rid`)
		REFERENCES `role` (`rid`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- user_friend
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `user_friend`;


CREATE TABLE `user_friend`
(
	`fid` INTEGER(11)  NOT NULL AUTO_INCREMENT,
	`uid` INTEGER(11)  NOT NULL,
	`friend_uid` INTEGER(11)  NOT NULL,
	`status` INTEGER(11)  NOT NULL,
	`created_at` DATETIME  NOT NULL,
	`updated_at` DATETIME  NOT NULL,
	PRIMARY KEY (`fid`),
	KEY `uf_i_uid`(`uid`),
	KEY `uf_i_friend_uid`(`friend_uid`),
	CONSTRAINT `uf_fk_uid`
		FOREIGN KEY (`uid`)
		REFERENCES `user` (`uid`),
	CONSTRAINT `uf_fk_friend_uid`
		FOREIGN KEY (`friend_uid`)
		REFERENCES `user` (`uid`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- user_invite
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `user_invite`;


CREATE TABLE `user_invite`
(
	`fid` INTEGER(11)  NOT NULL AUTO_INCREMENT,
	`friend_uid` INTEGER(11)  NOT NULL,
	`name` VARCHAR(40)  NOT NULL,
	`email` VARCHAR(255)  NOT NULL,
	`message_sid` INTEGER(11)  NOT NULL,
	`validation_code` VARCHAR(40)  NOT NULL,
	`status` INTEGER(11)  NOT NULL,
	`created_at` DATETIME  NOT NULL,
	`updated_at` DATETIME  NOT NULL,
	PRIMARY KEY (`fid`),
	INDEX `FI_fk_friend_uid` (`friend_uid`),
	CONSTRAINT `ui_fk_friend_uid`
		FOREIGN KEY (`friend_uid`)
		REFERENCES `user` (`uid`),
	INDEX `FI_fk_message_sid` (`message_sid`),
	CONSTRAINT `ui_fk_message_sid`
		FOREIGN KEY (`message_sid`)
		REFERENCES `statictext` (`sid`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- user_comment
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `user_comment`;


CREATE TABLE `user_comment`
(
	`ucid` INTEGER(11)  NOT NULL AUTO_INCREMENT,
	`uid` INTEGER(11)  NOT NULL,
	`pid` INTEGER(11) default 0 NOT NULL,
	`annotator_uid` INTEGER(11)  NOT NULL,
	`ano_username` VARCHAR(255),
	`text` TEXT  NOT NULL,
	`status` INTEGER(11) default 0 NOT NULL,
	`created_at` DATETIME  NOT NULL,
	`updated_at` DATETIME  NOT NULL,
	PRIMARY KEY (`ucid`),
	KEY `uc_i_uid`(`uid`),
	KEY `uc_i_pid`(`pid`),
	KEY `uc_i_annotator_uid`(`annotator_uid`),
	CONSTRAINT `uc_fk_uid`
		FOREIGN KEY (`uid`)
		REFERENCES `user` (`uid`),
	CONSTRAINT `uc_fk_annotator_uid`
		FOREIGN KEY (`annotator_uid`)
		REFERENCES `user` (`uid`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- user_view
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `user_view`;


CREATE TABLE `user_view`
(
	`uvid` INTEGER(11)  NOT NULL AUTO_INCREMENT,
	`uid` INTEGER(11)  NOT NULL,
	`viewer_uid` INTEGER(11)  NOT NULL,
	`sessid` VARCHAR(128)  NOT NULL,
	`hostname` VARCHAR(244)  NOT NULL,
	`external` TINYINT(1) default 0 NOT NULL,
	`external_url` VARCHAR(1024),
	`created_at` DATETIME  NOT NULL,
	PRIMARY KEY (`uvid`),
	KEY `uv_i_vuid_sessid`(`viewer_uid`, `sessid`),
	KEY `uv_i_uid`(`uid`),
	KEY `uv_i_viewer_uid`(`viewer_uid`),
	CONSTRAINT `uv_fk_uid`
		FOREIGN KEY (`uid`)
		REFERENCES `user` (`uid`),
	CONSTRAINT `uv_fk_viewer_uid`
		FOREIGN KEY (`viewer_uid`)
		REFERENCES `user` (`uid`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- user_flag
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `user_flag`;


CREATE TABLE `user_flag`
(
	`flagid` INTEGER(11)  NOT NULL AUTO_INCREMENT,
	`uid` INTEGER(11)  NOT NULL,
	`flagged_uid` INTEGER(11)  NOT NULL,
	`reason` TEXT  NOT NULL,
	`status` INTEGER(11) default 0 NOT NULL,
	`created_at` DATETIME  NOT NULL,
	`updated_at` DATETIME  NOT NULL,
	PRIMARY KEY (`flagid`),
	KEY `ufl_i_uid`(`uid`),
	KEY `ufl_i_flagged_uid`(`flagged_uid`),
	KEY `ufl_i_status`(`status`),
	CONSTRAINT `ufl_fk_uid`
		FOREIGN KEY (`uid`)
		REFERENCES `user` (`uid`),
	CONSTRAINT `ufl_fk_flagged_uid`
		FOREIGN KEY (`flagged_uid`)
		REFERENCES `user` (`uid`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- channel
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `channel`;


CREATE TABLE `channel`
(
	`chid` INTEGER(11)  NOT NULL AUTO_INCREMENT,
	`hidden` TINYINT(1) default 0 NOT NULL,
	`verify` TINYINT(1) default 0 NOT NULL,
	`upload` TINYINT(1) default 0 NOT NULL,
	`status` INTEGER(11) default 0 NOT NULL,
	`uid` INTEGER(11)  NOT NULL,
	`picture_filename` VARCHAR(255),
	`picture_menu_filename` VARCHAR(255),
	`font_color_title` VARCHAR(16) default '',
	`font_color_content` VARCHAR(16) default '',
	`notify_member` TINYINT(1) default 0 NOT NULL,
	`weight` INTEGER(11) default 0 NOT NULL,
	`price` FLOAT(8,2) default 0 NOT NULL,
	`with_costs` TINYINT(1) default 0 NOT NULL,
	`count_users` INTEGER(11) default 0 NOT NULL,
	`count_media` INTEGER(11) default 0 NOT NULL,
	`count_media_videos` INTEGER(11) default 0 NOT NULL,
	`count_media_photos` INTEGER(11) default 0 NOT NULL,
	`count_media_audios` INTEGER(11) default 0 NOT NULL,
	`count_media_documents` INTEGER(11) default 0 NOT NULL,
	`count_media_youtube` INTEGER(11) default 0 NOT NULL,
	`count_media_vimeo` INTEGER(11) default 0 NOT NULL,
	`created_at` DATETIME  NOT NULL,
	`updated_at` DATETIME  NOT NULL,
	PRIMARY KEY (`chid`),
	KEY `ch_i_uid`(`uid`),
	KEY `ch_i_created_at`(`created_at`),
	KEY `ch_i_status`(`status`),
	KEY `ch_i_status_created`(`status`, `created_at`),
	CONSTRAINT `ch_fk_uid`
		FOREIGN KEY (`uid`)
		REFERENCES `user` (`uid`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- channel_i18n
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `channel_i18n`;


CREATE TABLE `channel_i18n`
(
	`chid` INTEGER(11)  NOT NULL,
	`culture` VARCHAR(7)  NOT NULL,
	`name` VARCHAR(255)  NOT NULL,
	`description` TEXT,
	PRIMARY KEY (`chid`,`culture`),
	KEY `chi_i_chid`(`chid`),
	KEY `chi_i_culture`(`culture`),
	CONSTRAINT `chi_fk_chid`
		FOREIGN KEY (`chid`)
		REFERENCES `channel` (`chid`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- channel_user
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `channel_user`;


CREATE TABLE `channel_user`
(
	`chid` INTEGER(11)  NOT NULL,
	`uid` INTEGER(11)  NOT NULL,
	`rid` INTEGER(11)  NOT NULL,
	`status` INTEGER(11) default 0 NOT NULL,
	`created_at` DATETIME  NOT NULL,
	`updated_at` DATETIME  NOT NULL,
	PRIMARY KEY (`chid`,`uid`),
	KEY `chu_i_chid`(`chid`),
	KEY `chu_i_uid`(`uid`),
	CONSTRAINT `chu_fk_chid`
		FOREIGN KEY (`chid`)
		REFERENCES `channel` (`chid`),
	CONSTRAINT `chu_fk_uid`
		FOREIGN KEY (`uid`)
		REFERENCES `user` (`uid`),
	INDEX `FI__fk_rid` (`rid`),
	CONSTRAINT `chu_fk_rid`
		FOREIGN KEY (`rid`)
		REFERENCES `role` (`rid`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- channel_media
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `channel_media`;


CREATE TABLE `channel_media`
(
	`chid` INTEGER(11)  NOT NULL,
	`mid` INTEGER(11)  NOT NULL,
	`status` INTEGER(11) default 0 NOT NULL,
	`created_at` DATETIME  NOT NULL,
	`updated_at` DATETIME  NOT NULL,
	PRIMARY KEY (`chid`,`mid`),
	KEY `chm_i_chid`(`chid`),
	KEY `chm_i_mid`(`mid`),
	CONSTRAINT `chm_fk_chid`
		FOREIGN KEY (`chid`)
		REFERENCES `channel` (`chid`),
	CONSTRAINT `chm_fk_mid`
		FOREIGN KEY (`mid`)
		REFERENCES `media` (`mid`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- channel_category
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `channel_category`;


CREATE TABLE `channel_category`
(
	`chid` INTEGER(11)  NOT NULL,
	`cid` INTEGER(11)  NOT NULL,
	PRIMARY KEY (`chid`,`cid`),
	KEY `chc_i_chid`(`chid`),
	KEY `chc_i_cid`(`cid`),
	CONSTRAINT `chc_fk_chid`
		FOREIGN KEY (`chid`)
		REFERENCES `channel` (`chid`),
	CONSTRAINT `chc_fk_cid`
		FOREIGN KEY (`cid`)
		REFERENCES `category` (`cid`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- channel_view
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `channel_view`;


CREATE TABLE `channel_view`
(
	`chvid` INTEGER(11)  NOT NULL AUTO_INCREMENT,
	`chid` INTEGER(11)  NOT NULL,
	`uid` INTEGER(11)  NOT NULL,
	`sessid` VARCHAR(128)  NOT NULL,
	`hostname` VARCHAR(244)  NOT NULL,
	`external` TINYINT(1) default 0 NOT NULL,
	`external_url` VARCHAR(1024),
	`created_at` DATETIME  NOT NULL,
	PRIMARY KEY (`chvid`),
	KEY `chv_i_chid`(`chid`),
	KEY `chv_i_uid`(`uid`),
	CONSTRAINT `chv_fk_chid`
		FOREIGN KEY (`chid`)
		REFERENCES `channel` (`chid`),
	CONSTRAINT `chv_fk_uid`
		FOREIGN KEY (`uid`)
		REFERENCES `user` (`uid`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- role
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `role`;


CREATE TABLE `role`
(
	`rid` INTEGER(11)  NOT NULL AUTO_INCREMENT,
	`status` INTEGER(11) default 0 NOT NULL,
	`weight` INTEGER(11) default 0 NOT NULL,
	`created_at` DATETIME  NOT NULL,
	`updated_at` DATETIME  NOT NULL,
	PRIMARY KEY (`rid`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- role_i18n
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `role_i18n`;


CREATE TABLE `role_i18n`
(
	`rid` INTEGER(11)  NOT NULL,
	`culture` VARCHAR(7)  NOT NULL,
	`name` VARCHAR(255)  NOT NULL,
	`description` TEXT,
	PRIMARY KEY (`rid`,`culture`),
	KEY `ri_i_rid`(`rid`),
	KEY `ri_i_culture`(`culture`),
	CONSTRAINT `ri_fk_rid`
		FOREIGN KEY (`rid`)
		REFERENCES `role` (`rid`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- role_permission
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `role_permission`;


CREATE TABLE `role_permission`
(
	`rid` INTEGER(11)  NOT NULL,
	`perm` VARCHAR(255)  NOT NULL,
	`created_at` DATETIME  NOT NULL,
	PRIMARY KEY (`rid`,`perm`),
	KEY `rp_i_rid`(`rid`),
	KEY `rp_i_perm`(`perm`),
	CONSTRAINT `rp_fk_rid`
		FOREIGN KEY (`rid`)
		REFERENCES `role` (`rid`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- category
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `category`;


CREATE TABLE `category`
(
	`cid` INTEGER(11)  NOT NULL AUTO_INCREMENT,
	`pid` INTEGER(11),
	`categorytype` INTEGER(11)  NOT NULL,
	`status` INTEGER(11) default 0 NOT NULL,
	`picture_filename` VARCHAR(255),
	`weight` INTEGER(11) default 0 NOT NULL,
	`transcoding_priority` TINYINT default 0,
	`created_at` DATETIME  NOT NULL,
	`updated_at` DATETIME  NOT NULL,
	PRIMARY KEY (`cid`),
	KEY `ca_i_pid`(`pid`),
	CONSTRAINT `ca_fk_pid`
		FOREIGN KEY (`pid`)
		REFERENCES `category` (`cid`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- category_i18n
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `category_i18n`;


CREATE TABLE `category_i18n`
(
	`cid` INTEGER(11)  NOT NULL,
	`culture` VARCHAR(7)  NOT NULL,
	`name` VARCHAR(255)  NOT NULL,
	`description` TEXT,
	PRIMARY KEY (`cid`,`culture`),
	KEY `ci_i_cid`(`cid`),
	KEY `ci_i_culture`(`culture`),
	CONSTRAINT `ci_fk_cid`
		FOREIGN KEY (`cid`)
		REFERENCES `category` (`cid`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- user_field
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `user_field`;


CREATE TABLE `user_field`
(
	`ufid` INTEGER(11)  NOT NULL AUTO_INCREMENT,
	`fieldtype` INTEGER(11)  NOT NULL,
	`fieldname` VARCHAR(255)  NOT NULL,
	`required` TINYINT(1) default 0 NOT NULL,
	`hidden` TINYINT(1) default 0 NOT NULL,
	`registration` TINYINT(1) default 0 NOT NULL,
	`readonly` TINYINT(1) default 0 NOT NULL,
	`defaultvalue` VARCHAR(255),
	`maxlength` INTEGER(11),
	`min` VARCHAR(255),
	`max` VARCHAR(255),
	`weight` INTEGER(11) default 0 NOT NULL,
	`status` INTEGER(11) default 0 NOT NULL,
	`open_in_new_tab` TINYINT(1) default 0 NOT NULL,
	`created_at` DATETIME  NOT NULL,
	`updated_at` DATETIME  NOT NULL,
	PRIMARY KEY (`ufid`),
	KEY `ufi_i_ufid`(`ufid`),
	KEY `ufi_i_fieldtype`(`fieldtype`),
	KEY `ufi_i_fieldname`(`fieldname`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- user_field_i18n
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `user_field_i18n`;


CREATE TABLE `user_field_i18n`
(
	`ufid` INTEGER(11)  NOT NULL,
	`culture` VARCHAR(7)  NOT NULL,
	`name` VARCHAR(255)  NOT NULL,
	`description` TEXT,
	PRIMARY KEY (`ufid`,`culture`),
	KEY `ufii_i_ufid`(`ufid`),
	KEY `ufii_i_culture`(`culture`),
	CONSTRAINT `ufii_fk_ufid`
		FOREIGN KEY (`ufid`)
		REFERENCES `user_field` (`ufid`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- user_field_option
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `user_field_option`;


CREATE TABLE `user_field_option`
(
	`ufoid` INTEGER(11)  NOT NULL AUTO_INCREMENT,
	`ufid` INTEGER(11)  NOT NULL,
	`value` VARCHAR(255)  NOT NULL,
	`weight` INTEGER(11) default 0 NOT NULL,
	`created_at` DATETIME  NOT NULL,
	`updated_at` DATETIME  NOT NULL,
	PRIMARY KEY (`ufoid`),
	KEY `ufo_i_ufid`(`ufid`),
	KEY `ufo_i_value`(`value`),
	CONSTRAINT `ufo_fk_ufid`
		FOREIGN KEY (`ufid`)
		REFERENCES `user_field` (`ufid`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- user_field_option_i18n
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `user_field_option_i18n`;


CREATE TABLE `user_field_option_i18n`
(
	`ufoid` INTEGER(11)  NOT NULL,
	`culture` VARCHAR(7)  NOT NULL,
	`name` VARCHAR(255)  NOT NULL,
	PRIMARY KEY (`ufoid`,`culture`),
	KEY `ufoi_i_ufoid`(`ufoid`),
	KEY `ufoi_i_culture`(`culture`),
	CONSTRAINT `ufoi_fk_ufoid`
		FOREIGN KEY (`ufoid`)
		REFERENCES `user_field_option` (`ufoid`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- user_field_value
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `user_field_value`;


CREATE TABLE `user_field_value`
(
	`uid` INTEGER(11)  NOT NULL,
	`ufid` INTEGER(11)  NOT NULL,
	`value` TEXT,
	`created_at` DATETIME  NOT NULL,
	`updated_at` DATETIME  NOT NULL,
	PRIMARY KEY (`uid`,`ufid`),
	KEY `ufv_i_ufid`(`ufid`),
	KEY `ufv_i_uid`(`uid`),
	CONSTRAINT `ufv_fk_ufid`
		FOREIGN KEY (`ufid`)
		REFERENCES `user_field` (`ufid`),
	CONSTRAINT `ufv_fk_uid`
		FOREIGN KEY (`uid`)
		REFERENCES `user` (`uid`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- groups
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `groups`;


CREATE TABLE `groups`
(
	`gid` INTEGER(11)  NOT NULL AUTO_INCREMENT,
	`uid` INTEGER(11)  NOT NULL,
	`groupkey` VARCHAR(32)  NOT NULL,
	`hidden` TINYINT(1) default 0 NOT NULL,
	`visibility_in_overview` TINYINT(1) default 1,
	`verify` TINYINT(1) default 0 NOT NULL,
	`status` INTEGER(11) default 0 NOT NULL,
	`featured` TINYINT(1) default 0 NOT NULL,
	`culture` VARCHAR(7)  NOT NULL,
	`title` VARCHAR(255)  NOT NULL,
	`description` TEXT,
	`picture_filename` VARCHAR(255),
	`cover_filename` VARCHAR(255),
	`notify_member` TINYINT(1) default 0 NOT NULL,
	`weight` INTEGER(11) default 0 NOT NULL,
	`last_access_at` DATETIME,
	`count_members` INTEGER(11) default 0 NOT NULL,
	`count_media` INTEGER(11) default 0 NOT NULL,
	`count_media_videos` INTEGER(11) default 0 NOT NULL,
	`count_media_photos` INTEGER(11) default 0 NOT NULL,
	`count_media_audios` INTEGER(11) default 0 NOT NULL,
	`count_media_documents` INTEGER(11) default 0 NOT NULL,
	`count_media_youtube` INTEGER(11) default 0 NOT NULL,
	`count_media_vimeo` INTEGER(11) default 0 NOT NULL,
	`created_at` DATETIME  NOT NULL,
	`updated_at` DATETIME  NOT NULL,
	PRIMARY KEY (`gid`),
	KEY `g_i_uid`(`uid`),
	KEY `g_i_culture`(`culture`),
	CONSTRAINT `g_fk_uid`
		FOREIGN KEY (`uid`)
		REFERENCES `user` (`uid`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- groups_member
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `groups_member`;


CREATE TABLE `groups_member`
(
	`gid` INTEGER(11)  NOT NULL,
	`uid` INTEGER(11)  NOT NULL,
	`status` INTEGER(11) default 0 NOT NULL,
	`created_at` DATETIME  NOT NULL,
	`updated_at` DATETIME  NOT NULL,
	PRIMARY KEY (`gid`,`uid`),
	KEY `gm_i_gid`(`gid`),
	KEY `gm_i_uid`(`uid`),
	CONSTRAINT `gm_fk_gid`
		FOREIGN KEY (`gid`)
		REFERENCES `groups` (`gid`),
	CONSTRAINT `gm_fk_uid`
		FOREIGN KEY (`uid`)
		REFERENCES `user` (`uid`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- groups_media
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `groups_media`;


CREATE TABLE `groups_media`
(
	`gid` INTEGER(11)  NOT NULL,
	`mid` INTEGER(11)  NOT NULL,
	`created_at` DATETIME  NOT NULL,
	`updated_at` DATETIME  NOT NULL,
	PRIMARY KEY (`gid`,`mid`),
	KEY `gme_i_gid`(`gid`),
	KEY `gme_i_mid`(`mid`),
	CONSTRAINT `gme_fk_gid`
		FOREIGN KEY (`gid`)
		REFERENCES `groups` (`gid`),
	CONSTRAINT `gme_fk_mid`
		FOREIGN KEY (`mid`)
		REFERENCES `media` (`mid`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- groups_forum
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `groups_forum`;


CREATE TABLE `groups_forum`
(
	`gid` INTEGER(11)  NOT NULL,
	`forumid` INTEGER(11)  NOT NULL,
	`created_at` DATETIME  NOT NULL,
	`updated_at` DATETIME  NOT NULL,
	PRIMARY KEY (`gid`,`forumid`),
	KEY `gf_i_gid`(`gid`),
	KEY `gf_i_forumid`(`forumid`),
	CONSTRAINT `gf_fk_gid`
		FOREIGN KEY (`gid`)
		REFERENCES `groups` (`gid`),
	CONSTRAINT `gf_fk_forumid`
		FOREIGN KEY (`forumid`)
		REFERENCES `forum` (`forumid`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- groups_view
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `groups_view`;


CREATE TABLE `groups_view`
(
	`gvid` INTEGER(11)  NOT NULL AUTO_INCREMENT,
	`gid` INTEGER(11)  NOT NULL,
	`uid` INTEGER(11)  NOT NULL,
	`sessid` VARCHAR(128)  NOT NULL,
	`hostname` VARCHAR(244)  NOT NULL,
	`external` TINYINT(1) default 0 NOT NULL,
	`external_url` VARCHAR(1024),
	`created_at` DATETIME  NOT NULL,
	PRIMARY KEY (`gvid`),
	KEY `gv_i_gid`(`gid`),
	KEY `gv_i_uid`(`uid`),
	CONSTRAINT `gv_fk_gid`
		FOREIGN KEY (`gid`)
		REFERENCES `groups` (`gid`),
	CONSTRAINT `gv_fk_uid`
		FOREIGN KEY (`uid`)
		REFERENCES `user` (`uid`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- playlist
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `playlist`;


CREATE TABLE `playlist`
(
	`pid` INTEGER(11)  NOT NULL AUTO_INCREMENT,
	`uid` INTEGER(11)  NOT NULL,
	`title` VARCHAR(255)  NOT NULL,
	`description` TEXT,
	`created_at` DATETIME  NOT NULL,
	`updated_at` DATETIME  NOT NULL,
	PRIMARY KEY (`pid`),
	INDEX `FI_k_uid` (`uid`),
	CONSTRAINT `p_fk_uid`
		FOREIGN KEY (`uid`)
		REFERENCES `user` (`uid`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- playlist_media
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `playlist_media`;


CREATE TABLE `playlist_media`
(
	`pid` INTEGER(11)  NOT NULL,
	`mid` INTEGER(11)  NOT NULL,
	`weight` INTEGER(11) default 0 NOT NULL,
	`created_at` DATETIME  NOT NULL,
	`updated_at` DATETIME  NOT NULL,
	PRIMARY KEY (`pid`,`mid`),
	KEY `pm_i_pid`(`pid`),
	KEY `pm_i_mid`(`mid`),
	CONSTRAINT `pm_fk_pid`
		FOREIGN KEY (`pid`)
		REFERENCES `playlist` (`pid`),
	CONSTRAINT `pm_fk_mid`
		FOREIGN KEY (`mid`)
		REFERENCES `media` (`mid`)
)Engine=InnoDB;

# This restores the fkey checks, after having unset them earlier
SET FOREIGN_KEY_CHECKS = 1;
