[
  {
    "type": "create_table",
    "description": "Create SMS queue table for processing and tracking messages",
    "database": "{{store}}",
    "check_query": "SHOW TABLES LIKE 'sms_queue'",
    "sql": "CREATE TABLE `sms_queue` (\n  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,\n  `type_num` varchar(10) NOT NULL COMMENT 'Store identifier (e.g. ou00, pa00)',\n  `customer_phone` varchar(15) NOT NULL COMMENT 'Customer phone number',\n  `customer_name` varchar(255) NOT NULL COMMENT 'Customer name for personalization',\n  `message_text` text NOT NULL COMMENT 'SMS content with variables already replaced',\n  `trigger_id` int(10) unsigned NOT NULL COMMENT 'References seller_marketing_triggers.id',\n  `status` enum('queued','sending','sent','delivered','failed') NOT NULL DEFAULT 'queued' COMMENT 'Message processing status',\n  `created_at` timestamp NOT NULL DEFAULT current_timestamp() COMMENT 'When added to queue',\n  `sent_at` timestamp NULL DEFAULT NULL COMMENT 'When message was sent',\n  `delivered_at` timestamp NULL DEFAULT NULL COMMENT 'When delivery confirmed',\n  `error_message` text DEFAULT NULL COMMENT 'Error details if failed',\n  `retry_count` int(10) unsigned NOT NULL DEFAULT 0 COMMENT 'Number of retry attempts',\n  `twilio_sid` varchar(50) DEFAULT NULL COMMENT 'Twilio message SID',\n  PRIMARY KEY (`id`),\n  KEY `idx_type_num` (`type_num`),\n  KEY `idx_status` (`status`),\n  KEY `idx_trigger_id` (`trigger_id`),\n  KEY `idx_created_at` (`created_at`),\n  KEY `idx_type_status` (`type_num`,`status`),\n  KEY `idx_customer_phone` (`customer_phone`),\n  CONSTRAINT `fk_sms_queue_trigger` FOREIGN KEY (`trigger_id`) REFERENCES `seller_marketing_triggers` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='SMS message queue for trigger processing'"
  },
  {
    "type": "create_table",
    "description": "Create trigger execution tracking table",
    "database": "{{store}}",
    "check_query": "SHOW TABLES LIKE 'trigger_last_run'",
    "sql": "CREATE TABLE `trigger_last_run` (\n  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,\n  `trigger_id` int(10) unsigned NOT NULL COMMENT 'References seller_marketing_triggers.id',\n  `last_run_at` timestamp NOT NULL DEFAULT current_timestamp() COMMENT 'When trigger was last processed',\n  `customers_found` int(10) unsigned NOT NULL DEFAULT 0 COMMENT 'How many customers matched criteria',\n  `messages_queued` int(10) unsigned NOT NULL DEFAULT 0 COMMENT 'How many messages were queued',\n  `execution_time_ms` int(10) unsigned NOT NULL DEFAULT 0 COMMENT 'How long it took to run in milliseconds',\n  PRIMARY KEY (`id`),\n  KEY `idx_trigger_id` (`trigger_id`),\n  KEY `idx_last_run_at` (`last_run_at`),\n  CONSTRAINT `fk_trigger_last_run` FOREIGN KEY (`trigger_id`) REFERENCES `seller_marketing_triggers` (`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Track trigger execution history and performance'"
  }
]
