(bug 17964) Don't make namespaceDupes fail if someone actually has an empty interwiki...
[lhc/web/wiklou.git] / maintenance / updaters.inc
index b32e9d3..ddf7ca7 100644 (file)
@@ -150,6 +150,8 @@ $wgUpdates = array(
                array( 'do_active_users_init' ),
                array( 'add_field', 'ipblocks',     'ipb_allow_usertalk',  'patch-ipb_allow_usertalk.sql' ),
                array( 'do_unique_pl_tl_il' ),
+
+               // 1.15
                array( 'add_table', 'change_tag',                          'patch-change_tag.sql' ),
                array( 'add_table', 'tag_summary',                         'patch-change_tag.sql' ),
                array( 'add_table', 'valid_tag',                           'patch-change_tag.sql' ),
@@ -161,6 +163,11 @@ $wgUpdates = array(
                array( 'do_active_users_init' ),
                array( 'add_field', 'ipblocks',     'ipb_allow_usertalk',  'patch-ipb_allow_usertalk.sql' ),
                array( 'sqlite_initial_indexes' ),
+
+               // 1.15
+               array( 'add_table', 'change_tag',                          'patch-change_tag.sql' ),
+               array( 'add_table', 'tag_summary',                         'patch-change_tag.sql' ),
+               array( 'add_table', 'valid_tag',                           'patch-change_tag.sql' ),
        ),
 );
 
@@ -1503,23 +1510,24 @@ function do_postgres_updates() {
                array("archive",       "ar_page_id",           "INTEGER"),
                array("archive",       "ar_parent_id",         "INTEGER"),
                array("image",         "img_sha1",             "TEXT NOT NULL DEFAULT ''"),
+               array("ipblocks",      "ipb_allow_usertalk",   "SMALLINT NOT NULL DEFAULT 0"),
                array("ipblocks",      "ipb_anon_only",        "SMALLINT NOT NULL DEFAULT 0"),
                array("ipblocks",      "ipb_by_text",          "TEXT NOT NULL DEFAULT ''"),
                array("ipblocks",      "ipb_block_email",      "SMALLINT NOT NULL DEFAULT 0"),
                array("ipblocks",      "ipb_create_account",   "SMALLINT NOT NULL DEFAULT 1"),
                array("ipblocks",      "ipb_deleted",          "SMALLINT NOT NULL DEFAULT 0"),
                array("ipblocks",      "ipb_enable_autoblock", "SMALLINT NOT NULL DEFAULT 1"),
-               array("ipblocks",      "ipb_allow_usertalk",   "SMALLINT NOT NULL DEFAULT 0"),
                array("filearchive",   "fa_deleted",           "SMALLINT NOT NULL DEFAULT 0"),
                array("logging",       "log_deleted",          "SMALLINT NOT NULL DEFAULT 0"),
                array("logging",       "log_id",               "INTEGER NOT NULL PRIMARY KEY DEFAULT nextval('log_log_id_seq')"),
                array("logging",       "log_params",           "TEXT"),
                array("mwuser",        "user_editcount",       "INTEGER"),
+               array("mwuser",        "user_hidden",          "SMALLINT NOT NULL DEFAULT 0"),
                array("mwuser",        "user_newpass_time",    "TIMESTAMPTZ"),
                array("oldimage",      "oi_deleted",           "SMALLINT NOT NULL DEFAULT 0"),
-               array("oldimage",      "oi_metadata",          "BYTEA NOT NULL DEFAULT ''"),
-               array("oldimage",      "oi_media_type",        "TEXT"),
                array("oldimage",      "oi_major_mime",        "TEXT NOT NULL DEFAULT 'unknown'"),
+               array("oldimage",      "oi_media_type",        "TEXT"),
+               array("oldimage",      "oi_metadata",          "BYTEA NOT NULL DEFAULT ''"),
                array("oldimage",      "oi_minor_mime",        "TEXT NOT NULL DEFAULT 'unknown'"),
                array("oldimage",      "oi_sha1",              "TEXT NOT NULL DEFAULT ''"),
                array("page_restrictions", "pr_id",            "INTEGER NOT NULL UNIQUE DEFAULT nextval('pr_id_val')"),
@@ -1531,11 +1539,11 @@ function do_postgres_updates() {
                array("recentchanges", "rc_new_len",           "INTEGER"),
                array("recentchanges", "rc_old_len",           "INTEGER"),
                array("recentchanges", "rc_params",            "TEXT"),
-               array("revision",      "rev_len",              "INTEGER"),
                array("revision",      "rev_deleted",          "SMALLINT NOT NULL DEFAULT 0"),
-               array("user_newtalk",  "user_last_timestamp",  "TIMESTAMPTZ"),
-               array("site_stats",    "ss_active_users",      "INTEGER DEFAULT '-1'"),
+               array("revision",      "rev_len",              "INTEGER"),
                array("revision",      "rev_parent_id",        "INTEGER DEFAULT NULL"),
+               array("site_stats",    "ss_active_users",      "INTEGER DEFAULT '-1'"),
+               array("user_newtalk",  "user_last_timestamp",  "TIMESTAMPTZ"),
        );
 
 
@@ -1562,7 +1570,7 @@ function do_postgres_updates() {
                array("ipblocks",     "ipb_enable_autoblock", "smallint", "CASE WHEN ipb_enable_autoblock=' ' THEN 0 ELSE ipb_enable_autoblock::smallint END DEFAULT 1"),
                array("ipblocks",     "ipb_block_email", "smallint", "CASE WHEN ipb_block_email=' ' THEN 0 ELSE ipb_block_email::smallint END DEFAULT 0"),
                array("ipblocks",     "ipb_address",     "text",     "ipb_address::text"),
-               array("ipblocks",     "ipb_deleted",     "smallint", "ipb_deleted::smallint"),
+               array("ipblocks",     "ipb_deleted",     "smallint", "ipb_deleted::smallint DEFAULT 0"),
                array("math",         "math_inputhash",  "bytea",    "decode(math_inputhash,'escape')"),
                array("math",         "math_outputhash", "bytea",    "decode(math_outputhash,'escape')"),
                array("mwuser",       "user_token",      "text",     ""),
@@ -1588,12 +1596,20 @@ function do_postgres_updates() {
                array("user_newtalk", "user_ip",         "text",     "host(user_ip)"),
        );
 
+       # table, column, nullability
+       $nullchanges = array(
+               array("oldimage", "oi_bits",       "NULL"),
+               array("oldimage", "oi_timestamp",  "NULL"),
+               array("oldimage", "oi_major_mime", "NULL"),
+               array("oldimage", "oi_minor_mime", "NULL"),
+       );
+
        $newindexes = array(
                array("archive",       "archive_user_text",  "(ar_user_text)"),
                array("image",         "img_sha1",           "(img_sha1)"),
                array("oldimage",      "oi_sha1",            "(oi_sha1)"),
                array("revision",      "rev_text_id_idx",    "(rev_text_id)"),
-               array("recentchanges", "rc_timestamp_nobot", "(rc_timestamp) WHERE rc_bot = 0"),
+               array("recentchanges", "rc_timestamp_bot",   "(rc_timestamp) WHERE rc_bot = 0"),
                array("templatelinks", "templatelinks_from", "(tl_from)"),
                array("watchlist",     "wl_user",            "(wl_user)"),
        );
@@ -1674,6 +1690,34 @@ function do_postgres_updates() {
                }
        }
 
+       foreach ($nullchanges as $nc) {
+               $fi = $wgDatabase->fieldInfo($nc[0], $nc[1]);
+               if (is_null($fi)) {
+                       wfOut( "... error: expected column $nc[0].$nc[1] to exist\n" );
+                       exit(1);
+               }
+               if ($fi->nullable()) {
+                       ## It's NULL - does it need to be NOT NULL?
+                       if ('NOT NULL' === $nc[2]) {
+                               wfOut( "Changing \"$nc[0].$nc[1]\" to not allow NULLs\n" );
+                               $wgDatabase->query( "ALTER TABLE $nc[0] ALTER $nc[1] SET NOT NULL" );
+                       }
+                       else {
+                               wfOut( "... column \"$nc[0].$nc[1]\" is already set as NULL\n" );
+                       }
+               }
+               else {
+                       ## It's NOT NULL - does it need to be NULL?
+                       if ('NULL' === $nc[2]) {
+                               wfOut( "Changing \"$nc[0].$nc[1]\" to allow NULLs\n" );
+                               $wgDatabase->query( "ALTER TABLE $nc[0] ALTER $nc[1] DROP NOT NULL" );
+                       }
+                       else {
+                               wfOut( "... column \"$nc[0].$nc[1]\" is already set as NOT NULL\n" );
+                       }
+               }
+       }
+
        if ($wgDatabase->fieldInfo('oldimage','oi_deleted')->type() !== 'smallint') {
                wfOut( "Changing \"oldimage.oi_deleted\" to type \"smallint\"\n" );
                $wgDatabase->query( "ALTER TABLE oldimage ALTER oi_deleted DROP DEFAULT" );
@@ -1703,7 +1747,7 @@ function do_postgres_updates() {
        }
 
        if ($wgDatabase->hasConstraint("oldimage_oi_name_fkey")) {
-               wfOut( "Making foriegn key on table \"oldimage\" (to image) a cascade delete\n" );
+               wfOut( "Making foreign key on table \"oldimage\" (to image) a cascade delete\n" );
                $wgDatabase->query( "ALTER TABLE oldimage DROP CONSTRAINT oldimage_oi_name_fkey" );
                $wgDatabase->query( "ALTER TABLE oldimage ADD CONSTRAINT oldimage_oi_name_fkey_cascade ".
                        "FOREIGN KEY (oi_name) REFERENCES image(img_name) ON DELETE CASCADE" );
@@ -1790,7 +1834,12 @@ function do_postgres_updates() {
                        continue;
                }
                wfOut( "Creating index \"$ni[1]\" on table \"$ni[0]\"\n" );
-               dbsource($ni[2]);
+               if ( preg_match( '/^\(/', $ni[2] ) ) {
+                       $wgDatabase->query( "CREATE INDEX $ni[1] ON $ni[0] $ni[2]" );
+               }
+               else {
+                       dbsource($ni[2]);
+               }
        }
 
        # Tweak the page_title tsearch2 trigger to filter out slashes