-- --------------------------------------------------------
-- Host:                         162.240.96.111
-- Versión del servidor:         8.0.45 - MySQL Community Server - GPL
-- SO del servidor:              Linux
-- HeidiSQL Versión:             12.17.0.7270
-- --------------------------------------------------------

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET NAMES utf8 */;
/*!50503 SET NAMES utf8mb4 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

-- Volcando estructura para tabla wwinfo_newinfogate.ad_campaigns
CREATE TABLE IF NOT EXISTS `ad_campaigns` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `inventory_id` int unsigned NOT NULL,
  `name` varchar(160) COLLATE utf8mb4_unicode_ci NOT NULL,
  `target_url` varchar(500) COLLATE utf8mb4_unicode_ci NOT NULL,
  `image_path` varchar(500) COLLATE utf8mb4_unicode_ci NOT NULL,
  `alt_text` varchar(180) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `start_at` datetime DEFAULT NULL,
  `end_at` datetime DEFAULT NULL,
  `is_active` tinyint(1) NOT NULL DEFAULT '1',
  `weight` int NOT NULL DEFAULT '100',
  `created_by` bigint unsigned DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  KEY `idx_ad_c_inv` (`inventory_id`),
  KEY `idx_ad_c_active` (`is_active`,`start_at`,`end_at`),
  KEY `idx_ad_c_weight` (`weight`),
  KEY `fk_ad_c_created_by` (`created_by`),
  CONSTRAINT `fk_ad_c_created_by` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`) ON DELETE SET NULL,
  CONSTRAINT `fk_ad_c_inventory` FOREIGN KEY (`inventory_id`) REFERENCES `ad_inventories` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=21 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- La exportación de datos fue deseleccionada.

-- Volcando estructura para tabla wwinfo_newinfogate.ad_events
CREATE TABLE IF NOT EXISTS `ad_events` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `inventory_id` int unsigned NOT NULL,
  `campaign_id` bigint unsigned DEFAULT NULL,
  `event` enum('impression','click') COLLATE utf8mb4_unicode_ci NOT NULL,
  `visitor_id` char(32) COLLATE utf8mb4_unicode_ci NOT NULL,
  `user_id` bigint unsigned DEFAULT NULL,
  `page_path` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `referer` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `ip` varchar(45) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `ua` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  KEY `idx_ae_campaign` (`campaign_id`,`event`,`created_at`),
  KEY `idx_ae_inventory` (`inventory_id`,`event`,`created_at`),
  KEY `idx_ae_visitor` (`visitor_id`,`event`,`created_at`),
  KEY `idx_ae_event_created` (`event`,`created_at`),
  KEY `idx_ae_user_event_created` (`user_id`,`event`,`created_at`),
  CONSTRAINT `fk_ae_campaign` FOREIGN KEY (`campaign_id`) REFERENCES `ad_campaigns` (`id`) ON DELETE SET NULL,
  CONSTRAINT `fk_ae_inventory` FOREIGN KEY (`inventory_id`) REFERENCES `ad_inventories` (`id`) ON DELETE CASCADE,
  CONSTRAINT `fk_ae_user` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- La exportación de datos fue deseleccionada.

-- Volcando estructura para tabla wwinfo_newinfogate.ad_inventories
CREATE TABLE IF NOT EXISTS `ad_inventories` (
  `id` int unsigned NOT NULL AUTO_INCREMENT,
  `inv_key` varchar(80) COLLATE utf8mb4_unicode_ci NOT NULL,
  `name` varchar(120) COLLATE utf8mb4_unicode_ci NOT NULL,
  `description` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `is_active` tinyint(1) NOT NULL DEFAULT '1',
  `fallback_mode` enum('adsense','none') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'adsense',
  `adsense_client` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `adsense_slot` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `adsense_format` varchar(40) COLLATE utf8mb4_unicode_ci DEFAULT 'auto',
  `adsense_responsive` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_ad_inv_key` (`inv_key`),
  KEY `idx_ad_inv_active` (`is_active`)
) ENGINE=InnoDB AUTO_INCREMENT=16 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- La exportación de datos fue deseleccionada.

-- Volcando estructura para tabla wwinfo_newinfogate.ad_inventory_screenshots
CREATE TABLE IF NOT EXISTS `ad_inventory_screenshots` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `inventory_id` int unsigned NOT NULL,
  `label` varchar(120) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'Ubicación',
  `media_file_id` bigint unsigned NOT NULL,
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  KEY `idx_ad_is_inv` (`inventory_id`),
  KEY `idx_ad_is_mf` (`media_file_id`),
  CONSTRAINT `fk_ad_is_inv` FOREIGN KEY (`inventory_id`) REFERENCES `ad_inventories` (`id`) ON DELETE CASCADE,
  CONSTRAINT `fk_ad_is_mf` FOREIGN KEY (`media_file_id`) REFERENCES `media_files` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- La exportación de datos fue deseleccionada.

-- Volcando estructura para tabla wwinfo_newinfogate.ad_proposal_items
CREATE TABLE IF NOT EXISTS `ad_proposal_items` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `proposal_id` bigint unsigned NOT NULL,
  `inventory_id` int unsigned NOT NULL,
  `availability_json` longtext COLLATE utf8mb4_unicode_ci,
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_ad_pi` (`proposal_id`,`inventory_id`),
  KEY `idx_ad_pi_prop` (`proposal_id`),
  KEY `idx_ad_pi_inv` (`inventory_id`),
  CONSTRAINT `fk_ad_pi_inv` FOREIGN KEY (`inventory_id`) REFERENCES `ad_inventories` (`id`) ON DELETE CASCADE,
  CONSTRAINT `fk_ad_pi_prop` FOREIGN KEY (`proposal_id`) REFERENCES `ad_proposals` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=24 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- La exportación de datos fue deseleccionada.

-- Volcando estructura para tabla wwinfo_newinfogate.ad_proposal_recipients
CREATE TABLE IF NOT EXISTS `ad_proposal_recipients` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `proposal_id` bigint unsigned NOT NULL,
  `email` varchar(180) COLLATE utf8mb4_unicode_ci NOT NULL,
  `name` varchar(160) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_ad_pr` (`proposal_id`,`email`),
  KEY `idx_ad_pr_prop` (`proposal_id`),
  CONSTRAINT `fk_ad_pr_prop` FOREIGN KEY (`proposal_id`) REFERENCES `ad_proposals` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- La exportación de datos fue deseleccionada.

-- Volcando estructura para tabla wwinfo_newinfogate.ad_proposals
CREATE TABLE IF NOT EXISTS `ad_proposals` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `client_name` varchar(160) COLLATE utf8mb4_unicode_ci NOT NULL,
  `company_name` varchar(200) COLLATE utf8mb4_unicode_ci NOT NULL,
  `company_rut` varchar(30) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `company_address` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `company_city` varchar(120) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `company_country` varchar(80) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `contact_phone` varchar(80) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `contact_email` varchar(180) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `request_start_at` datetime NOT NULL,
  `request_end_at` datetime NOT NULL,
  `template_html_snapshot` longtext COLLATE utf8mb4_unicode_ci,
  `created_by` bigint unsigned DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  KEY `idx_ad_p_dates` (`request_start_at`,`request_end_at`),
  KEY `fk_ad_p_created_by` (`created_by`),
  CONSTRAINT `fk_ad_p_created_by` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- La exportación de datos fue deseleccionada.

-- Volcando estructura para tabla wwinfo_newinfogate.categories
CREATE TABLE IF NOT EXISTS `categories` (
  `id` int unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(120) COLLATE utf8mb4_unicode_ci NOT NULL,
  `slug` varchar(120) COLLATE utf8mb4_unicode_ci NOT NULL,
  `parent_id` int unsigned DEFAULT NULL,
  `sort_order` int NOT NULL DEFAULT '0',
  `is_active` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_cat_slug` (`slug`),
  UNIQUE KEY `uk_cat_name` (`name`),
  KEY `idx_cat_parent` (`parent_id`),
  CONSTRAINT `fk_cat_parent` FOREIGN KEY (`parent_id`) REFERENCES `categories` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB AUTO_INCREMENT=150 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- La exportación de datos fue deseleccionada.

-- Volcando estructura para tabla wwinfo_newinfogate.divisas
CREATE TABLE IF NOT EXISTS `divisas` (
  `code` varchar(10) COLLATE utf8mb4_general_ci NOT NULL,
  `name` varchar(80) COLLATE utf8mb4_general_ci NOT NULL,
  `series_id` varchar(60) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `rate_date` date DEFAULT NULL,
  `value_decimal` decimal(18,6) DEFAULT NULL,
  `value_raw` varchar(40) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `source` varchar(120) COLLATE utf8mb4_general_ci NOT NULL DEFAULT 'Banco Central de Chile (API BDE)',
  `status` enum('ok','error') COLLATE utf8mb4_general_ci NOT NULL DEFAULT 'ok',
  `error_msg` varchar(255) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`code`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- La exportación de datos fue deseleccionada.

-- Volcando estructura para tabla wwinfo_newinfogate.group_permissions
CREATE TABLE IF NOT EXISTS `group_permissions` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `group_id` int unsigned NOT NULL,
  `permission_id` int unsigned NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_group_perm` (`group_id`,`permission_id`),
  KEY `fk_gp_perm` (`permission_id`),
  CONSTRAINT `fk_gp_group` FOREIGN KEY (`group_id`) REFERENCES `user_groups` (`id`) ON DELETE CASCADE,
  CONSTRAINT `fk_gp_perm` FOREIGN KEY (`permission_id`) REFERENCES `permissions` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=29 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- La exportación de datos fue deseleccionada.

-- Volcando estructura para tabla wwinfo_newinfogate.media
CREATE TABLE IF NOT EXISTS `media` (
  `id` int NOT NULL AUTO_INCREMENT,
  `type` enum('image','video','file') COLLATE utf8mb4_general_ci NOT NULL DEFAULT 'image',
  `file_path` varchar(255) COLLATE utf8mb4_general_ci NOT NULL,
  `thumb_path` varchar(255) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `original_name` varchar(255) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `mime_type` varchar(120) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `file_size_bytes` bigint unsigned DEFAULT NULL,
  `width` int unsigned DEFAULT NULL,
  `height` int unsigned DEFAULT NULL,
  `title` varchar(180) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `alt_text` varchar(180) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `caption` varchar(255) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `uploaded_by` int DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  KEY `created_at` (`created_at`),
  KEY `idx_media_type_created` (`type`,`created_at`),
  KEY `idx_media_uploaded_by` (`uploaded_by`)
) ENGINE=InnoDB AUTO_INCREMENT=85477 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- La exportación de datos fue deseleccionada.

-- Volcando estructura para tabla wwinfo_newinfogate.media_categories
CREATE TABLE IF NOT EXISTS `media_categories` (
  `media_id` int NOT NULL,
  `category_id` int unsigned NOT NULL,
  PRIMARY KEY (`media_id`,`category_id`),
  KEY `idx_mc_cat` (`category_id`),
  CONSTRAINT `fk_mc_cat` FOREIGN KEY (`category_id`) REFERENCES `categories` (`id`) ON DELETE CASCADE,
  CONSTRAINT `fk_mc_media` FOREIGN KEY (`media_id`) REFERENCES `media` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- La exportación de datos fue deseleccionada.

-- Volcando estructura para tabla wwinfo_newinfogate.media_files
CREATE TABLE IF NOT EXISTS `media_files` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `uploader_user_id` bigint unsigned DEFAULT NULL,
  `kind` enum('image','file','video_thumb') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'image',
  `original_name` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `stored_path` varchar(500) COLLATE utf8mb4_unicode_ci NOT NULL,
  `mime_type` varchar(120) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `file_size_bytes` bigint unsigned DEFAULT NULL,
  `width` int unsigned DEFAULT NULL,
  `height` int unsigned DEFAULT NULL,
  `alt_text` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `caption` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  KEY `idx_media_uploader` (`uploader_user_id`),
  KEY `idx_media_kind` (`kind`),
  CONSTRAINT `fk_media_uploader` FOREIGN KEY (`uploader_user_id`) REFERENCES `users` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB AUTO_INCREMENT=525 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- La exportación de datos fue deseleccionada.

-- Volcando estructura para tabla wwinfo_newinfogate.media_tags
CREATE TABLE IF NOT EXISTS `media_tags` (
  `media_id` int NOT NULL,
  `tag_id` bigint unsigned NOT NULL,
  PRIMARY KEY (`media_id`,`tag_id`),
  KEY `idx_mt_tag` (`tag_id`),
  CONSTRAINT `fk_mt_media` FOREIGN KEY (`media_id`) REFERENCES `media` (`id`) ON DELETE CASCADE,
  CONSTRAINT `fk_mt_tag` FOREIGN KEY (`tag_id`) REFERENCES `tags` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- La exportación de datos fue deseleccionada.

-- Volcando estructura para tabla wwinfo_newinfogate.news_publishers
CREATE TABLE IF NOT EXISTS `news_publishers` (
  `id` int unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(160) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `slug` varchar(180) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `is_active` tinyint(1) NOT NULL DEFAULT '1',
  `created_by` bigint unsigned DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_news_publishers_name` (`name`),
  UNIQUE KEY `uk_news_publishers_slug` (`slug`),
  KEY `idx_news_publishers_active` (`is_active`),
  KEY `fk_news_publishers_created_by` (`created_by`),
  CONSTRAINT `fk_news_publishers_created_by` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- La exportación de datos fue deseleccionada.

-- Volcando estructura para tabla wwinfo_newinfogate.opinion_authors
CREATE TABLE IF NOT EXISTS `opinion_authors` (
  `opinion_id` int NOT NULL,
  `user_id` bigint unsigned NOT NULL,
  PRIMARY KEY (`opinion_id`,`user_id`),
  KEY `idx_oa_user` (`user_id`),
  CONSTRAINT `fk_oa_op` FOREIGN KEY (`opinion_id`) REFERENCES `opinions` (`id`) ON DELETE CASCADE,
  CONSTRAINT `fk_oa_user` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- La exportación de datos fue deseleccionada.

-- Volcando estructura para tabla wwinfo_newinfogate.opinion_categories
CREATE TABLE IF NOT EXISTS `opinion_categories` (
  `opinion_id` int NOT NULL,
  `category_id` int unsigned NOT NULL,
  PRIMARY KEY (`opinion_id`,`category_id`),
  KEY `idx_oc_cat` (`category_id`),
  CONSTRAINT `fk_oc_cat` FOREIGN KEY (`category_id`) REFERENCES `categories` (`id`) ON DELETE CASCADE,
  CONSTRAINT `fk_oc_op` FOREIGN KEY (`opinion_id`) REFERENCES `opinions` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- La exportación de datos fue deseleccionada.

-- Volcando estructura para tabla wwinfo_newinfogate.opinion_tags
CREATE TABLE IF NOT EXISTS `opinion_tags` (
  `opinion_id` int NOT NULL,
  `tag_id` bigint unsigned NOT NULL,
  PRIMARY KEY (`opinion_id`,`tag_id`),
  KEY `idx_ot_tag` (`tag_id`),
  CONSTRAINT `fk_ot_op` FOREIGN KEY (`opinion_id`) REFERENCES `opinions` (`id`) ON DELETE CASCADE,
  CONSTRAINT `fk_ot_tag` FOREIGN KEY (`tag_id`) REFERENCES `tags` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- La exportación de datos fue deseleccionada.

-- Volcando estructura para tabla wwinfo_newinfogate.opinions
CREATE TABLE IF NOT EXISTS `opinions` (
  `id` int NOT NULL AUTO_INCREMENT,
  `title` varchar(240) COLLATE utf8mb4_general_ci NOT NULL,
  `slug` varchar(260) COLLATE utf8mb4_general_ci NOT NULL,
  `excerpt` text COLLATE utf8mb4_general_ci,
  `content_html` mediumtext COLLATE utf8mb4_general_ci NOT NULL,
  `status` enum('draft','published','scheduled') COLLATE utf8mb4_general_ci NOT NULL DEFAULT 'draft',
  `publish_at` datetime DEFAULT NULL,
  `featured_media_id` int DEFAULT NULL,
  `created_by` int DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_op_slug` (`slug`),
  KEY `idx_op_status` (`status`),
  KEY `idx_op_publish` (`publish_at`),
  KEY `idx_op_featured` (`featured_media_id`),
  CONSTRAINT `fk_op_featured_media` FOREIGN KEY (`featured_media_id`) REFERENCES `media` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- La exportación de datos fue deseleccionada.

-- Volcando estructura para tabla wwinfo_newinfogate.permissions
CREATE TABLE IF NOT EXISTS `permissions` (
  `id` int unsigned NOT NULL AUTO_INCREMENT,
  `perm_key` varchar(120) COLLATE utf8mb4_unicode_ci NOT NULL,
  `description` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_perm_key` (`perm_key`)
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- La exportación de datos fue deseleccionada.

-- Volcando estructura para tabla wwinfo_newinfogate.post_categories
CREATE TABLE IF NOT EXISTS `post_categories` (
  `post_id` int NOT NULL,
  `category_id` int unsigned NOT NULL,
  PRIMARY KEY (`post_id`,`category_id`),
  KEY `idx_pc_category` (`category_id`),
  CONSTRAINT `fk_pc_cat` FOREIGN KEY (`category_id`) REFERENCES `categories` (`id`) ON DELETE CASCADE,
  CONSTRAINT `fk_pc_post` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- La exportación de datos fue deseleccionada.

-- Volcando estructura para tabla wwinfo_newinfogate.post_gallery
CREATE TABLE IF NOT EXISTS `post_gallery` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `post_id` int NOT NULL,
  `media_id` int NOT NULL,
  `sort_order` int NOT NULL DEFAULT '1',
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_post_gallery` (`post_id`,`media_id`),
  KEY `idx_post_gallery_post_sort` (`post_id`,`sort_order`,`id`),
  KEY `idx_post_gallery_media` (`media_id`),
  CONSTRAINT `fk_post_gallery_media` FOREIGN KEY (`media_id`) REFERENCES `media` (`id`) ON DELETE CASCADE,
  CONSTRAINT `fk_post_gallery_post` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=227 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- La exportación de datos fue deseleccionada.

-- Volcando estructura para tabla wwinfo_newinfogate.post_related
CREATE TABLE IF NOT EXISTS `post_related` (
  `post_id` int NOT NULL,
  `related_post_id` int NOT NULL,
  `created_by` bigint unsigned DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`post_id`,`related_post_id`),
  KEY `idx_pr_related` (`related_post_id`),
  KEY `idx_pr_created_by` (`created_by`),
  CONSTRAINT `fk_pr_created_by` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`) ON DELETE SET NULL,
  CONSTRAINT `fk_pr_post` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`) ON DELETE CASCADE,
  CONSTRAINT `fk_pr_related_post` FOREIGN KEY (`related_post_id`) REFERENCES `posts` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- La exportación de datos fue deseleccionada.

-- Volcando estructura para tabla wwinfo_newinfogate.post_tags
CREATE TABLE IF NOT EXISTS `post_tags` (
  `post_id` int NOT NULL,
  `tag_id` bigint unsigned NOT NULL,
  PRIMARY KEY (`post_id`,`tag_id`),
  KEY `idx_pt_tag` (`tag_id`),
  CONSTRAINT `fk_pt_post` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`) ON DELETE CASCADE,
  CONSTRAINT `fk_pt_tag` FOREIGN KEY (`tag_id`) REFERENCES `tags` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- La exportación de datos fue deseleccionada.

-- Volcando estructura para tabla wwinfo_newinfogate.posts
CREATE TABLE IF NOT EXISTS `posts` (
  `id` int NOT NULL AUTO_INCREMENT,
  `title` varchar(240) COLLATE utf8mb4_general_ci NOT NULL,
  `slug` varchar(260) COLLATE utf8mb4_general_ci NOT NULL,
  `excerpt` text COLLATE utf8mb4_general_ci,
  `content_html` mediumtext COLLATE utf8mb4_general_ci NOT NULL,
  `status` enum('draft','published','scheduled') COLLATE utf8mb4_general_ci NOT NULL DEFAULT 'draft',
  `publish_at` datetime DEFAULT NULL,
  `author_id` int DEFAULT NULL,
  `publisher_id` int unsigned DEFAULT NULL,
  `meta_title` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `meta_description` varchar(320) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `featured_media_id` int DEFAULT NULL,
  `is_featured` tinyint(1) NOT NULL DEFAULT '0',
  `featured_until` datetime DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `slug` (`slug`),
  KEY `status` (`status`),
  KEY `publish_at` (`publish_at`),
  KEY `fk_posts_featured_media` (`featured_media_id`),
  KEY `idx_posts_featured` (`is_featured`,`featured_until`),
  KEY `idx_posts_status_publish_at` (`status`,`publish_at`),
  KEY `idx_posts_publisher_id` (`publisher_id`),
  CONSTRAINT `fk_posts_featured_media` FOREIGN KEY (`featured_media_id`) REFERENCES `media` (`id`) ON DELETE SET NULL,
  CONSTRAINT `fk_posts_publisher_id` FOREIGN KEY (`publisher_id`) REFERENCES `news_publishers` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB AUTO_INCREMENT=95755 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- La exportación de datos fue deseleccionada.

-- Volcando estructura para tabla wwinfo_newinfogate.site_options
CREATE TABLE IF NOT EXISTS `site_options` (
  `opt_key` varchar(120) COLLATE utf8mb4_unicode_ci NOT NULL,
  `opt_value` longtext COLLATE utf8mb4_unicode_ci,
  `opt_type` enum('string','bool','json') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'string',
  `updated_by` bigint unsigned DEFAULT NULL,
  `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`opt_key`),
  KEY `idx_site_options_updated_by` (`updated_by`),
  CONSTRAINT `fk_site_options_updated_by` FOREIGN KEY (`updated_by`) REFERENCES `users` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- La exportación de datos fue deseleccionada.

-- Volcando estructura para tabla wwinfo_newinfogate.static_pages
CREATE TABLE IF NOT EXISTS `static_pages` (
  `id` int NOT NULL AUTO_INCREMENT,
  `title` varchar(220) COLLATE utf8mb4_general_ci NOT NULL,
  `slug` varchar(240) COLLATE utf8mb4_general_ci NOT NULL,
  `content_html` mediumtext COLLATE utf8mb4_general_ci NOT NULL,
  `status` enum('draft','published') COLLATE utf8mb4_general_ci NOT NULL DEFAULT 'published',
  `show_in_header` tinyint(1) NOT NULL DEFAULT '0',
  `featured_media_id` int DEFAULT NULL,
  `created_by` bigint unsigned DEFAULT NULL,
  `updated_by` bigint unsigned DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_static_slug` (`slug`),
  KEY `idx_static_status` (`status`),
  KEY `idx_static_show` (`show_in_header`),
  KEY `idx_static_featured` (`featured_media_id`),
  KEY `fk_static_created_by` (`created_by`),
  KEY `fk_static_updated_by` (`updated_by`),
  CONSTRAINT `fk_static_created_by` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`) ON DELETE SET NULL,
  CONSTRAINT `fk_static_featured_media` FOREIGN KEY (`featured_media_id`) REFERENCES `media` (`id`) ON DELETE SET NULL,
  CONSTRAINT `fk_static_updated_by` FOREIGN KEY (`updated_by`) REFERENCES `users` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- La exportación de datos fue deseleccionada.

-- Volcando estructura para tabla wwinfo_newinfogate.stats_pageviews
CREATE TABLE IF NOT EXISTS `stats_pageviews` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `visitor_id` char(32) COLLATE utf8mb4_unicode_ci NOT NULL,
  `page_type` varchar(40) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'page',
  `entity_type` varchar(40) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `entity_id` varchar(64) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `page_key` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL,
  `page_path` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `page_title` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `referer_host` varchar(120) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `referer_url` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `utm_source` varchar(120) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `utm_medium` varchar(120) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `utm_campaign` varchar(120) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `device_type` varchar(20) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `lang` varchar(20) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `viewed_at` datetime NOT NULL,
  `viewed_date` date NOT NULL,
  PRIMARY KEY (`id`),
  KEY `idx_spv_viewed_at` (`viewed_at`),
  KEY `idx_spv_visitor_viewed` (`visitor_id`,`viewed_at`),
  KEY `idx_spv_page_key` (`page_key`,`viewed_at`),
  KEY `idx_spv_page_type` (`page_type`,`viewed_at`),
  KEY `idx_spv_referrer` (`referer_host`,`viewed_at`),
  KEY `idx_spv_device` (`device_type`,`viewed_at`),
  KEY `idx_spv_date` (`viewed_date`),
  CONSTRAINT `fk_spv_visitor` FOREIGN KEY (`visitor_id`) REFERENCES `stats_visitors` (`visitor_id`) ON DELETE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=31505 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- La exportación de datos fue deseleccionada.

-- Volcando estructura para tabla wwinfo_newinfogate.stats_visitors
CREATE TABLE IF NOT EXISTS `stats_visitors` (
  `visitor_id` char(32) COLLATE utf8mb4_unicode_ci NOT NULL,
  `first_seen_at` datetime NOT NULL,
  `last_seen_at` datetime NOT NULL,
  `first_landing_path` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `first_referrer` varchar(120) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `device_type` varchar(20) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `lang` varchar(20) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  PRIMARY KEY (`visitor_id`),
  KEY `idx_sv_last_seen` (`last_seen_at`),
  KEY `idx_sv_device` (`device_type`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- La exportación de datos fue deseleccionada.

-- Volcando estructura para tabla wwinfo_newinfogate.tags
CREATE TABLE IF NOT EXISTS `tags` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(120) COLLATE utf8mb4_unicode_ci NOT NULL,
  `slug` varchar(120) COLLATE utf8mb4_unicode_ci NOT NULL,
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_tag_slug` (`slug`),
  UNIQUE KEY `uk_tag_name` (`name`)
) ENGINE=InnoDB AUTO_INCREMENT=70990 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- La exportación de datos fue deseleccionada.

-- Volcando estructura para tabla wwinfo_newinfogate.user_group_members
CREATE TABLE IF NOT EXISTS `user_group_members` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `user_id` bigint unsigned NOT NULL,
  `group_id` int unsigned NOT NULL,
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_user_group` (`user_id`,`group_id`),
  KEY `idx_ugm_group` (`group_id`),
  CONSTRAINT `fk_ugm_group` FOREIGN KEY (`group_id`) REFERENCES `user_groups` (`id`) ON DELETE CASCADE,
  CONSTRAINT `fk_ugm_user` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- La exportación de datos fue deseleccionada.

-- Volcando estructura para tabla wwinfo_newinfogate.user_groups
CREATE TABLE IF NOT EXISTS `user_groups` (
  `id` int unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(80) COLLATE utf8mb4_unicode_ci NOT NULL,
  `slug` varchar(80) COLLATE utf8mb4_unicode_ci NOT NULL,
  `description` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_user_groups_slug` (`slug`),
  UNIQUE KEY `uk_user_groups_name` (`name`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- La exportación de datos fue deseleccionada.

-- Volcando estructura para tabla wwinfo_newinfogate.users
CREATE TABLE IF NOT EXISTS `users` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `full_name` varchar(150) COLLATE utf8mb4_unicode_ci NOT NULL,
  `username` varchar(60) COLLATE utf8mb4_unicode_ci NOT NULL,
  `alias` varchar(80) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `email_corporate` varchar(180) COLLATE utf8mb4_unicode_ci NOT NULL,
  `email_personal` varchar(180) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `password_hash` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `is_active` tinyint(1) NOT NULL DEFAULT '1',
  `profile_photo_media_id` bigint unsigned DEFAULT NULL,
  `bio_html` longtext COLLATE utf8mb4_unicode_ci,
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `last_login_at` datetime DEFAULT NULL,
  `last_login_ip` varchar(45) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_users_username` (`username`),
  UNIQUE KEY `uk_users_email_corp` (`email_corporate`),
  UNIQUE KEY `uk_users_email_personal` (`email_personal`),
  KEY `idx_users_active` (`is_active`),
  KEY `fk_users_profile_photo` (`profile_photo_media_id`),
  CONSTRAINT `fk_users_profile_photo` FOREIGN KEY (`profile_photo_media_id`) REFERENCES `media_files` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB AUTO_INCREMENT=66 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- La exportación de datos fue deseleccionada.

-- Volcando estructura para tabla wwinfo_newinfogate.yt_videos
CREATE TABLE IF NOT EXISTS `yt_videos` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `video_id` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL,
  `channel_id` varchar(40) COLLATE utf8mb4_unicode_ci NOT NULL,
  `channel_title` varchar(200) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `title` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `description` mediumtext COLLATE utf8mb4_unicode_ci,
  `published_at` datetime DEFAULT NULL,
  `duration_seconds` int unsigned DEFAULT NULL,
  `view_count` bigint unsigned DEFAULT NULL,
  `like_count` bigint unsigned DEFAULT NULL,
  `comment_count` bigint unsigned DEFAULT NULL,
  `thumb_url` varchar(500) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `thumb_path` varchar(500) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `thumb_media_file_id` bigint unsigned DEFAULT NULL,
  `privacy_status` varchar(30) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `embeddable` tinyint(1) DEFAULT NULL,
  `made_for_kids` tinyint(1) DEFAULT NULL,
  `etag` varchar(80) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `fetched_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `last_seen_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `is_active` tinyint(1) NOT NULL DEFAULT '1',
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_yt_video_id` (`video_id`),
  KEY `idx_yt_published` (`published_at`),
  KEY `idx_yt_active_published` (`is_active`,`published_at`),
  KEY `fk_yt_thumb_media_file` (`thumb_media_file_id`),
  CONSTRAINT `fk_yt_thumb_media_file` FOREIGN KEY (`thumb_media_file_id`) REFERENCES `media_files` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB AUTO_INCREMENT=167 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- La exportación de datos fue deseleccionada.

/*!40103 SET TIME_ZONE=IFNULL(@OLD_TIME_ZONE, 'system') */;
/*!40101 SET SQL_MODE=IFNULL(@OLD_SQL_MODE, '') */;
/*!40014 SET FOREIGN_KEY_CHECKS=IFNULL(@OLD_FOREIGN_KEY_CHECKS, 1) */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40111 SET SQL_NOTES=IFNULL(@OLD_SQL_NOTES, 1) */;
