[
  {
    "type": "raw_sql",
    "description": "Migrate scheduleAvailability.employeeId from old employee IDs to central user IDs via user_employee_links",
    "database": "{{store}}",
    "check_query": "SELECT 1 WHERE NOT EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'scheduleAvailability') UNION SELECT 1 WHERE NOT EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'kiosk_users' AND TABLE_NAME = 'user_employee_links')",
    "sql": "UPDATE scheduleAvailability sa INNER JOIN kiosk_users.user_employee_links l ON sa.employeeId = l.employeeId COLLATE utf8mb4_unicode_ci AND l.typeNum = SUBSTRING(DATABASE(), 7) SET sa.employeeId = l.userId WHERE sa.employeeId != l.userId"
  },
  {
    "type": "raw_sql",
    "description": "Migrate scheduleAvailabilityExceptions.employeeId from old employee IDs to central user IDs via user_employee_links",
    "database": "{{store}}",
    "check_query": "SELECT 1 WHERE NOT EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'scheduleAvailabilityExceptions') UNION SELECT 1 WHERE NOT EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'kiosk_users' AND TABLE_NAME = 'user_employee_links')",
    "sql": "UPDATE scheduleAvailabilityExceptions sae INNER JOIN kiosk_users.user_employee_links l ON sae.employeeId = l.employeeId COLLATE utf8mb4_unicode_ci AND l.typeNum = SUBSTRING(DATABASE(), 7) SET sae.employeeId = l.userId WHERE sae.employeeId != l.userId"
  },
  {
    "type": "alter_table",
    "description": "Update scheduleAvailability.employeeId column comment to reflect FK to central users",
    "database": "{{store}}",
    "check_query": "SELECT 1 FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'scheduleAvailability' AND COLUMN_NAME = 'employeeId' AND COLUMN_COMMENT LIKE '%kiosk_users.users%'",
    "sql": "ALTER TABLE scheduleAvailability MODIFY COLUMN `employeeId` int(10) unsigned NOT NULL COMMENT 'FK to kiosk_users.users.id (central user ID)'"
  },
  {
    "type": "alter_table",
    "description": "Update scheduleAvailabilityExceptions.employeeId column comment to reflect FK to central users",
    "database": "{{store}}",
    "check_query": "SELECT 1 FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'scheduleAvailabilityExceptions' AND COLUMN_NAME = 'employeeId' AND COLUMN_COMMENT LIKE '%kiosk_users.users%'",
    "sql": "ALTER TABLE scheduleAvailabilityExceptions MODIFY COLUMN `employeeId` int(10) unsigned NOT NULL COMMENT 'FK to kiosk_users.users.id (central user ID)'"
  }
]
