From fa6ab166863f911e927720878763cda7e945f96d Mon Sep 17 00:00:00 2001 From: saper Date: Wed, 28 Mar 2012 23:23:13 +0200 Subject: [PATCH] (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 --- RELEASE-NOTES-1.20 | 2 ++ includes/db/DatabasePostgres.php | 2 +- includes/installer/PostgresUpdater.php | 12 +++++++++--- 3 files changed, 12 insertions(+), 4 deletions(-) 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 ); } -- 2.20.1