CREATE TABLE `global_tags` (
  `id` int(12) NOT NULL AUTO_INCREMENT,
  `entity_id` int(12) NOT NULL,
  `tag_id` int(12) NOT NULL,
  `tag_group_id` int(12) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `entity_id` (`entity_id`),
  KEY `tag_id` (`tag_id`),
  KEY `tag_group_id` (`tag_group_id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COMMENT='Таблица тэгов';

REPLACE INTO `_sys_datatypes` 
                        (`obj_name`,`attr_name`,`attr_type`,`attr_templ`,`attr_desc`,`attr_hide`,`attr_mand`,`attr_order`)
                        VALUES
                        ('global_tags','entity_id','int12','[title]','ID сущности','0','0','100');
REPLACE INTO `_sys_datatypes` 
                        (`obj_name`,`attr_name`,`attr_type`,`attr_templ`,`attr_desc`,`attr_hide`,`attr_mand`,`attr_order`)
                        VALUES
                        (
                        'global_tags','tag_group_id','LINK|global_tags_groups','[title]','Группа тэга','0','0','100');
REPLACE INTO `_sys_datatypes` 
                        (`obj_name`,`attr_name`,`attr_type`,`attr_templ`,`attr_desc`,`attr_hide`,`attr_mand`,`attr_order`)
                        VALUES
                        (
                        'global_tags',
                        'tag_id',
                        'LINK|global_tags_titles',
                        '[title]',
                        'Тэг',
                        '0',
                        '0',
                        '100')
                    ;
CREATE TABLE `global_tags_groups` (
  `id` int(12) NOT NULL AUTO_INCREMENT,
  `title` varchar(255) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
REPLACE INTO `_sys_datatypes` 
                        (`obj_name`,`attr_name`,`attr_type`,`attr_templ`,`attr_desc`,`attr_hide`,`attr_mand`,`attr_order`)
                        VALUES
                        (
                        'global_tags_groups',
                        'title',
                        'input',
                        '',
                        'Название группы',
                        '0',
                        '0',
                        '100')
                    ;
CREATE TABLE `global_tags_titles` (
  `id` int(12) NOT NULL AUTO_INCREMENT,
  `title` varchar(255) NOT NULL,
  `tag_group_id` int(12) NOT NULL,
  `url_part` varchar(255) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `tag_group_id` (`tag_group_id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
REPLACE INTO `_sys_datatypes` 
                        (`obj_name`,`attr_name`,`attr_type`,`attr_templ`,`attr_desc`,`attr_hide`,`attr_mand`,`attr_order`)
                        VALUES
                        (
                        'global_tags_titles',
                        'tag_group_id',
                        'LINK|global_tags_groups',
                        '[title]',
                        'Группа тэга',
                        '0',
                        '0',
                        '999')
                    ;
REPLACE INTO `_sys_datatypes` 
                        (`obj_name`,`attr_name`,`attr_type`,`attr_templ`,`attr_desc`,`attr_hide`,`attr_mand`,`attr_order`)
                        VALUES
                        (
                        'global_tags_titles',
                        'title',
                        'input',
                        '',
                        'Тэг',
                        '0',
                        '0',
                        '100')
                    ;
REPLACE INTO `_sys_datatypes` 
                        (`obj_name`,`attr_name`,`attr_type`,`attr_templ`,`attr_desc`,`attr_hide`,`attr_mand`,`attr_order`)
                        VALUES
                        (
                        'global_tags_titles',
                        'url_part',
                        'input',
                        '',
                        'Часть URL',
                        '0',
                        '0',
                        '200');
