From 20834cb3cbc7039bcefddd9d9cb5d2ea977f443e Mon Sep 17 00:00:00 2001
From: Jan-Hendrik Willms <tleilax+github@gmail.com>
Date: Fri, 1 Apr 2022 12:23:19 +0200
Subject: [PATCH] adjust migration to prevent errors (adjusts
 fe081811e9a365f6d37b7cec79775120ff31a13d), re #736

---
 .../20220401_add_index_to_cw_user_progresses_v50.php      | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/db/migrations/20220401_add_index_to_cw_user_progresses_v50.php b/db/migrations/20220401_add_index_to_cw_user_progresses_v50.php
index aaea146ee72..fe86201d8d7 100644
--- a/db/migrations/20220401_add_index_to_cw_user_progresses_v50.php
+++ b/db/migrations/20220401_add_index_to_cw_user_progresses_v50.php
@@ -8,6 +8,14 @@ final class AddIndexToCwUserProgressesV50 extends Migration
 
     public function up()
     {
+        // avoid running this migration twice
+        $query = "SHOW INDEX FROM `cw_user_progresses` WHERE Key_name = 'block_id'";
+        $result = DBManager::get()->query($query);
+
+        if ($result && $result->rowCount() > 0) {
+            return;
+        }
+
         $query = "ALTER TABLE `cw_user_progresses`
                   ADD INDEX `block_id` (`block_id`)";
         DBManager::get()->exec($query);
-- 
GitLab