[
  {
    "type": "create_table",
    "description": "Create events table for store event management",
    "database": "{{store}}",
    "check_query": "SHOW TABLES LIKE 'events'",
    "sql": "CREATE TABLE `events` (\n  `id` INT UNSIGNED NOT NULL AUTO_INCREMENT,\n  `templateId` INT UNSIGNED NULL COMMENT 'FK to eventTemplates (global DB) if created from template',\n  `sourceEventId` INT UNSIGNED NULL COMMENT 'FK to events - if duplicated from another event',\n  `name` VARCHAR(100) NOT NULL,\n  `description` TEXT NULL,\n  `eventType` ENUM('season', 'holiday', 'sale', 'custom') NOT NULL,\n  `year` YEAR NOT NULL,\n  `startDate` DATE NOT NULL,\n  `endDate` DATE NOT NULL,\n  `buildUpDays` INT UNSIGNED DEFAULT 14,\n  `windDownDays` INT UNSIGNED DEFAULT 7,\n  `status` ENUM('draft', 'scheduled', 'active', 'completed', 'cancelled', 'archived') DEFAULT 'draft',\n  `previousStatus` VARCHAR(20) NULL COMMENT 'Stores status before archiving (for unarchive)',\n  `phase` ENUM('upcoming', 'build_up', 'active', 'wind_down', 'completed') DEFAULT 'upcoming',\n  `color` VARCHAR(7) NULL COMMENT 'Hex color',\n  `icon` VARCHAR(50) NULL,\n  `isRecurring` TINYINT(1) DEFAULT 0,\n  `archivedAt` TIMESTAMP NULL COMMENT 'When event was archived',\n  `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,\n  `updated_at` TIMESTAMP NULL ON UPDATE CURRENT_TIMESTAMP,\n  `createdBy` INT UNSIGNED NULL COMMENT 'FK to employees',\n  PRIMARY KEY (`id`),\n  INDEX `idx_status` (`status`),\n  INDEX `idx_year` (`year`),\n  INDEX `idx_dates` (`startDate`, `endDate`),\n  INDEX `idx_type` (`eventType`),\n  INDEX `idx_archived` (`archivedAt`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Store event management'"
  },
  {
    "type": "create_table",
    "description": "Create event_audit_log table for tracking event changes",
    "database": "{{store}}",
    "check_query": "SHOW TABLES LIKE 'event_audit_log'",
    "sql": "CREATE TABLE `event_audit_log` (\n  `id` INT UNSIGNED NOT NULL AUTO_INCREMENT,\n  `eventId` INT UNSIGNED NOT NULL,\n  `action` VARCHAR(50) NOT NULL COMMENT 'created, updated, activated, cancelled, archived, duplicated, etc.',\n  `details` JSON NULL,\n  `employeeId` INT UNSIGNED NULL,\n  `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,\n  PRIMARY KEY (`id`),\n  INDEX `idx_event` (`eventId`),\n  CONSTRAINT `fk_audit_event` FOREIGN KEY (`eventId`) REFERENCES `events`(`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Event change audit log'"
  },
  {
    "type": "create_table",
    "description": "Create event_calendar_tokens table for iCal feed authentication",
    "database": "{{store}}",
    "check_query": "SHOW TABLES LIKE 'event_calendar_tokens'",
    "sql": "CREATE TABLE `event_calendar_tokens` (\n  `id` INT UNSIGNED NOT NULL AUTO_INCREMENT,\n  `employeeId` INT UNSIGNED NOT NULL COMMENT 'FK to employees',\n  `token` VARCHAR(64) NOT NULL COMMENT 'Unique token for iCal feed',\n  `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,\n  `expires_at` TIMESTAMP NULL COMMENT 'Token expiration (NULL = never expires)',\n  `last_accessed` TIMESTAMP NULL COMMENT 'Last time feed was accessed',\n  PRIMARY KEY (`id`),\n  UNIQUE KEY `uk_token` (`token`),\n  INDEX `idx_employee` (`employeeId`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='iCal feed authentication tokens'"
  }
]
