API: documentation and cleanup.
[lhc/web/wiklou.git] / maintenance / updaters.inc
index b3aaabb..e46ec69 100644 (file)
@@ -63,12 +63,19 @@ $wgNewFields = array(
        array( 'ipblocks',      'ipb_range_start',  'patch-ipb_range_start.sql' ),
        array( 'site_stats',    'ss_images',        'patch-ss_images.sql' ),
        array( 'ipblocks',      'ipb_anon_only',    'patch-ipb_anon_only.sql' ),
-       array( 'ipblocks',      'ipb_enable_autoblock', 'patch-ipb_optional_autoblock.sql' ),
+       array( 'ipblocks',              'ipb_enable_autoblock', 'patch-ipb_optional_autoblock.sql' ),
        array( 'user',          'user_newpass_time','patch-user_newpass_time.sql' ),
        array( 'user',          'user_editcount',   'patch-user_editcount.sql' ),
-       array( 'logging',       'log_id',               'patch-log_id.sql' ),
+       array( 'recentchanges', 'rc_deleted',           'patch-rc_deleted.sql' ),
+       array( 'logging',               'log_id',                       'patch-log_id.sql' ),
+       array( 'logging',               'log_deleted',          'patch-log_deleted.sql' ),
+       array( 'archive',               'ar_deleted',           'patch-ar_deleted.sql' ),
+       array( 'ipblocks',              'ipb_deleted',          'patch-ipb_deleted.sql' ),
+       array( 'filearchive',   'fa_deleted',           'patch-fa_deleted.sql' ),
+       array( 'revision',          'rev_len',          'patch-rev_len.sql' ),
+       array( 'archive',           'ar_len',           'patch-ar_len.sql' ),
+       array( 'revision',          'rev_parent_id',    'patch-rev_parent_id.sql' ),
        array( 'page_restrictions', 'pr_id',            'patch-page_restrictions_sortkey.sql' ),
-       array( 'revision',      'rev_len',              'patch-rev_len.sql' ),
 );
 
 function rename_table( $from, $to, $patch ) {
@@ -166,7 +173,7 @@ function do_index_update() {
        # Check that proper indexes are in place
        global $wgDatabase;
        $meta = $wgDatabase->fieldInfo( "recentchanges", "rc_timestamp" );
-       if( $meta->multiple_key == 0 ) {
+       if( !$meta->isMultipleKey() ) {
                echo "Updating indexes to 20031107: ";
                dbsource( archive("patch-indexes.sql") );
                echo "ok\n";
@@ -180,7 +187,7 @@ function do_image_index_update() {
        global $wgDatabase;
 
        $meta = $wgDatabase->fieldInfo( "image", "img_major_mime" );
-       if( $meta->multiple_key == 0 ) {
+       if( !$meta->isMultipleKey() ) {
                echo "Updating indexes to 20050912: ";
                dbsource( archive("patch-mimesearch-indexes.sql") );
                echo "ok\n";
@@ -414,7 +421,8 @@ function do_schema_restructuring() {
                        rev_timestamp char(14) binary NOT NULL default '',
                        rev_minor_edit tinyint(1) unsigned NOT NULL default '0',
                        rev_deleted tinyint(1) unsigned NOT NULL default '0',
-
+                       rev_len int(8) unsigned,
+                       rev_parent_id int(8) unsigned default NULL,
                        PRIMARY KEY rev_page_id (rev_page, rev_id),
                        UNIQUE INDEX rev_id (rev_id),
                        INDEX rev_timestamp (rev_timestamp),
@@ -671,7 +679,7 @@ function do_user_groups_reformat() {
        global $wgDatabase;
        $info = $wgDatabase->fieldInfo( 'user_groups', 'ug_group' );
 
-       if( $info->type == 'int' ) {
+       if( $info->type() == 'int' ) {
                $oldug = $wgDatabase->tableName( 'user_groups' );
                $newug = $wgDatabase->tableName( 'user_groups_bogus' );
                echo "user_groups is in bogus intermediate format. Renaming to $newug... ";
@@ -698,7 +706,7 @@ function do_watchlist_null() {
        global $wgDatabase;
        $info = $wgDatabase->fieldInfo( 'watchlist', 'wl_notificationtimestamp' );
 
-       if( $info->not_null ) {
+       if( !$info->nullable() ) {
                echo "Making wl_notificationtimestamp nullable... ";
                dbsource( archive( 'patch-watchlist-null.sql' ), $wgDatabase );
                echo "ok\n";
@@ -956,12 +964,14 @@ function do_restrictions_update() {
 
        $name = 'page_restrictions';
        $patch = 'patch-page_restrictions.sql';
+       $patch2 = 'patch-page_restrictions_sortkey.sql';
 
        if ( $wgDatabase->tableExists( $name ) ) {
                echo "...$name table already exists.\n";
        } else {
                echo "Creating $name table...";
                dbsource( archive($patch), $wgDatabase );
+               dbsource( archive($patch2), $wgDatabase );
                echo "ok\n";
 
                echo "Migrating old restrictions to new table...";
@@ -1011,7 +1021,8 @@ function do_restrictions_update() {
                                $wgDatabase->insert( 'page_restrictions', array ( 'pr_page' => $id,
                                                                                        'pr_type' => $type,
                                                                                        'pr_level' => $level,
-                                                                                       'pr_cascade' => 0 ),
+                                                                                       'pr_cascade' => 0,
+                                                                                       'pr_expiry' => 'infinity' ),
                                                                                        __METHOD__ );
                        }
                }
@@ -1098,206 +1109,172 @@ END;
 }
 
 function
-pg_column_has_type($table, $column, $wanttype)
-{
-global $wgDatabase, $wgDBname, $wgDBmwschema;
-
-       $q = <<<END
-SELECT typname FROM pg_class, pg_namespace, pg_attribute, pg_type
-       WHERE relnamespace=pg_namespace.oid AND relkind='r'
-             AND attrelid=pg_class.oid AND atttypid=pg_type.oid
-             AND nspname=%s AND relname=%s AND attname=%s;
-END;
-       $res = $wgDatabase->query(sprintf($q,
-                       $wgDatabase->addQuotes($wgDBmwschema),
-                       $wgDatabase->addQuotes($table),
-                       $wgDatabase->addQuotes($column)));
-       $row = $wgDatabase->fetchRow($res);
-       $istype = false;
-       if ($row)
-               $istype = $row[0] === $wanttype;
-       $wgDatabase->freeResult($res);
-       return $istype;
-}
-
-function
-pg_column_exists($table, $column)
-{
-global $wgDatabase, $wgDBname, $wgDBmwschema;
-
-       $q = <<<END
-SELECT 1 FROM pg_class, pg_namespace, pg_attribute
-       WHERE relnamespace=pg_namespace.oid AND relkind='r'
-             AND attrelid=pg_class.oid
-             AND nspname=%s AND relname=%s AND attname=%s;
-END;
-       $res = $wgDatabase->query(sprintf($q,
-                       $wgDatabase->addQuotes($wgDBmwschema),
-                       $wgDatabase->addQuotes($table),
-                       $wgDatabase->addQuotes($column)));
-       $row = $wgDatabase->fetchRow($res);
-       $exists = !!$row;
-       $wgDatabase->freeResult($res);
-       return $exists;
-}
-
-function
-pg_column_is_nullable($table, $column)
+pg_index_exists($table, $index)
 {
-global $wgDatabase, $wgDBname, $wgDBmwschema;
-
-       $q = <<<END
-SELECT attnotnull FROM pg_class, pg_namespace, pg_attribute
-       WHERE relnamespace=pg_namespace.oid AND relkind='r'
-             AND attrelid=pg_class.oid
-             AND nspname=%s AND relname=%s AND attname=%s;
-END;
-       $res = $wgDatabase->query(sprintf($q,
-                       $wgDatabase->addQuotes($wgDBmwschema),
-                       $wgDatabase->addQuotes($table),
-                       $wgDatabase->addQuotes($column)));
-       $row = $wgDatabase->fetchRow($res);
-       $nullable = ($row[0] === 'f');
-       $wgDatabase->freeResult($res);
-       return $nullable;
+global $wgDatabase, $wgDBmwschema;
+       $exists = $wgDatabase->selectField("pg_indexes", "indexname",
+                       array(  "indexname" => $index,
+                               "tablename" => $table,
+                               "schemaname" => $wgDBmwschema));
+       return $exists === $index;
 }
 
 function
-pg_table_exists($table)
+pg_fkey_deltype($fkey)
 {
-global $wgDatabase, $wgDBname, $wgDBmwschema;
-
+global $wgDatabase, $wgDBmwschema;
        $q = <<<END
-SELECT 1 FROM pg_class, pg_namespace
-       WHERE relnamespace=pg_namespace.oid AND relkind='r'
-             AND nspname=%s AND relname=%s
+SELECT confdeltype FROM pg_constraint, pg_namespace
+       WHERE connamespace=pg_namespace.oid
+         AND nspname=%s
+         AND conname=%s;
 END;
-       $res = $wgDatabase->query(sprintf($q,
-                       $wgDatabase->addQuotes($wgDBmwschema),
-                       $wgDatabase->addQuotes($table)));
-       $row = $wgDatabase->fetchRow($res);
-       $exists = !!$row;
-       $wgDatabase->freeResult($res);
-       return $exists;
+       $r = $wgDatabase->query(sprintf($q,
+               $wgDatabase->addQuotes($wgDBmwschema),
+               $wgDatabase->addQuotes($fkey)));
+       if (!($row = $wgDatabase->fetchRow($r)))
+               return null;
+       return $row[0];
 }
 
 function
-pg_trigger_exists($table, $trigger)
+pg_rule_def($table, $rule)
 {
-global $wgDatabase, $wgDBname, $wgDBmwschema;
-
+global $wgDatabase, $wgDBmwschema;
        $q = <<<END
-SELECT 1 FROM pg_class, pg_namespace, pg_trigger
-       WHERE relnamespace=pg_namespace.oid AND relkind='r'
-             AND tgrelid=pg_class.oid
-             AND nspname=%s AND relname=%s AND tgname=%s
+SELECT definition FROM pg_rules
+       WHERE schemaname = %s
+         AND tablename = %s
+         AND rulename = %s
 END;
-       $res = $wgDatabase->query(sprintf($q,
+       $r = $wgDatabase->query(sprintf($q,
                        $wgDatabase->addQuotes($wgDBmwschema),
                        $wgDatabase->addQuotes($table),
-                       $wgDatabase->addQuotes($trigger)));
-       $row = $wgDatabase->fetchRow($res);
-       $exists = !!$row;
-       $wgDatabase->freeResult($res);
-       return $exists;
-}
-
-
-function
-pg_index_exists($table, $index)
-{
-global $wgDatabase, $wgDBmwschema;
-       $exists = $wgDatabase->selectField("pg_indexes", "indexname",
-                       array(  "indexname" => $index,
-                               "tablename" => $table,
-                               "schemaname" => $wgDBmwschema));
-       return $exists === $index;
-}
-
-function
-pg_rule_exists($table, $rule)
-{
-global $wgDatabase, $wgDBmwschema;
-       $exists = $wgDatabase->selectField("pg_rules", "rulename",
-                       array(  "rulename" => $rule,
-                               "tablename" => $table,
-                               "schemaname" => $wgDBmwschema));
-       return $exists === $rule;
+                       $wgDatabase->addQuotes($rule)));
+       $row = $wgDatabase->fetchRow($r);
+       if (!$row)
+               return null;
+       $d = $row[0];
+       $wgDatabase->freeResult($r);
+       return $d;
 }
 
 function do_postgres_updates() {
-       global $wgDatabase, $wgVersion, $wgDBmwschema;
+       global $wgDatabase, $wgVersion, $wgDBmwschema, $wgDBts2schema, $wgShowExceptionDetails, $wgDBuser;
 
-       # Just in case their LocalSetings.php does not have this:
+       $wgShowExceptionDetails = 1;
+
+       # Just in case their LocalSettings.php does not have this:
        if ( !isset( $wgDBmwschema ))
                $wgDBmwschema = 'mediawiki';
 
-       ## Default to the oldest supported version
-       $version = 1.7;
-
-       $thisver = array();
-       if ($wgDatabase->tableExists("mediawiki_version")) {
-               $version = "1.8";
-               $sql = "SELECT mw_version FROM mediawiki_version ORDER BY cdate DESC LIMIT 1";
-               $tempversion = pg_fetch_result($wgDatabase->doQuery($sql),0,0);
-               if (preg_match('/(\d+\.\d+)/', $tempversion, $thisver)) {
-                       $version = $thisver[1];
-               }
+       # Verify that this user is configured correctly
+       $safeuser = $wgDatabase->addQuotes($wgDBuser);
+       $SQL = "SELECT array_to_string(useconfig,'*') FROM pg_user WHERE usename = $safeuser";
+       $config = pg_fetch_result( $wgDatabase->doQuery( $SQL ), 0, 0 );
+       $conf = array();
+       foreach( explode( '*', $config ) as $c ) {
+               list( $x,$y ) = explode( '=', $c );
+               $conf[$x] = $y;
        }
-
-       print " Detected version: $version\n";
-
-       ## Transform to a standard format
-       if (! preg_match('/(\d+)\.(\d+)/', $version, $thisver)) {
-               die ("Sorry, could not figure out what version \"$version\" means");
+       $newpath = array();
+       if( !array_key_exists( 'search_path', $conf ) or strpos( $conf['search_path'],$wgDBmwschema ) === false ) {
+               print "Adding in schema \"$wgDBmwschema\" to search_path for user \"$wgDBuser\"\n";
+               $newpath[$wgDBmwschema] = 1;
        }
-       $oldversion = $version;
-       $version = sprintf("%d%03d",$thisver[1],$thisver[2]);
-       print " Standardized version: $version\n";
-
-       $upgrade = '';
-
-       $typechanges = array(
-               array("oldimage",     "oi_size",    "int4"),
-               array("oldimage",     "oi_width",   "int4"),
-               array("oldimage",     "oi_height",  "int4"),
-               array("image",        "img_size",   "int4"),
-               array("image",        "img_width",  "int4"),
-               array("image",        "img_height", "int4"),
+       if( !array_key_exists( 'search_path', $conf ) or strpos( $conf['search_path'],$wgDBts2schema ) === false ) {
+               print "Adding in schema \"$wgDBts2schema\" to search_path for user \"$wgDBuser\"\n";
+               $newpath[$wgDBts2schema] = 1;
+       }
+       $searchpath = implode( ',', array_keys( $newpath ) );
+       if( strlen( $searchpath ) ) {
+               $wgDatabase->doQuery( "ALTER USER $wgDBuser SET search_path = $searchpath" );
+       }
+       $goodconf = array(
+               'client_min_messages' => 'error',
+               'DateStyle'           => 'ISO, YMD',
+               'TimeZone'            => 'GMT'
        );
+       foreach( array_keys( $goodconf ) AS $key ) {
+               $value = $goodconf[$key];
+               if( !array_key_exists( $key, $conf ) or $conf[$key] !== $value ) {
+                       print "Setting $key to '$value' for user \"$wgDBuser\"\n";
+                       $wgDatabase->doQuery( "ALTER USER $wgDBuser SET $key = '$value'" );
+               }
+       }
 
-       $newcols = array(
-               array("mwuser",        "user_newpass_time",    "TIMESTAMPTZ"),
-               array("mwuser",        "user_editcount",       "INTEGER"),
-               array("ipblocks",      "ipb_anon_only",        "CHAR NOT NULL DEFAULT '0'"),
-               array("ipblocks",      "ipb_create_account",   "CHAR NOT NULL DEFAULT '1'"),
-               array("ipblocks",      "ipb_enable_autoblock", "CHAR NOT NULL DEFAULT '1'"),
-               array("recentchanges", "rc_old_len",           "INT"),
-               array("recentchanges", "rc_new_len",           "INT"),
-               array("revision",      "rev_len",              "INT")
+       $newsequences = array(
+               "log_log_id_seq",
+               "pr_id_val",
        );
 
        $newtables = array(
+               array("mediawiki_version", "patch-mediawiki_version.sql"),
                array("mwuser",            "patch-mwuser.sql"),
                array("pagecontent",       "patch-pagecontent.sql"),
                array("querycachetwo",     "patch-querycachetwo.sql"),
-               array("redirect",          "patch-redirect.sql"),
                array("page_restrictions", "patch-page_restrictions.sql"),
                array("profiling",         "patch-profiling.sql"),
-               array("mediawiki_version", "patch-mediawiki_version.sql"),
-               array("archive2",          "patch-archive2.sql")
+               array("redirect",          "patch-redirect.sql"),
+       );
+
+       $newcols = array(
+               array("archive",       "ar_len",               "INTEGER"),
+               array("ipblocks",      "ipb_anon_only",        "CHAR NOT NULL DEFAULT '0'"),
+               array("ipblocks",      "ipb_create_account",   "CHAR NOT NULL DEFAULT '1'"),
+               array("ipblocks",      "ipb_deleted",          "INTEGER NOT NULL DEFAULT 0"),
+               array("ipblocks",      "ipb_enable_autoblock", "CHAR NOT NULL DEFAULT '1'"),
+               array("filearchive",   "fa_deleted",           "INTEGER NOT NULL DEFAULT 0"),
+               array("logging",       "log_deleted",          "INTEGER 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_newpass_time",    "TIMESTAMPTZ"),
+               array("page_restrictions", "pr_id",            "INTEGER NOT NULL UNIQUE DEFAULT nextval('pr_id_val')"),
+               array("recentchanges", "rc_deleted",           "INTEGER NOT NULL DEFAULT 0"),
+               array("recentchanges", "rc_log_action",        "TEXT"),
+        array("recentchanges", "rc_log_type",          "TEXT"),
+        array("recentchanges", "rc_logid",             "INTEGER NOT NULL DEFAULT 0"),
+               array("recentchanges", "rc_new_len",           "INTEGER"),
+               array("recentchanges", "rc_old_len",           "INTEGER"),
+               array("recentchanges", "rc_params",            "TEXT"),
+               array("revision",      "rev_len",              "INTEGER"),
+       );
+
+
+       # table, column, desired type, USING clause if needed
+       $typechanges = array(
+               array("image",        "img_size",        "int4",  ""),
+               array("image",        "img_width",       "int4",  ""),
+               array("image",        "img_height",      "int4",  ""),
+               array("ipblocks",     "ipb_address",     "text", "ipb_address::text"),
+               array("math",         "math_inputhash",  "bytea", "decode(math_inputhash,'escape')"),
+               array("math",         "math_outputhash", "bytea", "decode(math_outputhash,'escape')"),
+               array("oldimage",     "oi_size",         "int4",  ""),
+               array("oldimage",     "oi_width",        "int4",  ""),
+               array("oldimage",     "oi_height",       "int4",  ""),
+               array("user_newtalk", "user_ip",         "text", "host(user_ip)"),
        );
 
        $newindexes = array(
-               array("revision", "rev_text_id_idx",          "patch-rev_text_id_idx.sql")
+               array("revision", "rev_text_id_idx", "patch-rev_text_id_idx.sql")
        );
 
        $newrules = array(
-               array("archive", "archive_delete", "patch-archive_delete.sql")
        );
 
+       foreach ($newsequences as $ns) {
+               if ($wgDatabase->sequenceExists($ns)) {
+                       echo "... sequence $ns already exists\n";
+                       continue;
+               }
+
+               echo "... create sequence $ns\n";
+               $wgDatabase->query("CREATE SEQUENCE $ns");
+       }
+
        foreach ($newtables as $nt) {
-               if (pg_table_exists($nt[0])) {
+               if ($wgDatabase->tableExists($nt[0])) {
                        echo "... table $nt[0] already exists\n";
                        continue;
                }
@@ -1306,8 +1283,25 @@ function do_postgres_updates() {
                dbsource(archive($nt[1]));
        }
 
+       ## Needed before newcols
+       if ($wgDatabase->tableExists("archive2")) {
+               echo "... convert archive2 back to normal archive table\n";
+               if ($wgDatabase->ruleExists("archive", "archive_insert")) {
+                       echo "...   drop rule archive_insert\n";
+                       $wgDatabase->query("DROP RULE archive_insert ON archive");
+               }
+               if ($wgDatabase->ruleExists("archive", "archive_delete")) {
+                       echo "...   drop rule archive_delete\n";
+                       $wgDatabase->query("DROP RULE archive_delete ON archive");
+               }
+
+               dbsource(archive("patch-remove-archive2.sql"));
+       } else
+               echo "... obsolete archive2 not present\n";
+
        foreach ($newcols as $nc) {
-               if (pg_column_exists($nc[0], $nc[1])) {
+               $fi = $wgDatabase->fieldInfo($nc[0], $nc[1]);
+               if (!is_null($fi)) {
                        echo "... column $nc[0].$nc[1] already exists\n";
                        continue;
                }
@@ -1317,24 +1311,25 @@ function do_postgres_updates() {
        }
 
        foreach ($typechanges as $tc) {
-               if (!pg_column_exists($tc[0], $tc[1])) {
+               $fi = $wgDatabase->fieldInfo($tc[0], $tc[1]);
+               if (is_null($fi)) {
                        echo "... error: expected column $tc[0].$tc[1] to exist\n";
                        exit(1);
                }
 
-               if (pg_column_has_type($tc[0], $tc[1], $tc[2]))
+               if ($fi->type() === $tc[2])
                        echo "... $tc[0].$tc[1] is already $tc[2]\n";
                else {
-                       echo "... change $tc[0].$tc[1] to $tc[2]\n";
-                       $wgDatabase->query("ALTER TABLE $tc[0] ALTER $tc[1] TYPE $tc[2];\nCOMMIT;\n");
+                       echo "... change $tc[0].$tc[1] from {$fi->type()} to $tc[2]\n";
+                       $sql = "ALTER TABLE $tc[0] ALTER $tc[1] TYPE $tc[2]";
+                       if (strlen($tc[3])) {
+                               $sql .= " USING $tc[3]";
+                       }
+                       $sql .= ";\nCOMMIT;\n";
+                       $wgDatabase->query($sql);
                }
        }
 
-       if (!pg_column_has_type("user_newtalk", "user_ip", "text")) {
-               echo "... convert user_newtalk.user_ip to text\n";
-               $wgDatabase->query("ALTER TABLE user_newtalk ALTER user_ip TYPE TEXT USING host(user_ip)");
-       }
-
        foreach ($newindexes as $ni) {
                if (pg_index_exists($ni[0], $ni[1])) {
                        echo "... index $ni[1] on $ni[0] already exists\n";
@@ -1344,25 +1339,20 @@ function do_postgres_updates() {
        }
 
        foreach ($newrules as $nr) {
-               if (pg_rule_exists($nr[0], $nr[1])) {
+               if ($wgDatabase->ruleExists($nr[0], $nr[1])) {
                        echo "... rule $nr[1] on $nr[0] already exists\n";
                        continue;
                }
                dbsource(archive($nr[2]));
        }
 
-       if (!pg_column_has_type("ipblocks", "ipb_address", "text")) {
-               echo "... change ipblocks.ipb_address to TEXT\n";
-               $wgDatabase->query("ALTER TABLE ipblocks ALTER ipb_address TYPE TEXT USING ipb_address::TEXT");
-       } else
-               echo "... ipblocks.ipb_address is already TEXT\n";
-
-       if (!pg_trigger_exists("page", "page_deleted")) {
+       if (!$wgDatabase->triggerExists("page", "page_deleted")) {
                echo "... create page_deleted trigger\n";
                dbsource(archive('patch-page_deleted.sql'));
        }
 
-       if (!pg_column_is_nullable("recentchanges", "rc_cur_id")) {
+       $fi = $wgDatabase->fieldInfo("recentchanges", "rc_cur_id");
+       if (!$fi->nullable()) {
                echo "... remove NOT NULL constraint on recentchanges.rc_cur_id\n";
                dbsource(archive('patch-rc_cur_id-not-null.sql'));
        }
@@ -1388,35 +1378,11 @@ function do_postgres_updates() {
                dbsource(archive('patch-revision_rev_user_fkey.sql'));
        }
 
-       ## 1.10 updater
-       if ($version <= 1010) {
-               $upgrade = <<<PGEND
-
--- Fix the archive rule ar_timestamp field
-CREATE OR REPLACE RULE archive_insert AS ON INSERT TO archive
-DO INSTEAD INSERT INTO archive2 VALUES (
-  NEW.ar_namespace, NEW.ar_title, NEW.ar_text, NEW.ar_comment, NEW.ar_user, NEW.ar_user_text, 
-  TO_TIMESTAMP(NEW.ar_timestamp, 'YYYYMMDDHH24MISS'),
-  NEW.ar_minor_edit, NEW.ar_flags, NEW.ar_rev_id, NEW.ar_text_id
-);
-
--- Note this upgrade
-INSERT INTO mediawiki_version (type,mw_version,notes)
-VALUES ('Upgrade','MWVERSION','Upgrade from older pre 1.10 version THISVERSION aka SVERSION');
-
-
-PGEND;
-       } ## end version 1.10
-
-       if ( !strlen($upgrade)) {
-               print "No updates needed for this version ($oldversion)\n";
-               return;
-       }
-
-       $upgrade = str_replace( 'MWVERSION', $wgVersion, $upgrade );
-       $upgrade = str_replace( 'THISVERSION', $oldversion, $upgrade );
-       $upgrade = str_replace( 'SVERSION', $version, $upgrade );
-       $wgDatabase->query("BEGIN;\n\n $upgrade\n\nCOMMIT;\n");
+       if (is_null($wgDatabase->fieldInfo("archive", "ar_deleted"))) {
+               echo "... add archive.ar_deleted\n";
+               dbsource(archive("patch-archive-ar_deleted.sql"));
+       } else
+               echo "... archive.ar_deleted already exists\n";
 
        return;
 }