Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Additional fixes for indexes in postgres. A few unique indexes may ha…

…ve been created non-unique. Still deferring the version bump -- please review the patch!

Merge of patchsets
 arch-eduforge@catalyst.net.nz--2004/moodle--eduforge--1.3.3--patch-423
 arch-eduforge@catalyst.net.nz--2004/moodle--eduforge--1.3.3--patch-425
  • Loading branch information...
commit 778f416bd7e7c137b4c337dfb9750f63ec5a1140 1 parent b9ebeec
martinlanghoff authored
Showing with 19 additions and 4 deletions.
  1. +17 −3 lib/db/postgres7.php
  2. +2 −1  lib/db/postgres7.sql
View
20 lib/db/postgres7.php
@@ -678,7 +678,8 @@ function main_upgrade($oldversion=0) {
}
flush();
- modify_database('','DROP INDEX prefix_user_students_courseuserid_idx;');
+ execute_sql("DROP INDEX {$CFG->prefix}user_students_courseuserid_idx ", false);
+ execute_sql("DROP INDEX {$CFG->prefix}user_students_courseuserid_uk ", false);
modify_database('','CREATE UNIQUE INDEX prefix_user_students_courseuserid_uk ON prefix_user_students (course,userid);');
/// Delete duplicate teacher enrolments
@@ -691,9 +692,22 @@ function main_upgrade($oldversion=0) {
}
}
flush();
-
- modify_database('','DROP INDEX prefix_user_teachers_courseuserid_idx;');
+
+ execute_sql("DROP INDEX {$CFG->prefix}user_teachers_courseuserid_idx ", false);
+ execute_sql("DROP INDEX {$CFG->prefix}user_teachers_courseuserid_uk ", false);
modify_database('','CREATE UNIQUE INDEX prefix_user_teachers_courseuserid_uk ON prefix_user_teachers (course,userid);');
+
+ // some postgres databases may have a non-unique index mislabeled unique.
+ fix_course_sortorder(0,0,1);
+ execute_sql("DROP INDEX {$CFG->prefix}course_category_sortorder_uk ", false);
+ execute_sql("DROP INDEX {$CFG->prefix}course_category_idx ", false);
+ modify_database('', "CREATE UNIQUE INDEX prefix_course_category_sortorder_uk ON prefix_course(category,sortorder);");
+
+ // odd! username was missing its unique index!
+ // first silently drop it just in case...
+ execute_sql("DROP INDEX {$CFG->prefix}user_username_uk", false);
+ modify_database('', "CREATE UNIQUE INDEX prefix_user_username_uk ON prefix_user (username);");
+
}
return $result;
View
3  lib/db/postgres7.sql
@@ -40,7 +40,7 @@ CREATE TABLE prefix_course (
timemodified integer NOT NULL default '0'
);
-CREATE INDEX prefix_course_category_sortorder_uk ON prefix_course (category,sortorder);
+CREATE UNIQUE INDEX prefix_course_category_sortorder_uk ON prefix_course (category,sortorder);
CREATE INDEX prefix_course_idnumber_idx ON prefix_course (idnumber);
CREATE INDEX prefix_course_shortname_idx ON prefix_course (shortname);
@@ -252,6 +252,7 @@ CREATE TABLE prefix_user (
CONSTRAINT prefix_user_username_uk UNIQUE (username)
);
+CREATE UNIQUE INDEX prefix_user_username_uk ON prefix_user (username);
CREATE INDEX prefix_user_idnumber_idx ON prefix_user (idnumber);
CREATE INDEX prefix_user_auth_idx ON prefix_user (auth);
CREATE INDEX prefix_user_deleted_idx ON prefix_user (deleted);
Please sign in to comment.
Something went wrong with that request. Please try again.