Making numerous fields unsigned to match their target referenced column
authorReedy <reedy@wikimedia.org>
Wed, 26 Apr 2017 16:08:51 +0000 (17:08 +0100)
committerReedy <reedy@wikimedia.org>
Wed, 6 Sep 2017 18:34:09 +0000 (19:34 +0100)
Bug: T157227
Change-Id: Ic11822d6c893103adcc99a3e188a592f13c968b8

12 files changed:
RELEASE-NOTES-1.30
includes/installer/MysqlUpdater.php
maintenance/archives/patch-bot_passwords-bp_user-unsigned.sql [new file with mode: 0644]
maintenance/archives/patch-change_tag-ct_log_id-unsigned.sql [new file with mode: 0644]
maintenance/archives/patch-change_tag-ct_rev_id-unsigned.sql [new file with mode: 0644]
maintenance/archives/patch-page_restrictions-pr_user-unsigned.sql [new file with mode: 0644]
maintenance/archives/patch-tag_summary-ts_log_id-unsigned.sql [new file with mode: 0644]
maintenance/archives/patch-tag_summary-ts_rev_id-unsigned.sql [new file with mode: 0644]
maintenance/archives/patch-user-newtalk-userid-unsigned.sql [deleted file]
maintenance/archives/patch-user_newtalk-user_id-unsigned.sql [new file with mode: 0644]
maintenance/archives/patch-user_properties-up_user-unsigned.sql [new file with mode: 0644]
maintenance/tables.sql

index b478f51..0b2faec 100644 (file)
@@ -209,6 +209,9 @@ changes to languages because of Phabricator reports.
   (formerly it was needed by PostgreSQL and Oracle), and is now deprecated.
 * (T146591) The lc_lang_key index on the l10n_cache table has been changed into a
   PRIMARY KEY.
+* (T157227) bot_password.bp_user, change_tag.ct_log_id, change_tag.ct_rev_id,
+  page_restrictions.pr_user, tag_summary.ts_log_id, tag_summary.ts_rev_id and
+  user_properties.up_user have all been made unsigned on MySQL.
 
 == Compatibility ==
 MediaWiki 1.30 requires PHP 5.5.9 or later. There is experimental support for
index aeecbb0..2abc6b6 100644 (file)
@@ -266,7 +266,6 @@ class MysqlUpdater extends DatabaseUpdater {
                                'patch-fa_major_mime-chemical.sql' ],
 
                        // 1.25
-                       [ 'doUserNewTalkUseridUnsigned' ],
                        // note this patch covers other _comment and _description fields too
                        [ 'modifyField', 'recentchanges', 'rc_comment', 'patch-editsummary-length.sql' ],
 
@@ -329,6 +328,7 @@ class MysqlUpdater extends DatabaseUpdater {
                        [ 'migrateComments' ],
                        [ 'renameIndex', 'l10n_cache', 'lc_lang_key', 'PRIMARY', false,
                                'patch-l10n_cache-primary-key.sql' ],
+                       [ 'doUnsignedSyncronisation' ],
                ];
        }
 
@@ -1123,26 +1123,42 @@ class MysqlUpdater extends DatabaseUpdater {
                );
        }
 
-       protected function doUserNewTalkUseridUnsigned() {
-               if ( !$this->doTable( 'user_newtalk' ) ) {
-                       return true;
-               }
+       protected function doUnsignedSyncronisation() {
+               $sync = [
+                       [ 'table' => 'bot_passwords', 'field' => 'bp_user' ],
+                       [ 'table' => 'change_tag', 'field' => 'ct_log_id' ],
+                       [ 'table' => 'change_tag', 'field' => 'ct_rev_id' ],
+                       [ 'table' => 'page_restrictions', 'field' => 'pr_user' ],
+                       [ 'table' => 'tag_summary', 'field' => 'ts_log_id' ],
+                       [ 'table' => 'tag_summary', 'field' => 'ts_rev_id' ],
+                       [ 'table' => 'user_newtalk', 'field' => 'user_id' ],
+                       [ 'table' => 'user_properties', 'field' => 'up_user' ],
+               ];
 
-               $info = $this->db->fieldInfo( 'user_newtalk', 'user_id' );
-               if ( $info === false ) {
-                       return true;
-               }
-               if ( $info->isUnsigned() ) {
-                       $this->output( "...user_id is already unsigned int.\n" );
+               foreach ( $sync as $s ) {
+                       if ( !$this->doTable( $s['table'] ) ) {
+                               continue;
+                       }
 
-                       return true;
+                       $info = $this->db->fieldInfo( $s['table'], $s['field'] );
+                       if ( $info === false ) {
+                               continue;
+                       }
+                       $fullName = "{$s['table']}.{$s['field']}";
+                       if ( $info->isUnsigned() ) {
+                               $this->output( "...$fullName is already unsigned int.\n" );
+
+                               continue;
+                       }
+
+                       $this->applyPatch(
+                               "patch-{$s['table']}-{$s['field']}-unsigned.sql",
+                               false,
+                               "Making $fullName into an unsigned int"
+                       );
                }
 
-               return $this->applyPatch(
-                       'patch-user-newtalk-userid-unsigned.sql',
-                       false,
-                       'Making user_id unsigned int'
-               );
+               return true;
        }
 
        protected function doRevisionPageRevIndexNonUnique() {
diff --git a/maintenance/archives/patch-bot_passwords-bp_user-unsigned.sql b/maintenance/archives/patch-bot_passwords-bp_user-unsigned.sql
new file mode 100644 (file)
index 0000000..163609a
--- /dev/null
@@ -0,0 +1 @@
+ALTER TABLE /*_*/bot_passwords MODIFY bp_user int unsigned NOT NULL;
\ No newline at end of file
diff --git a/maintenance/archives/patch-change_tag-ct_log_id-unsigned.sql b/maintenance/archives/patch-change_tag-ct_log_id-unsigned.sql
new file mode 100644 (file)
index 0000000..1371c47
--- /dev/null
@@ -0,0 +1 @@
+ALTER TABLE /*_*/change_tag MODIFY ct_log_id int unsigned NULL;
\ No newline at end of file
diff --git a/maintenance/archives/patch-change_tag-ct_rev_id-unsigned.sql b/maintenance/archives/patch-change_tag-ct_rev_id-unsigned.sql
new file mode 100644 (file)
index 0000000..b7e1f02
--- /dev/null
@@ -0,0 +1 @@
+ALTER TABLE /*_*/change_tag MODIFY ct_rev_id int unsigned NULL;
\ No newline at end of file
diff --git a/maintenance/archives/patch-page_restrictions-pr_user-unsigned.sql b/maintenance/archives/patch-page_restrictions-pr_user-unsigned.sql
new file mode 100644 (file)
index 0000000..2337ff0
--- /dev/null
@@ -0,0 +1 @@
+ALTER TABLE /*_*/page_restrictions MODIFY pr_user int unsigned NULL;
diff --git a/maintenance/archives/patch-tag_summary-ts_log_id-unsigned.sql b/maintenance/archives/patch-tag_summary-ts_log_id-unsigned.sql
new file mode 100644 (file)
index 0000000..617073d
--- /dev/null
@@ -0,0 +1 @@
+ALTER TABLE /*_*/tag_summary MODIFY ts_log_id int unsigned NULL;
\ No newline at end of file
diff --git a/maintenance/archives/patch-tag_summary-ts_rev_id-unsigned.sql b/maintenance/archives/patch-tag_summary-ts_rev_id-unsigned.sql
new file mode 100644 (file)
index 0000000..e6a5bcd
--- /dev/null
@@ -0,0 +1 @@
+ALTER TABLE /*_*/tag_summary MODIFY ts_rev_id int unsigned NULL;
\ No newline at end of file
diff --git a/maintenance/archives/patch-user-newtalk-userid-unsigned.sql b/maintenance/archives/patch-user-newtalk-userid-unsigned.sql
deleted file mode 100644 (file)
index a83e03b..0000000
+++ /dev/null
@@ -1 +0,0 @@
-ALTER TABLE /*_*/user_newtalk MODIFY user_id int unsigned NOT NULL default 0;
diff --git a/maintenance/archives/patch-user_newtalk-user_id-unsigned.sql b/maintenance/archives/patch-user_newtalk-user_id-unsigned.sql
new file mode 100644 (file)
index 0000000..a83e03b
--- /dev/null
@@ -0,0 +1 @@
+ALTER TABLE /*_*/user_newtalk MODIFY user_id int unsigned NOT NULL default 0;
diff --git a/maintenance/archives/patch-user_properties-up_user-unsigned.sql b/maintenance/archives/patch-user_properties-up_user-unsigned.sql
new file mode 100644 (file)
index 0000000..f4f563f
--- /dev/null
@@ -0,0 +1 @@
+ALTER TABLE /*_*/user_properties MODIFY up_user int unsigned NOT NULL;
\ No newline at end of file
index bed80db..1813f6c 100644 (file)
@@ -213,7 +213,7 @@ CREATE INDEX /*i*/un_user_ip ON /*_*/user_newtalk (user_ip);
 --
 CREATE TABLE /*_*/user_properties (
   -- Foreign key to user.user_id
-  up_user int NOT NULL,
+  up_user int unsigned NOT NULL,
 
   -- Name of the option being saved. This is indexed for bulk lookup.
   up_property varbinary(255) NOT NULL,
@@ -231,7 +231,7 @@ CREATE INDEX /*i*/user_properties_property ON /*_*/user_properties (up_property)
 --
 CREATE TABLE /*_*/bot_passwords (
   -- User ID obtained from CentralIdLookup.
-  bp_user int NOT NULL,
+  bp_user int unsigned NOT NULL,
 
   -- Application identifier
   bp_app_id varbinary(32) NOT NULL,
@@ -1640,7 +1640,7 @@ CREATE TABLE /*_*/page_restrictions (
   -- Whether or not to cascade the protection down to pages transcluded.
   pr_cascade tinyint NOT NULL,
   -- Field for future support of per-user restriction.
-  pr_user int NULL,
+  pr_user int unsigned NULL,
   -- Field for time-limited protection.
   pr_expiry varbinary(14) NULL
 ) /*$wgDBTableOptions*/;
@@ -1692,9 +1692,9 @@ CREATE TABLE /*_*/change_tag (
   -- RCID for the change
   ct_rc_id int NULL,
   -- LOGID for the change
-  ct_log_id int NULL,
+  ct_log_id int unsigned NULL,
   -- REVID for the change
-  ct_rev_id int NULL,
+  ct_rev_id int unsigned NULL,
   -- Tag applied
   ct_tag varchar(255) NOT NULL,
   -- Parameters for the tag, presently unused
@@ -1715,9 +1715,9 @@ CREATE TABLE /*_*/tag_summary (
   -- RCID for the change
   ts_rc_id int NULL,
   -- LOGID for the change
-  ts_log_id int NULL,
+  ts_log_id int unsigned NULL,
   -- REVID for the change
-  ts_rev_id int NULL,
+  ts_rev_id int unsigned NULL,
   -- Comma-separated list of tags
   ts_tags blob NOT NULL
 ) /*$wgDBTableOptions*/;