[Fusionforge-commits] r7764 - branches/Branch_4_8/gforge/db
Guillaume Smet
gsmet at libremir.placard.fr.eu.org
Sun Jun 7 21:12:38 CEST 2009
Author: gsmet
Date: 2009-06-07 21:12:38 +0200 (Sun, 07 Jun 2009)
New Revision: 7764
Modified:
branches/Branch_4_8/gforge/db/upgrade-db.php
Log:
last fixes for the upgrade path from 4.0.2 to 4.8
Modified: branches/Branch_4_8/gforge/db/upgrade-db.php
===================================================================
--- branches/Branch_4_8/gforge/db/upgrade-db.php 2009-06-07 18:12:01 UTC (rev 7763)
+++ branches/Branch_4_8/gforge/db/upgrade-db.php 2009-06-07 19:12:38 UTC (rev 7764)
@@ -216,7 +216,7 @@
// Else, we just add it up
} else {
if (trim($q) != '') {
- $queries[] = trim($q);
+ $queries[] = trim(preg_replace("/\s+/", ' ', str_replace("\n", ' ', $q)));
}
}
}
@@ -258,6 +258,7 @@
} else {
print_r($aux);
}
+ // Check if it is a DROP INDEX
} else if (in_string($query, 'drop index')) {
$aux = explode(' ', trim($query));
if (count($aux) == 3 || count($aux) == 4) { // PERFECT!
@@ -265,6 +266,13 @@
} else {
print_r($aux);
}
+ // Check if it is a DROP CONSTRAINT
+ } else if (in_string($query, 'alter table') && in_string($query, 'drop constraint')) {
+ $aux = explode(' ', trim($query));
+ $table = trim($aux[2], "\" ");
+ $constraint = trim($aux[5], "\" ");
+
+ drop_constraint_if_exists($table, $constraint, $query);
} else {
$res = db_query($query);
if (!$res) {
@@ -414,6 +422,21 @@
return true;
}
+function drop_constraint_if_exists($table, $constraint, $query) {
+ $res = db_query("SELECT COUNT(*) AS exists FROM information_schema.constraint_table_usage WHERE table_name='$table' AND constraint_name='$constraint'");
+ if (!$res) {
+ show("ERROR:".db_error()."\n");
+ return false;
+ }
+ if (db_result($res, 0, 'exists') != '0') {
+ $res = db_query($query);
+ if (!$res) {
+ show("ERROR:".db_error()."\n");
+ }
+ }
+ return true;
+}
+
function drop_trigger_if_exists($name, $on) {
$res = db_query("SELECT COUNT(*) AS exists FROM pg_trigger WHERE tgname='$name'");
if (!$res) {
@@ -447,4 +470,4 @@
fwrite(STDOUT, $text);
}
-?>
+?>
\ No newline at end of file
More information about the Fusionforge-commits
mailing list