-- EnglishSpeak
-- Simple MariaDB-safe migration
-- Link activities.flashcard_set_id -> flashcard_sets.id

ALTER TABLE `activities`
ADD COLUMN `flashcard_set_id` BIGINT UNSIGNED NULL AFTER `lesson_id`;

ALTER TABLE `activities`
ADD INDEX `idx_activities_flashcard_set_id` (`flashcard_set_id`);

ALTER TABLE `activities`
ADD CONSTRAINT `fk_activities_flashcard_set`
FOREIGN KEY (`flashcard_set_id`)
REFERENCES `flashcard_sets` (`id`)
ON UPDATE CASCADE
ON DELETE SET NULL;
