[
  {
    "type": "create_table",
    "description": "Create analytics_item_velocity table for velocity bucket aggregation",
    "database": "{{store}}",
    "check_query": "SHOW TABLES LIKE 'analytics_item_velocity'",
    "sql": "CREATE TABLE `analytics_item_velocity` (`id` int(10) unsigned NOT NULL AUTO_INCREMENT, `date` date NOT NULL COMMENT 'Aggregation date', `velocityBucket` enum('0-7','8-14','15-30','31-60','61-90','91-180','180+') NOT NULL COMMENT 'Days to sale bucket', `itemCount` int(10) unsigned NOT NULL DEFAULT 0 COMMENT 'Items sold in bucket', `totalRevenue` decimal(12,2) DEFAULT 0 COMMENT 'Total sales amount', `totalCost` decimal(12,2) DEFAULT 0 COMMENT 'Total cost', `totalMargin` decimal(12,2) DEFAULT 0 COMMENT 'totalRevenue - totalCost', `avgMargin` decimal(10,2) DEFAULT 0 COMMENT 'Average margin per item', `avgDaysToSale` decimal(6,2) DEFAULT 0 COMMENT 'Average days in bucket', `computedAt` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), PRIMARY KEY (`id`), UNIQUE KEY `unique_date_bucket` (`date`, `velocityBucket`), KEY `idx_date` (`date`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Pre-computed velocity bucket distribution for analytics'"
  },
  {
    "type": "create_table",
    "description": "Create analytics_velocity_daily table for daily velocity summary",
    "database": "{{store}}",
    "check_query": "SHOW TABLES LIKE 'analytics_velocity_daily'",
    "sql": "CREATE TABLE `analytics_velocity_daily` (`id` int(10) unsigned NOT NULL AUTO_INCREMENT, `date` date NOT NULL COMMENT 'Aggregation date', `totalItemsSold` int(10) unsigned NOT NULL DEFAULT 0 COMMENT 'Total items sold', `avgDaysToSale` decimal(6,2) DEFAULT 0 COMMENT 'Daily average days to sale', `medianDaysToSale` decimal(6,2) DEFAULT 0 COMMENT 'Daily median days to sale', `avgMargin` decimal(10,2) DEFAULT 0 COMMENT 'Daily average margin', `marginErosion180Plus` decimal(6,2) DEFAULT 0 COMMENT 'Percent erosion vs 0-7 bucket', `computedAt` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), PRIMARY KEY (`id`), UNIQUE KEY `unique_date` (`date`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Daily velocity summary for trend analysis'"
  }
]
