-- IG Sort Yellow v46 non-destructive compatibility migration
-- 목적: 운영 데이터와 기존 테이블을 삭제하지 않고 ig_media_collect_event 필수 컬럼만 보완합니다.
-- 금지: DROP TABLE, TRUNCATE, DELETE를 사용하지 않습니다.

-- IG Sort Yellow v45 migration from v44
-- 기존 ig_media / ig_media_user_download 데이터를 보존하고 통계 이벤트 테이블만 추가합니다.

CREATE TABLE IF NOT EXISTS `ig_media_collect_event` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `event_key` char(40) NOT NULL COMMENT 'idempotent key for one pass/snapshot media event',
  `collector_id` varchar(80) NOT NULL DEFAULT '',
  `shortcode` varchar(64) NOT NULL,
  `ig_account_id` varchar(120) NOT NULL DEFAULT '',
  `account_name` varchar(255) NOT NULL DEFAULT '',
  `folder_name` varchar(255) NOT NULL DEFAULT '',
  `source_type` varchar(40) NOT NULL DEFAULT '' COMMENT 'explore/profile/reel/search/etc',
  `target_url` varchar(1024) NOT NULL DEFAULT '',
  `pass_id` varchar(120) NOT NULL DEFAULT '' COMMENT 'snapshot/pass/cycle id',
  `top_n` int(10) unsigned NOT NULL DEFAULT 0,
  `threshold_value` bigint(20) unsigned NOT NULL DEFAULT 0,
  `threshold_label` varchar(80) NOT NULL DEFAULT '',
  `rank_no` int(10) unsigned NOT NULL DEFAULT 0 COMMENT 'pass/snapshot rank only, not stable id',
  `rank_label` varchar(40) NOT NULL DEFAULT '',
  `rank_meaning` varchar(80) NOT NULL DEFAULT 'sort_rank_at_collection_time',
  `sort_field` varchar(40) NOT NULL DEFAULT '' COMMENT 'play_count/likes/comments/reposts/upload_at/etc',
  `sort_value` bigint(20) unsigned NOT NULL DEFAULT 0,
  `views` bigint(20) unsigned NOT NULL DEFAULT 0,
  `likes` bigint(20) unsigned NOT NULL DEFAULT 0,
  `comments` bigint(20) unsigned NOT NULL DEFAULT 0,
  `reposts` bigint(20) unsigned NOT NULL DEFAULT 0,
  `upload_at` datetime DEFAULT NULL,
  `collected_at` datetime DEFAULT NULL,
  `downloaded_at` datetime DEFAULT NULL,
  `filename_stem` varchar(255) NOT NULL DEFAULT '',
  `media_index` int(10) unsigned NOT NULL DEFAULT 0,
  `has_image` tinyint(1) unsigned NOT NULL DEFAULT 0,
  `has_video` tinyint(1) unsigned NOT NULL DEFAULT 0,
  `image_file_name` varchar(255) NOT NULL DEFAULT '',
  `video_file_name` varchar(255) NOT NULL DEFAULT '',
  `image_size` bigint(20) unsigned NOT NULL DEFAULT 0,
  `video_size` bigint(20) unsigned NOT NULL DEFAULT 0,
  `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 `uq_event_key` (`event_key`),
  KEY `idx_collector_date` (`collector_id`, `downloaded_at`, `id`),
  KEY `idx_collector_collect` (`collector_id`, `collected_at`, `id`),
  KEY `idx_sort_date` (`sort_field`, `downloaded_at`, `rank_no`),
  KEY `idx_shortcode` (`shortcode`),
  KEY `idx_upload_at` (`upload_at`),
  KEY `idx_rank` (`rank_no`),
  KEY `idx_views` (`views`),
  KEY `idx_likes` (`likes`),
  KEY `idx_comments` (`comments`),
  KEY `idx_reposts` (`reposts`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;


SET @yellow_db := DATABASE();

SET @yellow_sql := IF(EXISTS(SELECT 1 FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=@yellow_db AND TABLE_NAME='ig_media_collect_event' AND COLUMN_NAME='id'),
    'SELECT 1',
    'ALTER TABLE `ig_media_collect_event` ADD COLUMN `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT UNIQUE FIRST');
PREPARE yellow_stmt FROM @yellow_sql;
EXECUTE yellow_stmt;
DEALLOCATE PREPARE yellow_stmt;

SET @yellow_sql := IF(EXISTS(SELECT 1 FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=@yellow_db AND TABLE_NAME='ig_media_collect_event' AND COLUMN_NAME='event_key'),
    'SELECT 1',
    'ALTER TABLE `ig_media_collect_event` ADD COLUMN `event_key` char(40) NOT NULL DEFAULT '' COMMENT 'idempotent event key' AFTER `id`');
PREPARE yellow_stmt FROM @yellow_sql;
EXECUTE yellow_stmt;
DEALLOCATE PREPARE yellow_stmt;

SET @yellow_sql := IF(EXISTS(SELECT 1 FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=@yellow_db AND TABLE_NAME='ig_media_collect_event' AND COLUMN_NAME='collector_id'),
    'SELECT 1',
    'ALTER TABLE `ig_media_collect_event` ADD COLUMN `collector_id` varchar(80) NOT NULL DEFAULT '' AFTER `event_key`');
PREPARE yellow_stmt FROM @yellow_sql;
EXECUTE yellow_stmt;
DEALLOCATE PREPARE yellow_stmt;

SET @yellow_sql := IF(EXISTS(SELECT 1 FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=@yellow_db AND TABLE_NAME='ig_media_collect_event' AND COLUMN_NAME='shortcode'),
    'SELECT 1',
    'ALTER TABLE `ig_media_collect_event` ADD COLUMN `shortcode` varchar(64) NOT NULL DEFAULT '' AFTER `collector_id`');
PREPARE yellow_stmt FROM @yellow_sql;
EXECUTE yellow_stmt;
DEALLOCATE PREPARE yellow_stmt;

SET @yellow_sql := IF(EXISTS(SELECT 1 FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=@yellow_db AND TABLE_NAME='ig_media_collect_event' AND COLUMN_NAME='ig_account_id'),
    'SELECT 1',
    'ALTER TABLE `ig_media_collect_event` ADD COLUMN `ig_account_id` varchar(120) NOT NULL DEFAULT '' AFTER `shortcode`');
PREPARE yellow_stmt FROM @yellow_sql;
EXECUTE yellow_stmt;
DEALLOCATE PREPARE yellow_stmt;

SET @yellow_sql := IF(EXISTS(SELECT 1 FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=@yellow_db AND TABLE_NAME='ig_media_collect_event' AND COLUMN_NAME='account_name'),
    'SELECT 1',
    'ALTER TABLE `ig_media_collect_event` ADD COLUMN `account_name` varchar(255) NOT NULL DEFAULT '' AFTER `ig_account_id`');
PREPARE yellow_stmt FROM @yellow_sql;
EXECUTE yellow_stmt;
DEALLOCATE PREPARE yellow_stmt;

SET @yellow_sql := IF(EXISTS(SELECT 1 FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=@yellow_db AND TABLE_NAME='ig_media_collect_event' AND COLUMN_NAME='folder_name'),
    'SELECT 1',
    'ALTER TABLE `ig_media_collect_event` ADD COLUMN `folder_name` varchar(255) NOT NULL DEFAULT '' AFTER `account_name`');
PREPARE yellow_stmt FROM @yellow_sql;
EXECUTE yellow_stmt;
DEALLOCATE PREPARE yellow_stmt;

SET @yellow_sql := IF(EXISTS(SELECT 1 FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=@yellow_db AND TABLE_NAME='ig_media_collect_event' AND COLUMN_NAME='source_type'),
    'SELECT 1',
    'ALTER TABLE `ig_media_collect_event` ADD COLUMN `source_type` varchar(40) NOT NULL DEFAULT '' AFTER `folder_name`');
PREPARE yellow_stmt FROM @yellow_sql;
EXECUTE yellow_stmt;
DEALLOCATE PREPARE yellow_stmt;

SET @yellow_sql := IF(EXISTS(SELECT 1 FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=@yellow_db AND TABLE_NAME='ig_media_collect_event' AND COLUMN_NAME='target_url'),
    'SELECT 1',
    'ALTER TABLE `ig_media_collect_event` ADD COLUMN `target_url` varchar(1024) NOT NULL DEFAULT '' AFTER `source_type`');
PREPARE yellow_stmt FROM @yellow_sql;
EXECUTE yellow_stmt;
DEALLOCATE PREPARE yellow_stmt;

SET @yellow_sql := IF(EXISTS(SELECT 1 FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=@yellow_db AND TABLE_NAME='ig_media_collect_event' AND COLUMN_NAME='pass_id'),
    'SELECT 1',
    'ALTER TABLE `ig_media_collect_event` ADD COLUMN `pass_id` varchar(120) NOT NULL DEFAULT '' AFTER `target_url`');
PREPARE yellow_stmt FROM @yellow_sql;
EXECUTE yellow_stmt;
DEALLOCATE PREPARE yellow_stmt;

SET @yellow_sql := IF(EXISTS(SELECT 1 FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=@yellow_db AND TABLE_NAME='ig_media_collect_event' AND COLUMN_NAME='top_n'),
    'SELECT 1',
    'ALTER TABLE `ig_media_collect_event` ADD COLUMN `top_n` int(10) unsigned NOT NULL DEFAULT 0 AFTER `pass_id`');
PREPARE yellow_stmt FROM @yellow_sql;
EXECUTE yellow_stmt;
DEALLOCATE PREPARE yellow_stmt;

SET @yellow_sql := IF(EXISTS(SELECT 1 FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=@yellow_db AND TABLE_NAME='ig_media_collect_event' AND COLUMN_NAME='threshold_value'),
    'SELECT 1',
    'ALTER TABLE `ig_media_collect_event` ADD COLUMN `threshold_value` bigint(20) unsigned NOT NULL DEFAULT 0 AFTER `top_n`');
PREPARE yellow_stmt FROM @yellow_sql;
EXECUTE yellow_stmt;
DEALLOCATE PREPARE yellow_stmt;

SET @yellow_sql := IF(EXISTS(SELECT 1 FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=@yellow_db AND TABLE_NAME='ig_media_collect_event' AND COLUMN_NAME='threshold_label'),
    'SELECT 1',
    'ALTER TABLE `ig_media_collect_event` ADD COLUMN `threshold_label` varchar(80) NOT NULL DEFAULT '' AFTER `threshold_value`');
PREPARE yellow_stmt FROM @yellow_sql;
EXECUTE yellow_stmt;
DEALLOCATE PREPARE yellow_stmt;

SET @yellow_sql := IF(EXISTS(SELECT 1 FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=@yellow_db AND TABLE_NAME='ig_media_collect_event' AND COLUMN_NAME='rank_no'),
    'SELECT 1',
    'ALTER TABLE `ig_media_collect_event` ADD COLUMN `rank_no` int(10) unsigned NOT NULL DEFAULT 0 AFTER `threshold_label`');
PREPARE yellow_stmt FROM @yellow_sql;
EXECUTE yellow_stmt;
DEALLOCATE PREPARE yellow_stmt;

SET @yellow_sql := IF(EXISTS(SELECT 1 FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=@yellow_db AND TABLE_NAME='ig_media_collect_event' AND COLUMN_NAME='rank_label'),
    'SELECT 1',
    'ALTER TABLE `ig_media_collect_event` ADD COLUMN `rank_label` varchar(40) NOT NULL DEFAULT '' AFTER `rank_no`');
PREPARE yellow_stmt FROM @yellow_sql;
EXECUTE yellow_stmt;
DEALLOCATE PREPARE yellow_stmt;

SET @yellow_sql := IF(EXISTS(SELECT 1 FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=@yellow_db AND TABLE_NAME='ig_media_collect_event' AND COLUMN_NAME='rank_meaning'),
    'SELECT 1',
    'ALTER TABLE `ig_media_collect_event` ADD COLUMN `rank_meaning` varchar(80) NOT NULL DEFAULT 'sort_rank_at_collection_time' AFTER `rank_label`');
PREPARE yellow_stmt FROM @yellow_sql;
EXECUTE yellow_stmt;
DEALLOCATE PREPARE yellow_stmt;

SET @yellow_sql := IF(EXISTS(SELECT 1 FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=@yellow_db AND TABLE_NAME='ig_media_collect_event' AND COLUMN_NAME='sort_field'),
    'SELECT 1',
    'ALTER TABLE `ig_media_collect_event` ADD COLUMN `sort_field` varchar(40) NOT NULL DEFAULT '' AFTER `rank_meaning`');
PREPARE yellow_stmt FROM @yellow_sql;
EXECUTE yellow_stmt;
DEALLOCATE PREPARE yellow_stmt;

SET @yellow_sql := IF(EXISTS(SELECT 1 FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=@yellow_db AND TABLE_NAME='ig_media_collect_event' AND COLUMN_NAME='sort_value'),
    'SELECT 1',
    'ALTER TABLE `ig_media_collect_event` ADD COLUMN `sort_value` bigint(20) unsigned NOT NULL DEFAULT 0 AFTER `sort_field`');
PREPARE yellow_stmt FROM @yellow_sql;
EXECUTE yellow_stmt;
DEALLOCATE PREPARE yellow_stmt;

SET @yellow_sql := IF(EXISTS(SELECT 1 FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=@yellow_db AND TABLE_NAME='ig_media_collect_event' AND COLUMN_NAME='views'),
    'SELECT 1',
    'ALTER TABLE `ig_media_collect_event` ADD COLUMN `views` bigint(20) unsigned NOT NULL DEFAULT 0 AFTER `sort_value`');
PREPARE yellow_stmt FROM @yellow_sql;
EXECUTE yellow_stmt;
DEALLOCATE PREPARE yellow_stmt;

SET @yellow_sql := IF(EXISTS(SELECT 1 FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=@yellow_db AND TABLE_NAME='ig_media_collect_event' AND COLUMN_NAME='likes'),
    'SELECT 1',
    'ALTER TABLE `ig_media_collect_event` ADD COLUMN `likes` bigint(20) unsigned NOT NULL DEFAULT 0 AFTER `views`');
PREPARE yellow_stmt FROM @yellow_sql;
EXECUTE yellow_stmt;
DEALLOCATE PREPARE yellow_stmt;

SET @yellow_sql := IF(EXISTS(SELECT 1 FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=@yellow_db AND TABLE_NAME='ig_media_collect_event' AND COLUMN_NAME='comments'),
    'SELECT 1',
    'ALTER TABLE `ig_media_collect_event` ADD COLUMN `comments` bigint(20) unsigned NOT NULL DEFAULT 0 AFTER `likes`');
PREPARE yellow_stmt FROM @yellow_sql;
EXECUTE yellow_stmt;
DEALLOCATE PREPARE yellow_stmt;

SET @yellow_sql := IF(EXISTS(SELECT 1 FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=@yellow_db AND TABLE_NAME='ig_media_collect_event' AND COLUMN_NAME='reposts'),
    'SELECT 1',
    'ALTER TABLE `ig_media_collect_event` ADD COLUMN `reposts` bigint(20) unsigned NOT NULL DEFAULT 0 AFTER `comments`');
PREPARE yellow_stmt FROM @yellow_sql;
EXECUTE yellow_stmt;
DEALLOCATE PREPARE yellow_stmt;

SET @yellow_sql := IF(EXISTS(SELECT 1 FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=@yellow_db AND TABLE_NAME='ig_media_collect_event' AND COLUMN_NAME='upload_at'),
    'SELECT 1',
    'ALTER TABLE `ig_media_collect_event` ADD COLUMN `upload_at` datetime DEFAULT NULL AFTER `reposts`');
PREPARE yellow_stmt FROM @yellow_sql;
EXECUTE yellow_stmt;
DEALLOCATE PREPARE yellow_stmt;

SET @yellow_sql := IF(EXISTS(SELECT 1 FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=@yellow_db AND TABLE_NAME='ig_media_collect_event' AND COLUMN_NAME='collected_at'),
    'SELECT 1',
    'ALTER TABLE `ig_media_collect_event` ADD COLUMN `collected_at` datetime DEFAULT NULL AFTER `upload_at`');
PREPARE yellow_stmt FROM @yellow_sql;
EXECUTE yellow_stmt;
DEALLOCATE PREPARE yellow_stmt;

SET @yellow_sql := IF(EXISTS(SELECT 1 FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=@yellow_db AND TABLE_NAME='ig_media_collect_event' AND COLUMN_NAME='downloaded_at'),
    'SELECT 1',
    'ALTER TABLE `ig_media_collect_event` ADD COLUMN `downloaded_at` datetime DEFAULT NULL AFTER `collected_at`');
PREPARE yellow_stmt FROM @yellow_sql;
EXECUTE yellow_stmt;
DEALLOCATE PREPARE yellow_stmt;

SET @yellow_sql := IF(EXISTS(SELECT 1 FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=@yellow_db AND TABLE_NAME='ig_media_collect_event' AND COLUMN_NAME='filename_stem'),
    'SELECT 1',
    'ALTER TABLE `ig_media_collect_event` ADD COLUMN `filename_stem` varchar(255) NOT NULL DEFAULT '' AFTER `downloaded_at`');
PREPARE yellow_stmt FROM @yellow_sql;
EXECUTE yellow_stmt;
DEALLOCATE PREPARE yellow_stmt;

SET @yellow_sql := IF(EXISTS(SELECT 1 FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=@yellow_db AND TABLE_NAME='ig_media_collect_event' AND COLUMN_NAME='media_index'),
    'SELECT 1',
    'ALTER TABLE `ig_media_collect_event` ADD COLUMN `media_index` int(10) unsigned NOT NULL DEFAULT 0 AFTER `filename_stem`');
PREPARE yellow_stmt FROM @yellow_sql;
EXECUTE yellow_stmt;
DEALLOCATE PREPARE yellow_stmt;

SET @yellow_sql := IF(EXISTS(SELECT 1 FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=@yellow_db AND TABLE_NAME='ig_media_collect_event' AND COLUMN_NAME='has_image'),
    'SELECT 1',
    'ALTER TABLE `ig_media_collect_event` ADD COLUMN `has_image` tinyint(1) unsigned NOT NULL DEFAULT 0 AFTER `media_index`');
PREPARE yellow_stmt FROM @yellow_sql;
EXECUTE yellow_stmt;
DEALLOCATE PREPARE yellow_stmt;

SET @yellow_sql := IF(EXISTS(SELECT 1 FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=@yellow_db AND TABLE_NAME='ig_media_collect_event' AND COLUMN_NAME='has_video'),
    'SELECT 1',
    'ALTER TABLE `ig_media_collect_event` ADD COLUMN `has_video` tinyint(1) unsigned NOT NULL DEFAULT 0 AFTER `has_image`');
PREPARE yellow_stmt FROM @yellow_sql;
EXECUTE yellow_stmt;
DEALLOCATE PREPARE yellow_stmt;

SET @yellow_sql := IF(EXISTS(SELECT 1 FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=@yellow_db AND TABLE_NAME='ig_media_collect_event' AND COLUMN_NAME='image_file_name'),
    'SELECT 1',
    'ALTER TABLE `ig_media_collect_event` ADD COLUMN `image_file_name` varchar(255) NOT NULL DEFAULT '' AFTER `has_video`');
PREPARE yellow_stmt FROM @yellow_sql;
EXECUTE yellow_stmt;
DEALLOCATE PREPARE yellow_stmt;

SET @yellow_sql := IF(EXISTS(SELECT 1 FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=@yellow_db AND TABLE_NAME='ig_media_collect_event' AND COLUMN_NAME='video_file_name'),
    'SELECT 1',
    'ALTER TABLE `ig_media_collect_event` ADD COLUMN `video_file_name` varchar(255) NOT NULL DEFAULT '' AFTER `image_file_name`');
PREPARE yellow_stmt FROM @yellow_sql;
EXECUTE yellow_stmt;
DEALLOCATE PREPARE yellow_stmt;

SET @yellow_sql := IF(EXISTS(SELECT 1 FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=@yellow_db AND TABLE_NAME='ig_media_collect_event' AND COLUMN_NAME='image_size'),
    'SELECT 1',
    'ALTER TABLE `ig_media_collect_event` ADD COLUMN `image_size` bigint(20) unsigned NOT NULL DEFAULT 0 AFTER `video_file_name`');
PREPARE yellow_stmt FROM @yellow_sql;
EXECUTE yellow_stmt;
DEALLOCATE PREPARE yellow_stmt;

SET @yellow_sql := IF(EXISTS(SELECT 1 FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=@yellow_db AND TABLE_NAME='ig_media_collect_event' AND COLUMN_NAME='video_size'),
    'SELECT 1',
    'ALTER TABLE `ig_media_collect_event` ADD COLUMN `video_size` bigint(20) unsigned NOT NULL DEFAULT 0 AFTER `image_size`');
PREPARE yellow_stmt FROM @yellow_sql;
EXECUTE yellow_stmt;
DEALLOCATE PREPARE yellow_stmt;

SET @yellow_sql := IF(EXISTS(SELECT 1 FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=@yellow_db AND TABLE_NAME='ig_media_collect_event' AND COLUMN_NAME='created_at'),
    'SELECT 1',
    'ALTER TABLE `ig_media_collect_event` ADD COLUMN `created_at` datetime NOT NULL DEFAULT current_timestamp() AFTER `video_size`');
PREPARE yellow_stmt FROM @yellow_sql;
EXECUTE yellow_stmt;
DEALLOCATE PREPARE yellow_stmt;

SET @yellow_sql := IF(EXISTS(SELECT 1 FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=@yellow_db AND TABLE_NAME='ig_media_collect_event' AND COLUMN_NAME='updated_at'),
    'SELECT 1',
    'ALTER TABLE `ig_media_collect_event` ADD COLUMN `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp() AFTER `created_at`');
PREPARE yellow_stmt FROM @yellow_sql;
EXECUTE yellow_stmt;
DEALLOCATE PREPARE yellow_stmt;

SET @yellow_sql := IF(EXISTS(
    SELECT 1 FROM information_schema.STATISTICS
    WHERE TABLE_SCHEMA=@yellow_db AND TABLE_NAME='ig_media_collect_event'
      AND COLUMN_NAME='event_key' AND NON_UNIQUE=0
), 'SELECT 1', 'ALTER TABLE `ig_media_collect_event` ADD UNIQUE KEY `uq_event_key` (`event_key`)');
PREPARE yellow_stmt FROM @yellow_sql;
EXECUTE yellow_stmt;
DEALLOCATE PREPARE yellow_stmt;

SELECT COLUMN_NAME, COLUMN_TYPE, IS_NULLABLE, COLUMN_DEFAULT, COLUMN_KEY, EXTRA
FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME='ig_media_collect_event'
ORDER BY ORDINAL_POSITION;
