[
  {
    "type": "create_table",
    "description": "Create closeReports table for storing daily close report data",
    "database": "{{store}}",
    "check_query": "SHOW TABLES LIKE 'closeReports'",
    "sql": "CREATE TABLE `closeReports` (\n  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,\n  `reportDate` date NOT NULL COMMENT 'Date of the close report (store local time)',\n  `postedAt` datetime NOT NULL COMMENT 'When the report was posted/submitted',\n  `netSalesRetail` int(11) DEFAULT NULL COMMENT 'Net sales in cents for list views',\n  `salesVsGoalPercent` decimal(5,2) DEFAULT NULL COMMENT 'Sales vs goal percentage for list views',\n  `buysCount` smallint(5) unsigned DEFAULT NULL COMMENT 'Number of buys for list views',\n  `buysTotal` int(11) DEFAULT NULL COMMENT 'Total buys amount in cents',\n  `laborPercent` decimal(5,2) DEFAULT NULL COMMENT 'Labor percentage (WiW stores only)',\n  `cashVariance` int(11) DEFAULT NULL COMMENT 'Cash variance in cents',\n  `hasDiscrepancy` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'Flag for quick filtering of discrepancies',\n  `fullPayload` json NOT NULL COMMENT 'Complete DRS JSON payload',\n  `salesSummary` json DEFAULT NULL COMMENT 'Extracted sales metrics JSON',\n  `buysData` json DEFAULT NULL COMMENT 'Buy statistics JSON',\n  `returnsData` json DEFAULT NULL COMMENT 'Returns data JSON',\n  `laborData` json DEFAULT NULL COMMENT 'Labor metrics JSON (if WiW)',\n  `cashData` json DEFAULT NULL COMMENT 'Cash variance/alerts JSON',\n  `checklistData` json DEFAULT NULL COMMENT 'Checklists with assignments JSON',\n  `comparisons` json DEFAULT NULL COMMENT 'WTD/MTD YoY comparison data JSON',\n  `isLegacyMigrated` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'Flag for records migrated from JSON files',\n  `createdAt` datetime NOT NULL DEFAULT current_timestamp(),\n  `updatedAt` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),\n  PRIMARY KEY (`id`),\n  UNIQUE KEY `uk_reportDate` (`reportDate`),\n  KEY `idx_postedAt` (`postedAt`),\n  KEY `idx_netSales` (`netSalesRetail`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Daily close report data per store'"
  }
]
