Sequel.migration do transaction up do run 'ALTER TABLE `tasks` ADD CONSTRAINT `task_master_id` FOREIGN KEY (`master_id`) REFERENCES `tasks` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE;' run 'ALTER TABLE `tasks` ADD CONSTRAINT `task_parent_id` FOREIGN KEY (`parent_id`) REFERENCES `tasks` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE;' run 'ALTER TABLE `task_logs` CHANGE `node_id` `node_id` INT(11) UNSIGNED NULL;' run 'ALTER TABLE `task_logs` ADD CONSTRAINT `task_logs_task_id` FOREIGN KEY (`task_id`) REFERENCES `tasks` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE;' run 'ALTER TABLE `task_logs` ADD CONSTRAINT `task_logs_node_id` FOREIGN KEY (`node_id`) REFERENCES `nodes` (`id`) ON DELETE SET NULL ON UPDATE CASCADE;' end down do run 'ALTER TABLE `task_logs` DROP FOREIGN KEY `task_logs_node_id`;' run 'ALTER TABLE `task_logs` DROP FOREIGN KEY `task_logs_task_id`;' run 'ALTER TABLE `task_logs` CHANGE `node_id` `node_id` INT(11) UNSIGNED NOT NULL;' run 'ALTER TABLE `tasks` DROP FOREIGN KEY `task_parent_id`;' run 'ALTER TABLE `tasks` DROP FOREIGN KEY `task_master_id`;' end end