[
  {
    "type": "alter_table",
    "description": "Drop foreign key on staff_chat_attachments.messageId to allow nullable",
    "database": "{{store}}",
    "check_query": "SELECT COUNT(*) as cnt FROM information_schema.TABLE_CONSTRAINTS WHERE CONSTRAINT_NAME = 'fk_staff_chat_attachment_message' AND TABLE_NAME = 'staff_chat_attachments' AND TABLE_SCHEMA = DATABASE()",
    "check_value": "1",
    "sql": "ALTER TABLE `staff_chat_attachments` DROP FOREIGN KEY `fk_staff_chat_attachment_message`"
  },
  {
    "type": "alter_table",
    "description": "Make staff_chat_attachments.messageId nullable for pre-upload attachment workflow",
    "database": "{{store}}",
    "check_query": "SELECT IS_NULLABLE FROM information_schema.COLUMNS WHERE TABLE_NAME = 'staff_chat_attachments' AND COLUMN_NAME = 'messageId' AND TABLE_SCHEMA = DATABASE()",
    "check_value": "NO",
    "sql": "ALTER TABLE `staff_chat_attachments` MODIFY COLUMN `messageId` bigint(20) unsigned DEFAULT NULL"
  },
  {
    "type": "alter_table",
    "description": "Re-add foreign key on staff_chat_attachments.messageId with ON DELETE CASCADE",
    "database": "{{store}}",
    "check_query": "SELECT COUNT(*) as cnt FROM information_schema.TABLE_CONSTRAINTS WHERE CONSTRAINT_NAME = 'fk_staff_chat_attachment_message' AND TABLE_NAME = 'staff_chat_attachments' AND TABLE_SCHEMA = DATABASE()",
    "check_value": "0",
    "sql": "ALTER TABLE `staff_chat_attachments` ADD CONSTRAINT `fk_staff_chat_attachment_message` FOREIGN KEY (`messageId`) REFERENCES `staff_chat_messages` (`id`) ON DELETE CASCADE"
  }
]
