(bug 33689) Fix incomplete query on constraints
authorsaper <saper@saper.info>
Wed, 28 Mar 2012 21:23:13 +0000 (23:23 +0200)
committersaper <saper@saper.info>
Wed, 28 Mar 2012 21:23:13 +0000 (23:23 +0200)
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
includes/db/DatabasePostgres.php
includes/installer/PostgresUpdater.php

index d300541..962d280 100644 (file)
@@ -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.
index e2b38f5..c7d64eb 100644 (file)
@@ -18,7 +18,7 @@ class PostgresField implements Field {
        static function fromText( $db, $table, $field ) {
                $q = <<<SQL
 SELECT
- attnotnull, attlen, COALESCE(conname, '') AS conname,
+ attnotnull, attlen, conname AS conname,
  COALESCE(condeferred, 'f') AS deferred,
  COALESCE(condeferrable, 'f') AS deferrable,
  CASE WHEN typname = 'int2' THEN 'smallint'
index 6b3cb51..9a982f9 100644 (file)
@@ -514,9 +514,15 @@ END;
                }
                $this->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 );
        }