-- =============================================
-- CATEGORYS - Sistema de Categorías
-- =============================================
-- Tabla principal de categorías del sistema
-- Soporta jerarquía mediante cat_parent_id
-- =============================================

DROP TABLE IF EXISTS `categorys`;

CREATE TABLE `categorys` (
  `cat_id` int NOT NULL AUTO_INCREMENT,
  `cat_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `cat_path` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `cat_pathurl` varchar(1000) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `cat_description` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci,
  `cat_order` int DEFAULT NULL,
  `cat_parent_id` int DEFAULT '0',
  `cat_related` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `cat_icon` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `cat_color` varchar(11) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `cat_img` int DEFAULT NULL,
  `cat_banner` int DEFAULT NULL,
  `cat_ent_id` int DEFAULT NULL,
  `cat_configpath` varchar(400) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `cat_cls` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `cat_json` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci,
  `cat_state_collapse` int NOT NULL DEFAULT '1',
  `cat_site_id` int NOT NULL DEFAULT 1,
  `cat_state` int NOT NULL DEFAULT '0',
  PRIMARY KEY (`cat_id`) USING BTREE,
  KEY `idx_parent_id` (`cat_parent_id`) USING BTREE,
  KEY `idx_ent_id` (`cat_ent_id`) USING BTREE,
  KEY `idx_state` (`cat_state`) USING BTREE,
  KEY `idx_path` (`cat_path`) USING BTREE,
  KEY `idx_parent_ent_state` (`cat_parent_id`, `cat_ent_id`, `cat_state`) USING BTREE
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci AUTO_INCREMENT=1;


-- =============================================
-- CATEGORYS_FILES - Relación Categorías-Archivos
-- =============================================
-- Tabla de relación muchos a muchos entre categorías y archivos
-- =============================================

DROP TABLE IF EXISTS `categorys_files`;

CREATE TABLE `categorys_files` (
  `cat_file_file_id` int NOT NULL,
  `cat_file_cat_id` int NOT NULL,
  `cat_file_order` int NOT NULL DEFAULT '0',
  `cat_file_site_id` int NOT NULL DEFAULT 1,
  PRIMARY KEY (`cat_file_file_id`,`cat_file_cat_id`) USING BTREE,
  KEY `idx_cat_id` (`cat_file_cat_id`) USING BTREE,
  KEY `idx_cat_order` (`cat_file_cat_id`, `cat_file_order`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;


-- =============================================
-- CONTENTS_CATEGORYS - Relación Contenidos-Categorías
-- =============================================

DROP TABLE IF EXISTS `contents_categorys`;

CREATE TABLE `contents_categorys` (
  `cont_cat_cont_id` int NOT NULL,
  `cont_cat_cat_id` int NOT NULL,
  `cont_cat_ent_id` int DEFAULT NULL,
  `cont_cat_order` int NOT NULL DEFAULT '0',
  `cont_cat_site_id` int NOT NULL DEFAULT 1,
  PRIMARY KEY (`cont_cat_cont_id`,`cont_cat_cat_id`) USING BTREE,
  KEY `idx_cat_id` (`cont_cat_cat_id`) USING BTREE,
  KEY `idx_ent_id` (`cont_cat_ent_id`) USING BTREE,
  KEY `idx_cat_order` (`cont_cat_cat_id`, `cont_cat_order`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;


-- =============================================
-- DOCS_CATEGORYS - Relación Documentos-Categorías
-- =============================================

DROP TABLE IF EXISTS `docs_categorys`;

CREATE TABLE `docs_categorys` (
  `doc_cat_doc_id` int NOT NULL,
  `doc_cat_cat_id` int NOT NULL,
  `doc_cat_order` int NOT NULL DEFAULT '0',
  `doc_cat_ent_id` int NOT NULL,
  `doc_cat_site_id` int NOT NULL DEFAULT 1,
  PRIMARY KEY (`doc_cat_doc_id`,`doc_cat_cat_id`) USING BTREE,
  KEY `idx_cat_id` (`doc_cat_cat_id`) USING BTREE,
  KEY `idx_ent_id` (`doc_cat_ent_id`) USING BTREE,
  KEY `idx_cat_order` (`doc_cat_cat_id`, `doc_cat_order`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;


-- =============================================
-- LINKS_CATEGORYS - Relación Enlaces-Categorías
-- =============================================

DROP TABLE IF EXISTS `links_categorys`;

CREATE TABLE `links_categorys` (
  `lnk_cat_cat_id` int NOT NULL,
  `lnk_cat_lnk_id` int NOT NULL,
  `lnk_cat_order` int NOT NULL DEFAULT '0',
  `lnk_cat_site_id` int NOT NULL DEFAULT 1,
  PRIMARY KEY (`lnk_cat_cat_id`,`lnk_cat_lnk_id`) USING BTREE,
  KEY `idx_lnk_id` (`lnk_cat_lnk_id`) USING BTREE,
  KEY `idx_cat_order` (`lnk_cat_cat_id`, `lnk_cat_order`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;


-- =============================================
-- MEDIA_CATEGORYS - Relación Media-Categorías
-- =============================================

DROP TABLE IF EXISTS `media_categorys`;

CREATE TABLE `media_categorys` (
  `media_cat_file_id` int NOT NULL,
  `media_cat_cat_id` int NOT NULL,
  `media_cat_order` int NOT NULL DEFAULT '0',
  `media_cat_ent_id` int NOT NULL,
  `media_cat_site_id` int NOT NULL DEFAULT 1,
  PRIMARY KEY (`media_cat_file_id`,`media_cat_cat_id`) USING BTREE,
  KEY `idx_cat_id` (`media_cat_cat_id`) USING BTREE,
  KEY `idx_ent_id` (`media_cat_ent_id`) USING BTREE,
  KEY `idx_cat_order` (`media_cat_cat_id`, `media_cat_order`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;


-- =============================================
-- MODULES_CATEGORYS - Relación Módulos-Categorías
-- =============================================

DROP TABLE IF EXISTS `modules_categorys`;

CREATE TABLE `modules_categorys` (
  `mod_cat_mod_id` int NOT NULL,
  `mod_cat_cat_id` int NOT NULL,
  `mod_cat_ent_id` int NOT NULL,
  `mod_cat_order` int NOT NULL DEFAULT '0',
  `mod_cat_site_id` int NOT NULL DEFAULT 1,
  PRIMARY KEY (`mod_cat_mod_id`,`mod_cat_cat_id`,`mod_cat_ent_id`) USING BTREE,
  KEY `idx_cat_id` (`mod_cat_cat_id`) USING BTREE,
  KEY `idx_ent_id` (`mod_cat_ent_id`) USING BTREE,
  KEY `idx_cat_order` (`mod_cat_cat_id`, `mod_cat_order`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;


-- =============================================
-- POSTS_CATEGORYS - Relación Posts-Categorías
-- =============================================

DROP TABLE IF EXISTS `posts_categorys`;

CREATE TABLE `posts_categorys` (
  `post_cat_post_id` int NOT NULL,
  `post_cat_cat_id` int NOT NULL,
  `post_cat_ent_id` int DEFAULT NULL,
  `post_cat_order` int NOT NULL DEFAULT '0',
  `post_cat_site_id` int NOT NULL DEFAULT 1,
  PRIMARY KEY (`post_cat_post_id`,`post_cat_cat_id`) USING BTREE,
  KEY `idx_cat_id` (`post_cat_cat_id`) USING BTREE,
  KEY `idx_ent_id` (`post_cat_ent_id`) USING BTREE,
  KEY `idx_cat_order` (`post_cat_cat_id`, `post_cat_order`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;


-- =============================================
-- ROLES_CATEGORYS - Relación Roles-Categorías
-- =============================================

DROP TABLE IF EXISTS `roles_categorys`;

CREATE TABLE `roles_categorys` (
  `rol_cat_rol_id` int NOT NULL,
  `rol_cat_cat_id` int NOT NULL,
  `rol_cat_order` int NOT NULL DEFAULT '0',
  `rol_cat_site_id` int NOT NULL DEFAULT 1,
  PRIMARY KEY (`rol_cat_rol_id`,`rol_cat_cat_id`) USING BTREE,
  KEY `idx_cat_id` (`rol_cat_cat_id`) USING BTREE,
  KEY `idx_cat_order` (`rol_cat_cat_id`, `rol_cat_order`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;


-- =============================================
-- MOD_SLIDERS_CATEGORYS - Relación Sliders-Categorías
-- =============================================

DROP TABLE IF EXISTS `mod_sliders_categorys`;

CREATE TABLE `mod_sliders_categorys` (
  `mod_sli_cat_sli_id` int(11) NOT NULL,
  `mod_sli_cat_cat_id` int(11) NOT NULL,
  `mod_sli_cat_order` int(11) NOT NULL DEFAULT '0',
  `mod_sli_cat_site_id` int(11) NOT NULL DEFAULT '1',
  PRIMARY KEY (`mod_sli_cat_sli_id`,`mod_sli_cat_cat_id`) USING BTREE,
  KEY `idx_cat_id` (`mod_sli_cat_cat_id`) USING BTREE,
  KEY `idx_cat_order` (`mod_sli_cat_cat_id`, `mod_sli_cat_order`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

COMMIT;
