From 26b82be252bab3775f00365ae09f97149236e736 Mon Sep 17 00:00:00 2001 From: stronk7 Date: Sun, 24 Sep 2006 22:14:23 +0000 Subject: [PATCH] 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) --- lib/db/postgres7.php | 31 +++++++++++++++++++++++++++++++ version.php | 2 +- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/lib/db/postgres7.php b/lib/db/postgres7.php index 2fe94a979c..73f6b8f6f9 100644 --- a/lib/db/postgres7.php +++ b/lib/db/postgres7.php @@ -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; } diff --git a/version.php b/version.php index 7b55067aee..c169f54635 100644 --- a/version.php +++ b/version.php @@ -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 -- 2.39.5