[
  {
    "type": "create_table",
    "description": "Audit trail of timesheet/payroll CSV exports. Every export (incl. unmarked previews) writes one row so there is a durable record of what was sent to payroll, by whom, and whether it flipped timesheets to status=exported. Fixes the gap where biweekly/period exports left no trace in the system.",
    "database": "{{store}}",
    "check_query": "SHOW TABLES LIKE 'scheduleTimesheetExports'",
    "sql": "CREATE TABLE `scheduleTimesheetExports` (\n  `exportId` INT UNSIGNED NOT NULL AUTO_INCREMENT,\n  `exportedByUserId` INT UNSIGNED DEFAULT NULL COMMENT 'kiosk_users.users.id of the manager who ran the export',\n  `payPeriod` VARCHAR(16) NOT NULL DEFAULT 'weekly' COMMENT 'weekly | period (biweekly/multi-week)',\n  `periodStart` DATE DEFAULT NULL COMMENT 'First covered work-week start (store local)',\n  `periodEnd` DATE DEFAULT NULL COMMENT 'Last covered work-week end (store local)',\n  `weekStarts` VARCHAR(512) DEFAULT NULL COMMENT 'JSON array of covered week-start dates',\n  `employeeCount` INT UNSIGNED NOT NULL DEFAULT 0 COMMENT 'Distinct employees in the export',\n  `timesheetCount` INT UNSIGNED NOT NULL DEFAULT 0 COMMENT 'Timesheet rows in the export',\n  `totalHours` DECIMAL(10,2) NOT NULL DEFAULT 0.00 COMMENT 'Sum of totalHours across exported rows',\n  `totalPay` DECIMAL(12,2) DEFAULT NULL COMMENT 'Sum of totalPay where known',\n  `markedExported` TINYINT(1) NOT NULL DEFAULT 0 COMMENT '1 = flipped rows to status=exported; 0 = preview/download only',\n  `includeAll` TINYINT(1) NOT NULL DEFAULT 0 COMMENT '1 = pending rows were included (period export)',\n  `rowsMarked` INT UNSIGNED NOT NULL DEFAULT 0 COMMENT 'How many timesheet rows were actually flipped to exported',\n  `roundingMode` VARCHAR(16) DEFAULT NULL COMMENT 'Payroll rounding mode applied to the CSV',\n  `roundingIncrementMinutes` INT UNSIGNED DEFAULT NULL COMMENT 'Payroll rounding increment applied to the CSV',\n  `filename` VARCHAR(255) DEFAULT NULL COMMENT 'Generated CSV filename',\n  `timesheetIds` TEXT DEFAULT NULL COMMENT 'JSON array of exported timesheetId values (detail audit)',\n  `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'When the export ran',\n  PRIMARY KEY (`exportId`),\n  KEY `idx_created` (`created_at`),\n  KEY `idx_period` (`periodStart`, `periodEnd`),\n  KEY `idx_user` (`exportedByUserId`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Audit trail of timesheet/payroll CSV exports'"
  }
]
