[
  {
    "type": "create_table",
    "description": "Spec 049 T1.2.3: Create storeBreakPolicy table in each store DB (adopted break policy per store)",
    "database": "{{store}}",
    "check_query": "SHOW TABLES LIKE 'storeBreakPolicy'",
    "sql": "CREATE TABLE `storeBreakPolicy` (\n  `id` INT UNSIGNED NOT NULL AUTO_INCREMENT,\n  `basedOnPresetKey` VARCHAR(50) NULL COMMENT 'Adopted preset key, e.g. CA-2025. NULL if fully custom.',\n  `basedOnPresetVersion` INT UNSIGNED NULL COMMENT 'Version of the adopted preset at time of adoption',\n  `isCustomized` TINYINT(1) NOT NULL DEFAULT 0 COMMENT 'True if any cloned rule has been edited',\n  `enabled` TINYINT(1) NOT NULL DEFAULT 1 COMMENT 'Store-level kill switch for the policy itself (distinct from stores.breakPolicyEnabled feature flag)',\n  `defaultBreakType` ENUM('paid','unpaid') NOT NULL DEFAULT 'unpaid' COMMENT 'Fallback classification for breaks that match no rule',\n  `createdAt` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,\n  `updatedAt` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,\n  PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Spec 049: Per-store adopted break policy (one row per store)'"
  },
  {
    "type": "create_table",
    "description": "Spec 049 T1.2.3: Create storeBreakPolicyRule table in each store DB (cloned rules with preset back-pointer)",
    "database": "{{store}}",
    "check_query": "SHOW TABLES LIKE 'storeBreakPolicyRule'",
    "sql": "CREATE TABLE `storeBreakPolicyRule` (\n  `id` INT UNSIGNED NOT NULL AUTO_INCREMENT,\n  `policyId` INT UNSIGNED NOT NULL,\n  `priority` INT UNSIGNED NOT NULL,\n  `ruleType` ENUM('rest','meal','secondMeal','flsaCutoff','autoDeduct') NOT NULL,\n  `triggerShiftMinHours` DECIMAL(4,2) NULL,\n  `triggerShiftMaxHours` DECIMAL(4,2) NULL,\n  `triggerStartTimeWindow` VARCHAR(20) NULL,\n  `durationMinutes` INT UNSIGNED NOT NULL,\n  `durationToleranceMinutes` INT UNSIGNED NOT NULL DEFAULT 0,\n  `isPaid` TINYINT(1) NOT NULL,\n  `isRequired` TINYINT(1) NOT NULL DEFAULT 0,\n  `mustStartBeforeHourOfShift` DECIMAL(4,2) NULL,\n  `classifyShortBreaksUnderMinutesAsPaid` INT UNSIGNED NULL,\n  `premiumPayOnViolation` TINYINT(1) NOT NULL DEFAULT 0,\n  `premiumPayHours` DECIMAL(4,2) NOT NULL DEFAULT 0.00,\n  `notes` TEXT NULL,\n  `isOverride` TINYINT(1) NOT NULL DEFAULT 0 COMMENT 'True if this rule has been edited away from the source preset',\n  `sourcePresetRuleId` INT UNSIGNED NULL COMMENT 'Back-pointer to kiosk_buykiosk.breakPolicyPresetRule.id for Reset-to-preset action (no cross-DB FK)',\n  PRIMARY KEY (`id`),\n  INDEX `idx_policy_priority` (`policyId`, `priority`),\n  INDEX `idx_sourcePresetRuleId` (`sourcePresetRuleId`),\n  CONSTRAINT `fk_storeBreakPolicyRule_policy` FOREIGN KEY (`policyId`) REFERENCES `storeBreakPolicy`(`id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Spec 049: Cloned policy rules per store (with preset back-pointer for Reset action)'"
  },
  {
    "type": "create_table",
    "description": "Spec 049 T1.2.3: Create breakComplianceLog table in each store DB (append-only violation log; uk_idempotent unique key for safe recompute)",
    "database": "{{store}}",
    "check_query": "SHOW TABLES LIKE 'breakComplianceLog'",
    "sql": "CREATE TABLE `breakComplianceLog` (\n  `id` INT UNSIGNED NOT NULL AUTO_INCREMENT,\n  `employeeId` INT UNSIGNED NOT NULL COMMENT 'References kiosk_users.users.id (cross-DB, no FK)',\n  `shiftId` INT UNSIGNED NULL COMMENT 'References shifts.id in this store DB (no FK to avoid coupling). Repository writes 0 sentinel for NULL to make uk_idempotent enforce uniqueness.',\n  `punchId` INT UNSIGNED NULL COMMENT 'References timePunch.id; may be NULL for missingMeal/autoDeduct synthesis. Repository writes 0 sentinel for NULL to make uk_idempotent enforce uniqueness.',\n  `violationType` ENUM('missingMeal','lateMeal','shortMeal','missingRest','autoDeduct') NOT NULL,\n  `ruleId` INT UNSIGNED NULL COMMENT 'References storeBreakPolicyRule.id. Repository writes 0 sentinel for autoDeduct synthesis without a live rule.',\n  `shiftDate` DATE NOT NULL,\n  `details` JSON NULL COMMENT 'Rule snapshot + break meta + preset key/version (populated in Phase 3 per T3.2.2a). Survives post-adoption rule deletion.',\n  `premiumPayHours` DECIMAL(4,2) NOT NULL DEFAULT 0.00,\n  `resolved` TINYINT(1) NOT NULL DEFAULT 0,\n  `resolvedByUserId` INT UNSIGNED NULL,\n  `resolvedAt` TIMESTAMP NULL,\n  `createdAt` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,\n  PRIMARY KEY (`id`),\n  INDEX `idx_employee_date` (`employeeId`, `shiftDate`),\n  INDEX `idx_unresolved` (`resolved`, `shiftDate`),\n  UNIQUE KEY `uk_idempotent` (`employeeId`, `shiftDate`, `shiftId`, `violationType`, `ruleId`, `punchId`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Spec 049: Append-only break compliance violation log; uk_idempotent makes timesheet recompute safe via INSERT ON DUPLICATE KEY UPDATE'"
  }
]
