IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = 'app_35849' AND TABLE_NAME = 'tasks' AND COLUMN_NAME = 'user_id') THEN
    ALTER TABLE `tasks` ADD `user_id` INT(11) NULL AFTER `id`;
END IF;

IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE TABLE_SCHEMA = 'app_35849' AND TABLE_NAME = 'tasks' AND CONSTRAINT_NAME = 'fk_tasks_user_id') THEN
    ALTER TABLE `tasks` ADD CONSTRAINT `fk_tasks_user_id` FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
END IF;