mirror of
https://github.com/moodle/moodle.git
synced 2025-04-17 22:45:54 +02:00
Drop all the unique keys inside PostgreSQL DB and convert them to
their equivalest unique indexes. We aren't going to allow unique keys from 1.7 and upwards (until we decide to enforce referential intregrity and until ADOdb support it)
This commit is contained in:
parent
32da8f410f
commit
26b82be252
@ -1923,6 +1923,37 @@ function main_upgrade($oldversion=0) {
|
||||
execute_sql("CREATE UNIQUE INDEX {$CFG->prefix}role_sor_uix ON {$CFG->prefix}role (sortorder);", false);
|
||||
}
|
||||
|
||||
if ($oldversion < 2006092510) {
|
||||
/// Convert all the PG unique keys into their corresponding unique indexes
|
||||
/// we don't want such keys inside Moodle 1.7 and above
|
||||
/// Look for all the UNIQUE CONSTRAINSTS existing in DB
|
||||
$uniquecons = get_records_sql ("SELECT conname, relname, conkey, clas.oid AS tableoid
|
||||
FROM pg_constraint cons,
|
||||
pg_class clas
|
||||
WHERE cons.contype='u'
|
||||
AND cons.conrelid = clas.oid");
|
||||
/// Iterate over every unique constraint, calculating its fields
|
||||
if ($uniquecons) {
|
||||
foreach ($uniquecons as $uniquecon) {
|
||||
$conscols = trim(trim($uniquecon->conkey, '}'), '{');
|
||||
$conscols = explode(',', $conscols);
|
||||
/// Iterate over each column to fetch its name
|
||||
$indexcols = array();
|
||||
foreach ($conscols as $conscol) {
|
||||
$column = get_record_sql ("SELECT attname, attname
|
||||
FROM pg_attribute
|
||||
WHERE attrelid = $uniquecon->tableoid
|
||||
AND attnum = $conscol");
|
||||
$indexcols[] = $column->attname;
|
||||
}
|
||||
/// Drop the old UNIQUE CONSTRAINT
|
||||
execute_sql ("ALTER TABLE $uniquecon->relname DROP CONSTRAINT $uniquecon->conname", false);
|
||||
/// Create the new UNIQUE INDEX
|
||||
execute_sql ("CREATE UNIQUE INDEX {$uniquecon->relname}_".implode('_', $indexcols)."_uix ON $uniquecon->relname (".implode(', ', $indexcols).')', false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
// This is compared against the values stored in the database to determine
|
||||
// whether upgrades should be performed (see lib/db/*.php)
|
||||
|
||||
$version = 2006092409; // YYYYMMDD = date
|
||||
$version = 2006092410; // YYYYMMDD = date
|
||||
// XY = increments within a single day
|
||||
|
||||
$release = '1.7 dev'; // Human-friendly version name
|
||||
|
Loading…
x
Reference in New Issue
Block a user