Merge "[schema] Make column user_newtalk.user_id an unsigned int"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Tue, 17 Feb 2015 17:44:43 +0000 (17:44 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Tue, 17 Feb 2015 17:44:43 +0000 (17:44 +0000)
includes/db/DatabaseMysqlBase.php
includes/installer/MysqlUpdater.php
maintenance/archives/patch-user-newtalk-userid-unsigned.sql [new file with mode: 0644]
maintenance/tables.sql

index 458b286..c1f2969 100644 (file)
@@ -1201,6 +1201,7 @@ class MySQLField implements Field {
                $this->is_multiple = $info->multiple_key;
                $this->is_key = ( $this->is_pk || $this->is_unique || $this->is_multiple );
                $this->type = $info->type;
+               $this->flags = $info->flags;
                $this->binary = isset( $info->binary ) ? $info->binary : false;
        }
 
@@ -1250,6 +1251,13 @@ class MySQLField implements Field {
                return $this->is_multiple;
        }
 
+       /**
+        * @return int
+        */
+       function flags() {
+               return $this->flags;
+       }
+
        function isBinary() {
                return $this->binary;
        }
index 81f563a..eada44a 100644 (file)
@@ -270,6 +270,7 @@ class MysqlUpdater extends DatabaseUpdater {
                        array( 'dropTable', 'hitcounter' ),
                        array( 'dropField', 'site_stats', 'ss_total_views', 'patch-drop-ss_total_views.sql' ),
                        array( 'dropField', 'page', 'page_counter', 'patch-drop-page_counter.sql' ),
+                       array( 'doUserNewTalkUseridUnsigned' ),
                );
        }
 
@@ -1062,4 +1063,26 @@ class MysqlUpdater extends DatabaseUpdater {
                        'Making iwl_prefix_title_from index non-UNIQUE'
                );
        }
+
+       protected function doUserNewTalkUseridUnsigned() {
+               if ( !$this->doTable( 'user_newtalk' ) ) {
+                       return true;
+               }
+
+               $info = $this->db->fieldInfo( 'user_newtalk', 'user_id' );
+               if ( $info === false ) {
+                       return true;
+               }
+               if ( ( $info->flags() & 32 /*MYSQLI_UNSIGNED_FLAG*/ ) ) {
+                       $this->output( "...user_id is already unsigned int.\n" );
+
+                       return true;
+               }
+
+               return $this->applyPatch(
+                       'patch-user-newtalk-userid-unsigned.sql',
+                       false,
+                       'Making user_id unsigned int'
+               );
+       }
 }
diff --git a/maintenance/archives/patch-user-newtalk-userid-unsigned.sql b/maintenance/archives/patch-user-newtalk-userid-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;
index 112ac05..4433502 100644 (file)
@@ -182,7 +182,7 @@ CREATE UNIQUE INDEX /*i*/ufg_user_group ON /*_*/user_former_groups (ufg_user,ufg
 --
 CREATE TABLE /*_*/user_newtalk (
   -- Key to user.user_id
-  user_id int NOT NULL default 0,
+  user_id int unsigned NOT NULL default 0,
   -- If the user is an anonymous user their IP address is stored here
   -- since the user_id of 0 is ambiguous
   user_ip varbinary(40) NOT NULL default '',