From: saper Date: Wed, 28 Mar 2012 21:23:13 +0000 (+0200) Subject: (bug 33689) Fix incomplete query on constraints X-Git-Tag: 1.31.0-rc.0~24101^2 X-Git-Url: https://git.cyclocoop.org/%7B%24admin_url%7Dmembres/cotisations/rappels.php?a=commitdiff_plain;h=fa6ab166863f911e927720878763cda7e945f96d;p=lhc%2Fweb%2Fwiklou.git (bug 33689) Fix incomplete query on constraints Upgrade to 1.19 on Postgres fails due to incomplete query when trying to defer foreign key for externallinks * FieldInfo::conname() should return NULL not "" when constraint is not present * Re-create missing constraint on schema update Change-Id: I7ca351e07d228afdf4a5c3bef365f42a27c9ac45 --- diff --git a/RELEASE-NOTES-1.20 b/RELEASE-NOTES-1.20 index d300541ec2..962d280358 100644 --- a/RELEASE-NOTES-1.20 +++ b/RELEASE-NOTES-1.20 @@ -51,6 +51,8 @@ production. usages of -s and -n parameters depending on compression type * (bug 13896) Rendering of devanagari numbers in automatic '#' number lists * (bug 18704) Add an unique CSS class or ID to the tagfilter table row at RecentChanges +* (bug 33689) Upgrade to 1.19 on Postgres fails due to incomplete query when + trying to defer foreign key for externallinks === API changes in 1.20 === * (bug 34316) Add ability to retrieve maximum upload size from MediaWiki API. diff --git a/includes/db/DatabasePostgres.php b/includes/db/DatabasePostgres.php index e2b38f5203..c7d64eb2ab 100644 --- a/includes/db/DatabasePostgres.php +++ b/includes/db/DatabasePostgres.php @@ -18,7 +18,7 @@ class PostgresField implements Field { static function fromText( $db, $table, $field ) { $q = <<output( "Altering column '$table.$field' to be DEFERRABLE INITIALLY DEFERRED\n" ); $conname = $fi->conname(); - $command = "ALTER TABLE $table DROP CONSTRAINT $conname"; - $this->db->query( $command ); - $command = "ALTER TABLE $table ADD CONSTRAINT $conname FOREIGN KEY ($field) REFERENCES $clause DEFERRABLE INITIALLY DEFERRED"; + if ( $fi->conname() ) { + $conclause = "CONSTRAINT \"$conname\""; + $command = "ALTER TABLE $table DROP CONSTRAINT $conname"; + $this->db->query( $command ); + } else { + $this->output( "Column '$table.$field' does not have a foreign key constraint, will be added\n" ); + $conclause = ""; + } + $command = "ALTER TABLE $table ADD $conclause FOREIGN KEY ($field) REFERENCES $clause DEFERRABLE INITIALLY DEFERRED"; $this->db->query( $command ); }