Jjanes has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/178271

Change subject: PostgreSQL: Drop unneeded foreign key constraint
......................................................................

PostgreSQL: Drop unneeded foreign key constraint

Change I1c7f3a84f10df05d6b37dccbad4c8232edf51580 causes
an existing foreign key assumption (under PostgreSQL) to be
violated upon deleting a page.  This foreign key assumption does not
explicitly exist in MySQL, and is not implied via documentation.  So
it was probably never needed in the first place.

Don't create the foreign key constraint in PostgreSQL, and drop it
if it already exists when running update.php.

The constraint was previously created with an implicit name, so
drop the constraint involving the specified column name (rc_cur_id),
rather than hard-coding the name of the constraint itself.

This bug probably exists under Oracle and MSSQL as well, but no attempt
was made to address it there.

Bug: T76254
Change-Id: I2abd650c8ce83c5b725aec0545fff14a927a305a
---
M includes/installer/PostgresUpdater.php
M maintenance/postgres/tables.sql
2 files changed, 22 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/71/178271/1

diff --git a/includes/installer/PostgresUpdater.php 
b/includes/installer/PostgresUpdater.php
index 9e8ee94..e2ee3b6 100644
--- a/includes/installer/PostgresUpdater.php
+++ b/includes/installer/PostgresUpdater.php
@@ -418,6 +418,9 @@
                        array( 'addPgField', 'pagelinks', 'pl_from_namespace', 
'INTEGER NOT NULL DEFAULT 0' ),
                        array( 'addPgField', 'templatelinks', 
'tl_from_namespace', 'INTEGER NOT NULL DEFAULT 0' ),
                        array( 'addPgField', 'imagelinks', 'il_from_namespace', 
'INTEGER NOT NULL DEFAULT 0' ),
+
+                       // 1.24.1
+                       array( 'dropFkey', 'recentchanges', 'rc_cur_id' )
                );
        }
 
@@ -769,6 +772,24 @@
                }
        }
 
+       protected function dropFkey( $table, $field ) {
+               $fi = $this->db->fieldInfo( $table, $field );
+               if ( is_null( $fi ) ) {
+                       $this->output( "WARNING! Column '$table.$field' does 
not exist but it should! " .
+                               "Please report this.\n" );
+                       return;
+               }
+               $conname = $fi->conname();
+               if ( $fi->conname() ) {
+                       $this->output( "Dropping foreign key constraint on 
'$table.$field'\n" );
+                       $conclause = "CONSTRAINT \"$conname\"";
+                       $command = "ALTER TABLE $table DROP CONSTRAINT 
$conname";
+                       $this->db->query( $command );
+               } else {
+                       $this->output( "Foreign key constraint on 
'$table.$field' already does not exist\n" );
+               };
+       }
+
        protected function changeFkeyDeferrable( $table, $field, $clause ) {
                $fi = $this->db->fieldInfo( $table, $field );
                if ( is_null( $fi ) ) {
diff --git a/maintenance/postgres/tables.sql b/maintenance/postgres/tables.sql
index 400050e..12e357f 100644
--- a/maintenance/postgres/tables.sql
+++ b/maintenance/postgres/tables.sql
@@ -421,7 +421,7 @@
   rc_minor           SMALLINT     NOT NULL  DEFAULT 0,
   rc_bot             SMALLINT     NOT NULL  DEFAULT 0,
   rc_new             SMALLINT     NOT NULL  DEFAULT 0,
-  rc_cur_id          INTEGER          NULL  REFERENCES page(page_id) ON DELETE 
SET NULL DEFERRABLE INITIALLY DEFERRED,
+  rc_cur_id          INTEGER          NULL,
   rc_this_oldid      INTEGER      NOT NULL,
   rc_last_oldid      INTEGER      NOT NULL,
   rc_type            SMALLINT     NOT NULL  DEFAULT 0,

-- 
To view, visit https://gerrit.wikimedia.org/r/178271
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I2abd650c8ce83c5b725aec0545fff14a927a305a
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Jjanes <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to