diff --git a/db/upgrade.php b/db/upgrade.php
index dee0096d5c1f4e42e5cfbd690eb874fceed62ca2..dcad1a6a51ab42713957bf50a3983c8f71bba0e6 100644
--- a/db/upgrade.php
+++ b/db/upgrade.php
@@ -524,14 +524,16 @@ function hvp_upgrade_2020082800() {
  * Drop old unused unique index, add nonunique index.
  */
 function hvp_upgrade_2020091500() {
-      global $DB;
-      $dbman = $DB->get_manager();
-      $table = new xmldb_table('hvp_xapi_results');
-      $index = new xmldb_index('results', XMLDB_INDEX_NOTUNIQUE, ['content_id', 'user_id']);
-      $dbman->add_index($table, $index);
-
-      $oldindex = new xmldb_index('result', XMLDB_INDEX_UNIQUE, ['id', 'content_id', 'user_id']);
-      $dbman->drop_index($table, $oldindex);
+    global $DB;
+    $dbman = $DB->get_manager();
+    $table = new xmldb_table('hvp_xapi_results');
+    $index = new xmldb_index('results', XMLDB_INDEX_NOTUNIQUE, ['content_id', 'user_id']);
+    if (!$dbman->index_exists($table, $index)) {
+        $dbman->add_index($table, $index);
+    }
+
+    $oldindex = new xmldb_index('result', XMLDB_INDEX_UNIQUE, ['id', 'content_id', 'user_id']);
+    $dbman->drop_index($table, $oldindex);
 }
 
 function hvp_upgrade_2020112600() {