Schema change: change cl_type from ENUM('page', 'subcat', 'file') to varchar(6)....
authorRoan Kattouw <catrope@users.mediawiki.org>
Sun, 13 Mar 2011 10:35:06 +0000 (10:35 +0000)
committerRoan Kattouw <catrope@users.mediawiki.org>
Sun, 13 Mar 2011 10:35:06 +0000 (10:35 +0000)
This commit does not include a patch for SQLite, because ALTER TABLE MODIFY is apparently not supported by SQLite as far as I could tell by Googling. Leaving resolution of this issue for SQLite to the SQLite experts; maybe SQLite's enum implementation is saner than MySQL and it doesn't even need this schema change, I don't know.

includes/installer/MysqlUpdater.php
maintenance/archives/patch-cl_type.sql [new file with mode: 0644]
maintenance/tables.sql

index c3186f2..db9f9c5 100644 (file)
@@ -175,6 +175,7 @@ class MysqlUpdater extends DatabaseUpdater {
                        array( 'dropIndex', 'archive', 'ar_page_revid',         'patch-archive_kill_ar_page_revid.sql' ),
                        array( 'addIndex', 'archive', 'ar_revid',               'patch-archive_ar_revid.sql' ),
                        array( 'doLangLinksLengthUpdate' ),
+                       array( 'doClTypeVarcharUpdate' ),
                );
        }
 
@@ -828,4 +829,18 @@ class MysqlUpdater extends DatabaseUpdater {
                        $this->output( "...ll_lang is up-to-date.\n" );
                }
        }
+       
+       protected function doClTypeVarcharUpdate() {
+               $categorylinks = $this->db->tableName( 'categorylinks' );
+               $res = $this->db->query( "SHOW COLUMNS FROM $categorylinks LIKE 'cl_type'" );
+               $row = $this->db->fetchObject( $res );
+               
+               if ( $row && substr( $row->Type, 0, 4 ) == 'enum' ) {
+                       $this->output( 'Changing cl_type from enum to varchar...' );
+                       $this->applyPatch( 'patch-cl_type.sql' );
+                       $this->output( "done.\n" );
+               } else {
+                       $this->output( "...cl_type is up-to-date.\n" );
+               }
+       }
 }
diff --git a/maintenance/archives/patch-cl_type.sql b/maintenance/archives/patch-cl_type.sql
new file mode 100644 (file)
index 0000000..0eefa02
--- /dev/null
@@ -0,0 +1,6 @@
+--
+-- Change cl_type to a varchar from an enum because of the weird semantics of
+-- the < and > operators when working with enums
+--
+
+ALTER TABLE categorylinks MODIFY cl_type varchar(6) NOT NULL default 'page';
index 11392f1..99b70e4 100644 (file)
@@ -521,7 +521,9 @@ CREATE TABLE /*_*/categorylinks (
   -- paginate the three categories separately.  This never has to be updated
   -- after the page is created, since none of these page types can be moved to
   -- any other.
-  cl_type ENUM('page', 'subcat', 'file') NOT NULL default 'page'
+  -- This used to be ENUM('page', 'subcat', 'file') but was changed to a
+  -- varchar because of the weird semantics of < and > when used on enums
+  cl_type varchar(6) NOT NULL default 'page'
 ) /*$wgDBTableOptions*/;
 
 CREATE UNIQUE INDEX /*i*/cl_from ON /*_*/categorylinks (cl_from,cl_to);