[
  {
    "type": "alter_table",
    "description": "Add eventId column to tasks table for event management integration",
    "database": "{{store}}",
    "check_query": "SELECT COUNT(*) as cnt FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'tasks' AND COLUMN_NAME = 'eventId'",
    "check_value": 0,
    "sql": "ALTER TABLE `tasks` ADD COLUMN `eventId` INT UNSIGNED NULL DEFAULT NULL COMMENT 'FK to events.id for event-managed tasks' AFTER `timeOfDay`"
  },
  {
    "type": "alter_table",
    "description": "Add index on tasks.eventId for efficient lookups",
    "database": "{{store}}",
    "check_query": "SELECT COUNT(*) as cnt FROM information_schema.STATISTICS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'tasks' AND INDEX_NAME = 'idx_eventId'",
    "check_value": 0,
    "sql": "ALTER TABLE `tasks` ADD INDEX `idx_eventId` (`eventId`)"
  },
  {
    "type": "alter_table",
    "description": "Add foreign key constraint from tasks.eventId to events.id with SET NULL on delete",
    "database": "{{store}}",
    "check_query": "SELECT COUNT(*) as cnt FROM information_schema.TABLE_CONSTRAINTS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'tasks' AND CONSTRAINT_NAME = 'fk_tasks_event'",
    "check_value": 0,
    "sql": "ALTER TABLE `tasks` ADD CONSTRAINT `fk_tasks_event` FOREIGN KEY (`eventId`) REFERENCES `events`(`id`) ON DELETE SET NULL ON UPDATE CASCADE"
  }
]
