diff --git a/db/migrations/5.1.41_cleanup_seminar_user_notifications.php b/db/migrations/5.1.41_cleanup_seminar_user_notifications.php new file mode 100644 index 0000000000000000000000000000000000000000..6279ac7b29fa81aa4785163b242330d3f0e256e8 --- /dev/null +++ b/db/migrations/5.1.41_cleanup_seminar_user_notifications.php @@ -0,0 +1,21 @@ +<?php + +/** + * @see https://gitlab.studip.de/studip/studip/-/issues/2141 + */ +final class CleanupSeminarUserNotifications extends Migration +{ + public function description() + { + return "Removes all entries from `seminar_user_notifications` that are not in `seminar_user` as well"; + } + + protected function up() + { + $query = "DELETE `seminar_user_notifications` + FROM `seminar_user_notifications` + LEFT JOIN `seminar_user` USING(`user_id`, `Seminar_id`) + WHERE `seminar_user`.`user_id` IS NULL"; + DBManager::get()->exec($query); + } +}