MediaWiki  REL1_23
PostgresUpdater.php
Go to the documentation of this file.
00001 <?php
00030 class PostgresUpdater extends DatabaseUpdater {
00031 
00035     protected $db;
00036 
00042     protected function getCoreUpdateList() {
00043         return array(
00044             # rename tables 1.7.3
00045             # r15791 Change reserved word table names "user" and "text"
00046             array( 'renameTable', 'user', 'mwuser' ),
00047             array( 'renameTable', 'text', 'pagecontent' ),
00048             array( 'renameIndex', 'mwuser', 'user_pkey', 'mwuser_pkey' ),
00049             array( 'renameIndex', 'mwuser', 'user_user_name_key', 'mwuser_user_name_key' ),
00050             array( 'renameIndex', 'pagecontent', 'text_pkey', 'pagecontent_pkey' ),
00051 
00052             # renamed sequences
00053             array( 'renameSequence', 'ipblocks_ipb_id_val', 'ipblocks_ipb_id_seq' ),
00054             array( 'renameSequence', 'rev_rev_id_val', 'revision_rev_id_seq' ),
00055             array( 'renameSequence', 'text_old_id_val', 'text_old_id_seq' ),
00056             array( 'renameSequence', 'rc_rc_id_seq', 'recentchanges_rc_id_seq' ),
00057             array( 'renameSequence', 'log_log_id_seq', 'logging_log_id_seq' ),
00058             array( 'renameSequence', 'pr_id_val', 'page_restrictions_pr_id_seq' ),
00059             array( 'renameSequence', 'us_id_seq', 'uploadstash_us_id_seq' ),
00060 
00061             # since r58263
00062             array( 'renameSequence', 'category_id_seq', 'category_cat_id_seq' ),
00063 
00064             # new sequences if not renamed above
00065             array( 'addSequence', 'logging', false, 'logging_log_id_seq' ),
00066             array( 'addSequence', 'page_restrictions', false, 'page_restrictions_pr_id_seq' ),
00067             array( 'addSequence', 'filearchive', 'fa_id', 'filearchive_fa_id_seq' ),
00068             array( 'addSequence', 'archive', false, 'archive_ar_id_seq' ),
00069             array( 'addSequence', 'externallinks', false, 'externallinks_el_id_seq' ),
00070 
00071             # new tables
00072             array( 'addTable', 'category', 'patch-category.sql' ),
00073             array( 'addTable', 'page', 'patch-page.sql' ),
00074             array( 'addTable', 'querycachetwo', 'patch-querycachetwo.sql' ),
00075             array( 'addTable', 'page_props', 'patch-page_props.sql' ),
00076             array( 'addTable', 'page_restrictions', 'patch-page_restrictions.sql' ),
00077             array( 'addTable', 'profiling', 'patch-profiling.sql' ),
00078             array( 'addTable', 'protected_titles', 'patch-protected_titles.sql' ),
00079             array( 'addTable', 'redirect', 'patch-redirect.sql' ),
00080             array( 'addTable', 'updatelog', 'patch-updatelog.sql' ),
00081             array( 'addTable', 'change_tag', 'patch-change_tag.sql' ),
00082             array( 'addTable', 'tag_summary', 'patch-tag_summary.sql' ),
00083             array( 'addTable', 'valid_tag', 'patch-valid_tag.sql' ),
00084             array( 'addTable', 'user_properties', 'patch-user_properties.sql' ),
00085             array( 'addTable', 'log_search', 'patch-log_search.sql' ),
00086             array( 'addTable', 'l10n_cache', 'patch-l10n_cache.sql' ),
00087             array( 'addTable', 'iwlinks', 'patch-iwlinks.sql' ),
00088             array( 'addTable', 'msg_resource', 'patch-msg_resource.sql' ),
00089             array( 'addTable', 'msg_resource_links', 'patch-msg_resource_links.sql' ),
00090             array( 'addTable', 'module_deps', 'patch-module_deps.sql' ),
00091             array( 'addTable', 'uploadstash', 'patch-uploadstash.sql' ),
00092             array( 'addTable', 'user_former_groups', 'patch-user_former_groups.sql' ),
00093             array( 'addTable', 'sites', 'patch-sites.sql' ),
00094 
00095             # Needed before new field
00096             array( 'convertArchive2' ),
00097 
00098             # new fields
00099             array( 'addPgField', 'updatelog', 'ul_value', 'TEXT' ),
00100             array( 'addPgField', 'archive', 'ar_deleted', 'SMALLINT NOT NULL DEFAULT 0' ),
00101             array( 'addPgField', 'archive', 'ar_len', 'INTEGER' ),
00102             array( 'addPgField', 'archive', 'ar_page_id', 'INTEGER' ),
00103             array( 'addPgField', 'archive', 'ar_parent_id', 'INTEGER' ),
00104             array( 'addPgField', 'archive', 'ar_content_model', 'TEXT' ),
00105             array( 'addPgField', 'archive', 'ar_content_format', 'TEXT' ),
00106             array( 'addPgField', 'categorylinks', 'cl_sortkey_prefix', "TEXT NOT NULL DEFAULT ''" ),
00107             array( 'addPgField', 'categorylinks', 'cl_collation', "TEXT NOT NULL DEFAULT 0" ),
00108             array( 'addPgField', 'categorylinks', 'cl_type', "TEXT NOT NULL DEFAULT 'page'" ),
00109             array( 'addPgField', 'image', 'img_sha1', "TEXT NOT NULL DEFAULT ''" ),
00110             array( 'addPgField', 'ipblocks', 'ipb_allow_usertalk', 'SMALLINT NOT NULL DEFAULT 0' ),
00111             array( 'addPgField', 'ipblocks', 'ipb_anon_only', 'SMALLINT NOT NULL DEFAULT 0' ),
00112             array( 'addPgField', 'ipblocks', 'ipb_by_text', "TEXT NOT NULL DEFAULT ''" ),
00113             array( 'addPgField', 'ipblocks', 'ipb_block_email', 'SMALLINT NOT NULL DEFAULT 0' ),
00114             array( 'addPgField', 'ipblocks', 'ipb_create_account', 'SMALLINT NOT NULL DEFAULT 1' ),
00115             array( 'addPgField', 'ipblocks', 'ipb_deleted', 'SMALLINT NOT NULL DEFAULT 0' ),
00116             array( 'addPgField', 'ipblocks', 'ipb_enable_autoblock', 'SMALLINT NOT NULL DEFAULT 1' ),
00117             array( 'addPgField', 'ipblocks', 'ipb_parent_block_id',
00118                 'INTEGER DEFAULT NULL REFERENCES ipblocks(ipb_id) ' .
00119                 'ON DELETE SET NULL DEFERRABLE INITIALLY DEFERRED' ),
00120             array( 'addPgField', 'filearchive', 'fa_deleted', 'SMALLINT NOT NULL DEFAULT 0' ),
00121             array( 'addPgField', 'filearchive', 'fa_sha1', "TEXT NOT NULL DEFAULT ''" ),
00122             array( 'addPgField', 'logging', 'log_deleted', 'SMALLINT NOT NULL DEFAULT 0' ),
00123             array( 'addPgField', 'logging', 'log_id',
00124                 "INTEGER NOT NULL PRIMARY KEY DEFAULT nextval('logging_log_id_seq')" ),
00125             array( 'addPgField', 'logging', 'log_params', 'TEXT' ),
00126             array( 'addPgField', 'mwuser', 'user_editcount', 'INTEGER' ),
00127             array( 'addPgField', 'mwuser', 'user_newpass_time', 'TIMESTAMPTZ' ),
00128             array( 'addPgField', 'oldimage', 'oi_deleted', 'SMALLINT NOT NULL DEFAULT 0' ),
00129             array( 'addPgField', 'oldimage', 'oi_major_mime', "TEXT NOT NULL DEFAULT 'unknown'" ),
00130             array( 'addPgField', 'oldimage', 'oi_media_type', 'TEXT' ),
00131             array( 'addPgField', 'oldimage', 'oi_metadata', "BYTEA NOT NULL DEFAULT ''" ),
00132             array( 'addPgField', 'oldimage', 'oi_minor_mime', "TEXT NOT NULL DEFAULT 'unknown'" ),
00133             array( 'addPgField', 'oldimage', 'oi_sha1', "TEXT NOT NULL DEFAULT ''" ),
00134             array( 'addPgField', 'page', 'page_content_model', 'TEXT' ),
00135             array( 'addPgField', 'page_restrictions', 'pr_id',
00136                 "INTEGER NOT NULL UNIQUE DEFAULT nextval('page_restrictions_pr_id_seq')" ),
00137             array( 'addPgField', 'profiling', 'pf_memory', 'NUMERIC(18,10) NOT NULL DEFAULT 0' ),
00138             array( 'addPgField', 'recentchanges', 'rc_deleted', 'SMALLINT NOT NULL DEFAULT 0' ),
00139             array( 'addPgField', 'recentchanges', 'rc_log_action', 'TEXT' ),
00140             array( 'addPgField', 'recentchanges', 'rc_log_type', 'TEXT' ),
00141             array( 'addPgField', 'recentchanges', 'rc_logid', 'INTEGER NOT NULL DEFAULT 0' ),
00142             array( 'addPgField', 'recentchanges', 'rc_new_len', 'INTEGER' ),
00143             array( 'addPgField', 'recentchanges', 'rc_old_len', 'INTEGER' ),
00144             array( 'addPgField', 'recentchanges', 'rc_params', 'TEXT' ),
00145             array( 'addPgField', 'redirect', 'rd_interwiki', 'TEXT NULL' ),
00146             array( 'addPgField', 'redirect', 'rd_fragment', 'TEXT NULL' ),
00147             array( 'addPgField', 'revision', 'rev_deleted', 'SMALLINT NOT NULL DEFAULT 0' ),
00148             array( 'addPgField', 'revision', 'rev_len', 'INTEGER' ),
00149             array( 'addPgField', 'revision', 'rev_parent_id', 'INTEGER DEFAULT NULL' ),
00150             array( 'addPgField', 'revision', 'rev_content_model', 'TEXT' ),
00151             array( 'addPgField', 'revision', 'rev_content_format', 'TEXT' ),
00152             array( 'addPgField', 'site_stats', 'ss_active_users', "INTEGER DEFAULT '-1'" ),
00153             array( 'addPgField', 'user_newtalk', 'user_last_timestamp', 'TIMESTAMPTZ' ),
00154             array( 'addPgField', 'logging', 'log_user_text', "TEXT NOT NULL DEFAULT ''" ),
00155             array( 'addPgField', 'logging', 'log_page', 'INTEGER' ),
00156             array( 'addPgField', 'interwiki', 'iw_api', "TEXT NOT NULL DEFAULT ''" ),
00157             array( 'addPgField', 'interwiki', 'iw_wikiid', "TEXT NOT NULL DEFAULT ''" ),
00158             array( 'addPgField', 'revision', 'rev_sha1', "TEXT NOT NULL DEFAULT ''" ),
00159             array( 'addPgField', 'archive', 'ar_sha1', "TEXT NOT NULL DEFAULT ''" ),
00160             array( 'addPgField', 'uploadstash', 'us_chunk_inx', "INTEGER NULL" ),
00161             array( 'addPgField', 'job', 'job_timestamp', "TIMESTAMPTZ" ),
00162             array( 'addPgField', 'job', 'job_random', "INTEGER NOT NULL DEFAULT 0" ),
00163             array( 'addPgField', 'job', 'job_attempts', "INTEGER NOT NULL DEFAULT 0" ),
00164             array( 'addPgField', 'job', 'job_token', "TEXT NOT NULL DEFAULT ''" ),
00165             array( 'addPgField', 'job', 'job_token_timestamp', "TIMESTAMPTZ" ),
00166             array( 'addPgField', 'job', 'job_sha1', "TEXT NOT NULL DEFAULT ''" ),
00167             array( 'addPgField', 'archive', 'ar_id',
00168                 "INTEGER NOT NULL PRIMARY KEY DEFAULT nextval('archive_ar_id_seq')" ),
00169             array( 'addPgField', 'externallinks', 'el_id',
00170                 "INTEGER NOT NULL PRIMARY KEY DEFAULT nextval('externallinks_el_id_seq')" ),
00171             array( 'addPgField', 'uploadstash', 'us_props', "BYTEA" ),
00172 
00173             # type changes
00174             array( 'changeField', 'archive', 'ar_deleted', 'smallint', '' ),
00175             array( 'changeField', 'archive', 'ar_minor_edit', 'smallint',
00176                 'ar_minor_edit::smallint DEFAULT 0' ),
00177             array( 'changeField', 'filearchive', 'fa_deleted', 'smallint', '' ),
00178             array( 'changeField', 'filearchive', 'fa_height', 'integer', '' ),
00179             array( 'changeField', 'filearchive', 'fa_metadata', 'bytea', "decode(fa_metadata,'escape')" ),
00180             array( 'changeField', 'filearchive', 'fa_size', 'integer', '' ),
00181             array( 'changeField', 'filearchive', 'fa_width', 'integer', '' ),
00182             array( 'changeField', 'filearchive', 'fa_storage_group', 'text', '' ),
00183             array( 'changeField', 'filearchive', 'fa_storage_key', 'text', '' ),
00184             array( 'changeField', 'image', 'img_metadata', 'bytea', "decode(img_metadata,'escape')" ),
00185             array( 'changeField', 'image', 'img_size', 'integer', '' ),
00186             array( 'changeField', 'image', 'img_width', 'integer', '' ),
00187             array( 'changeField', 'image', 'img_height', 'integer', '' ),
00188             array( 'changeField', 'interwiki', 'iw_local', 'smallint', 'iw_local::smallint' ),
00189             array( 'changeField', 'interwiki', 'iw_trans', 'smallint', 'iw_trans::smallint DEFAULT 0' ),
00190             array( 'changeField', 'ipblocks', 'ipb_auto', 'smallint', 'ipb_auto::smallint DEFAULT 0' ),
00191             array( 'changeField', 'ipblocks', 'ipb_anon_only', 'smallint',
00192                 "CASE WHEN ipb_anon_only=' ' THEN 0 ELSE ipb_anon_only::smallint END DEFAULT 0" ),
00193             array( 'changeField', 'ipblocks', 'ipb_create_account', 'smallint',
00194                 "CASE WHEN ipb_create_account=' ' THEN 0 ELSE ipb_create_account::smallint END DEFAULT 1" ),
00195             array( 'changeField', 'ipblocks', 'ipb_enable_autoblock', 'smallint',
00196                 "CASE WHEN ipb_enable_autoblock=' ' THEN 0 ELSE ipb_enable_autoblock::smallint END DEFAULT 1" ),
00197             array( 'changeField', 'ipblocks', 'ipb_block_email', 'smallint',
00198                 "CASE WHEN ipb_block_email=' ' THEN 0 ELSE ipb_block_email::smallint END DEFAULT 0" ),
00199             array( 'changeField', 'ipblocks', 'ipb_address', 'text', 'ipb_address::text' ),
00200             array( 'changeField', 'ipblocks', 'ipb_deleted', 'smallint', 'ipb_deleted::smallint DEFAULT 0' ),
00201             array( 'changeField', 'mwuser', 'user_token', 'text', '' ),
00202             array( 'changeField', 'mwuser', 'user_email_token', 'text', '' ),
00203             array( 'changeField', 'objectcache', 'keyname', 'text', '' ),
00204             array( 'changeField', 'oldimage', 'oi_height', 'integer', '' ),
00205             array( 'changeField', 'oldimage', 'oi_metadata', 'bytea', "decode(img_metadata,'escape')" ),
00206             array( 'changeField', 'oldimage', 'oi_size', 'integer', '' ),
00207             array( 'changeField', 'oldimage', 'oi_width', 'integer', '' ),
00208             array( 'changeField', 'page', 'page_is_redirect', 'smallint',
00209                 'page_is_redirect::smallint DEFAULT 0' ),
00210             array( 'changeField', 'page', 'page_is_new', 'smallint', 'page_is_new::smallint DEFAULT 0' ),
00211             array( 'changeField', 'querycache', 'qc_value', 'integer', '' ),
00212             array( 'changeField', 'querycachetwo', 'qcc_value', 'integer', '' ),
00213             array( 'changeField', 'recentchanges', 'rc_bot', 'smallint', 'rc_bot::smallint DEFAULT 0' ),
00214             array( 'changeField', 'recentchanges', 'rc_deleted', 'smallint', '' ),
00215             array( 'changeField', 'recentchanges', 'rc_minor', 'smallint', 'rc_minor::smallint DEFAULT 0' ),
00216             array( 'changeField', 'recentchanges', 'rc_new', 'smallint', 'rc_new::smallint DEFAULT 0' ),
00217             array( 'changeField', 'recentchanges', 'rc_type', 'smallint', 'rc_type::smallint DEFAULT 0' ),
00218             array( 'changeField', 'recentchanges', 'rc_patrolled', 'smallint',
00219                 'rc_patrolled::smallint DEFAULT 0' ),
00220             array( 'changeField', 'revision', 'rev_deleted', 'smallint', 'rev_deleted::smallint DEFAULT 0' ),
00221             array( 'changeField', 'revision', 'rev_minor_edit', 'smallint',
00222                 'rev_minor_edit::smallint DEFAULT 0' ),
00223             array( 'changeField', 'templatelinks', 'tl_namespace', 'smallint', 'tl_namespace::smallint' ),
00224             array( 'changeField', 'user_newtalk', 'user_ip', 'text', 'host(user_ip)' ),
00225             array( 'changeField', 'uploadstash', 'us_image_bits', 'smallint', '' ),
00226             array( 'changeField', 'profiling', 'pf_time', 'float', '' ),
00227             array( 'changeField', 'profiling', 'pf_memory', 'float', '' ),
00228 
00229             # null changes
00230             array( 'changeNullableField', 'oldimage', 'oi_bits', 'NULL' ),
00231             array( 'changeNullableField', 'oldimage', 'oi_timestamp', 'NULL' ),
00232             array( 'changeNullableField', 'oldimage', 'oi_major_mime', 'NULL' ),
00233             array( 'changeNullableField', 'oldimage', 'oi_minor_mime', 'NULL' ),
00234             array( 'changeNullableField', 'image', 'img_metadata', 'NOT NULL' ),
00235             array( 'changeNullableField', 'filearchive', 'fa_metadata', 'NOT NULL' ),
00236             array( 'changeNullableField', 'recentchanges', 'rc_cur_id', 'NULL' ),
00237             array( 'changeNullableField', 'recentchanges', 'rc_cur_time', 'NULL' ),
00238 
00239             array( 'checkOiDeleted' ),
00240 
00241             # New indexes
00242             array( 'addPgIndex', 'archive', 'archive_user_text', '(ar_user_text)' ),
00243             array( 'addPgIndex', 'image', 'img_sha1', '(img_sha1)' ),
00244             array( 'addPgIndex', 'ipblocks', 'ipb_parent_block_id', '(ipb_parent_block_id)' ),
00245             array( 'addPgIndex', 'oldimage', 'oi_sha1', '(oi_sha1)' ),
00246             array( 'addPgIndex', 'page', 'page_mediawiki_title', '(page_title) WHERE page_namespace = 8' ),
00247             array( 'addPgIndex', 'pagelinks', 'pagelinks_title', '(pl_title)' ),
00248             array( 'addPgIndex', 'page_props', 'pp_propname_page', '(pp_propname, pp_page)' ),
00249             array( 'addPgIndex', 'revision', 'rev_text_id_idx', '(rev_text_id)' ),
00250             array( 'addPgIndex', 'recentchanges', 'rc_timestamp_bot', '(rc_timestamp) WHERE rc_bot = 0' ),
00251             array( 'addPgIndex', 'templatelinks', 'templatelinks_from', '(tl_from)' ),
00252             array( 'addPgIndex', 'watchlist', 'wl_user', '(wl_user)' ),
00253             array( 'addPgIndex', 'logging', 'logging_user_type_time',
00254                 '(log_user, log_type, log_timestamp)' ),
00255             array( 'addPgIndex', 'logging', 'logging_page_id_time', '(log_page,log_timestamp)' ),
00256             array( 'addPgIndex', 'iwlinks', 'iwl_prefix_from_title', '(iwl_prefix, iwl_from, iwl_title)' ),
00257             array( 'addPgIndex', 'iwlinks', 'iwl_prefix_title_from', '(iwl_prefix, iwl_title, iwl_from)' ),
00258             array( 'addPgIndex', 'job', 'job_timestamp_idx', '(job_timestamp)' ),
00259             array( 'addPgIndex', 'job', 'job_sha1', '(job_sha1)' ),
00260             array( 'addPgIndex', 'job', 'job_cmd_token', '(job_cmd, job_token, job_random)' ),
00261             array( 'addPgIndex', 'job', 'job_cmd_token_id', '(job_cmd, job_token, job_id)' ),
00262             array( 'addPgIndex', 'filearchive', 'fa_sha1', '(fa_sha1)' ),
00263             array( 'addPgIndex', 'logging', 'logging_user_text_type_time',
00264                 '(log_user_text, log_type, log_timestamp)' ),
00265             array( 'addPgIndex', 'logging', 'logging_user_text_time', '(log_user_text, log_timestamp)' ),
00266 
00267             array( 'checkIndex', 'pagelink_unique', array(
00268                 array( 'pl_from', 'int4_ops', 'btree', 0 ),
00269                 array( 'pl_namespace', 'int2_ops', 'btree', 0 ),
00270                 array( 'pl_title', 'text_ops', 'btree', 0 ),
00271             ),
00272                 'CREATE UNIQUE INDEX pagelink_unique ON pagelinks (pl_from,pl_namespace,pl_title)' ),
00273             array( 'checkIndex', 'cl_sortkey', array(
00274                 array( 'cl_to', 'text_ops', 'btree', 0 ),
00275                 array( 'cl_sortkey', 'text_ops', 'btree', 0 ),
00276                 array( 'cl_from', 'int4_ops', 'btree', 0 ),
00277             ),
00278                 'CREATE INDEX cl_sortkey ON "categorylinks" ' .
00279                     'USING "btree" ("cl_to", "cl_sortkey", "cl_from")' ),
00280             array( 'checkIndex', 'iwl_prefix_title_from', array(
00281                 array( 'iwl_prefix', 'text_ops', 'btree', 0 ),
00282                 array( 'iwl_title', 'text_ops', 'btree', 0 ),
00283                 array( 'iwl_from', 'int4_ops', 'btree', 0 ),
00284             ),
00285             'CREATE INDEX iwl_prefix_title_from ON "iwlinks" ' .
00286                 'USING "btree" ("iwl_prefix", "iwl_title", "iwl_from")' ),
00287             array( 'checkIndex', 'logging_times', array(
00288                 array( 'log_timestamp', 'timestamptz_ops', 'btree', 0 ),
00289             ),
00290             'CREATE INDEX "logging_times" ON "logging" USING "btree" ("log_timestamp")' ),
00291             array( 'dropIndex', 'oldimage', 'oi_name' ),
00292             array( 'checkIndex', 'oi_name_archive_name', array(
00293                 array( 'oi_name', 'text_ops', 'btree', 0 ),
00294                 array( 'oi_archive_name', 'text_ops', 'btree', 0 ),
00295             ),
00296             'CREATE INDEX "oi_name_archive_name" ON "oldimage" ' .
00297                 'USING "btree" ("oi_name", "oi_archive_name")' ),
00298             array( 'checkIndex', 'oi_name_timestamp', array(
00299                 array( 'oi_name', 'text_ops', 'btree', 0 ),
00300                 array( 'oi_timestamp', 'timestamptz_ops', 'btree', 0 ),
00301             ),
00302             'CREATE INDEX "oi_name_timestamp" ON "oldimage" ' .
00303                 'USING "btree" ("oi_name", "oi_timestamp")' ),
00304             array( 'checkIndex', 'page_main_title', array(
00305                 array( 'page_title', 'text_pattern_ops', 'btree', 0 ),
00306             ),
00307             'CREATE INDEX "page_main_title" ON "page" ' .
00308                 'USING "btree" ("page_title" "text_pattern_ops") WHERE ("page_namespace" = 0)' ),
00309             array( 'checkIndex', 'page_mediawiki_title', array(
00310                 array( 'page_title', 'text_pattern_ops', 'btree', 0 ),
00311             ),
00312             'CREATE INDEX "page_mediawiki_title" ON "page" ' .
00313                 'USING "btree" ("page_title" "text_pattern_ops") WHERE ("page_namespace" = 8)' ),
00314             array( 'checkIndex', 'page_project_title', array(
00315                 array( 'page_title', 'text_pattern_ops', 'btree', 0 ),
00316             ),
00317             'CREATE INDEX "page_project_title" ON "page" ' .
00318                 'USING "btree" ("page_title" "text_pattern_ops") ' .
00319                 'WHERE ("page_namespace" = 4)' ),
00320             array( 'checkIndex', 'page_talk_title', array(
00321                 array( 'page_title', 'text_pattern_ops', 'btree', 0 ),
00322             ),
00323             'CREATE INDEX "page_talk_title" ON "page" ' .
00324                 'USING "btree" ("page_title" "text_pattern_ops") ' .
00325                 'WHERE ("page_namespace" = 1)' ),
00326             array( 'checkIndex', 'page_user_title', array(
00327                 array( 'page_title', 'text_pattern_ops', 'btree', 0 ),
00328             ),
00329             'CREATE INDEX "page_user_title" ON "page" ' .
00330                 'USING "btree" ("page_title" "text_pattern_ops") WHERE ' .
00331                 '("page_namespace" = 2)' ),
00332             array( 'checkIndex', 'page_utalk_title', array(
00333                 array( 'page_title', 'text_pattern_ops', 'btree', 0 ),
00334             ),
00335             'CREATE INDEX "page_utalk_title" ON "page" ' .
00336                 'USING "btree" ("page_title" "text_pattern_ops") ' .
00337                 'WHERE ("page_namespace" = 3)' ),
00338             array( 'checkIndex', 'ts2_page_text', array(
00339                 array( 'textvector', 'tsvector_ops', 'gist', 0 ),
00340             ),
00341             'CREATE INDEX "ts2_page_text" ON "pagecontent" USING "gist" ("textvector")' ),
00342             array( 'checkIndex', 'ts2_page_title', array(
00343                 array( 'titlevector', 'tsvector_ops', 'gist', 0 ),
00344             ),
00345             'CREATE INDEX "ts2_page_title" ON "page" USING "gist" ("titlevector")' ),
00346 
00347             array( 'checkOiNameConstraint' ),
00348             array( 'checkPageDeletedTrigger' ),
00349             array( 'checkRevUserFkey' ),
00350             array( 'dropIndex', 'ipblocks', 'ipb_address' ),
00351             array( 'checkIndex', 'ipb_address_unique', array(
00352                 array( 'ipb_address', 'text_ops', 'btree', 0 ),
00353                 array( 'ipb_user', 'int4_ops', 'btree', 0 ),
00354                 array( 'ipb_auto', 'int2_ops', 'btree', 0 ),
00355                 array( 'ipb_anon_only', 'int2_ops', 'btree', 0 ),
00356             ),
00357             'CREATE UNIQUE INDEX ipb_address_unique ' .
00358                 'ON ipblocks (ipb_address,ipb_user,ipb_auto,ipb_anon_only)' ),
00359 
00360             array( 'checkIwlPrefix' ),
00361 
00362             # All FK columns should be deferred
00363             array( 'changeFkeyDeferrable', 'archive', 'ar_user', 'mwuser(user_id) ON DELETE SET NULL' ),
00364             array( 'changeFkeyDeferrable', 'categorylinks', 'cl_from', 'page(page_id) ON DELETE CASCADE' ),
00365             array( 'changeFkeyDeferrable', 'externallinks', 'el_from', 'page(page_id) ON DELETE CASCADE' ),
00366             array( 'changeFkeyDeferrable', 'filearchive', 'fa_deleted_user',
00367                 'mwuser(user_id) ON DELETE SET NULL' ),
00368             array( 'changeFkeyDeferrable', 'filearchive', 'fa_user', 'mwuser(user_id) ON DELETE SET NULL' ),
00369             array( 'changeFkeyDeferrable', 'image', 'img_user', 'mwuser(user_id) ON DELETE SET NULL' ),
00370             array( 'changeFkeyDeferrable', 'imagelinks', 'il_from', 'page(page_id) ON DELETE CASCADE' ),
00371             array( 'changeFkeyDeferrable', 'ipblocks', 'ipb_by', 'mwuser(user_id) ON DELETE CASCADE' ),
00372             array( 'changeFkeyDeferrable', 'ipblocks', 'ipb_user', 'mwuser(user_id) ON DELETE SET NULL' ),
00373             array( 'changeFkeyDeferrable', 'ipblocks', 'ipb_parent_block_id',
00374                 'ipblocks(ipb_id) ON DELETE SET NULL' ),
00375             array( 'changeFkeyDeferrable', 'langlinks', 'll_from', 'page(page_id) ON DELETE CASCADE' ),
00376             array( 'changeFkeyDeferrable', 'logging', 'log_user', 'mwuser(user_id) ON DELETE SET NULL' ),
00377             array( 'changeFkeyDeferrable', 'oldimage', 'oi_name',
00378                 'image(img_name) ON DELETE CASCADE ON UPDATE CASCADE' ),
00379             array( 'changeFkeyDeferrable', 'oldimage', 'oi_user', 'mwuser(user_id) ON DELETE SET NULL' ),
00380             array( 'changeFkeyDeferrable', 'pagelinks', 'pl_from', 'page(page_id) ON DELETE CASCADE' ),
00381             array( 'changeFkeyDeferrable', 'page_props', 'pp_page', 'page (page_id) ON DELETE CASCADE' ),
00382             array( 'changeFkeyDeferrable', 'page_restrictions', 'pr_page',
00383                 'page(page_id) ON DELETE CASCADE' ),
00384             array( 'changeFkeyDeferrable', 'protected_titles', 'pt_user',
00385                 'mwuser(user_id) ON DELETE SET NULL' ),
00386             array( 'changeFkeyDeferrable', 'recentchanges', 'rc_cur_id',
00387                 'page(page_id) ON DELETE SET NULL' ),
00388             array( 'changeFkeyDeferrable', 'recentchanges', 'rc_user',
00389                 'mwuser(user_id) ON DELETE SET NULL' ),
00390             array( 'changeFkeyDeferrable', 'redirect', 'rd_from', 'page(page_id) ON DELETE CASCADE' ),
00391             array( 'changeFkeyDeferrable', 'revision', 'rev_page', 'page (page_id) ON DELETE CASCADE' ),
00392             array( 'changeFkeyDeferrable', 'revision', 'rev_user', 'mwuser(user_id) ON DELETE RESTRICT' ),
00393             array( 'changeFkeyDeferrable', 'templatelinks', 'tl_from', 'page(page_id) ON DELETE CASCADE' ),
00394             array( 'changeFkeyDeferrable', 'user_groups', 'ug_user', 'mwuser(user_id) ON DELETE CASCADE' ),
00395             array( 'changeFkeyDeferrable', 'user_newtalk', 'user_id', 'mwuser(user_id) ON DELETE CASCADE' ),
00396             array( 'changeFkeyDeferrable', 'user_properties', 'up_user',
00397                 'mwuser(user_id) ON DELETE CASCADE' ),
00398             array( 'changeFkeyDeferrable', 'watchlist', 'wl_user', 'mwuser(user_id) ON DELETE CASCADE' ),
00399 
00400             # r81574
00401             array( 'addInterwikiType' ),
00402             # end
00403             array( 'tsearchFixes' ),
00404 
00405             // 1.23
00406             array( 'addPgField', 'recentchanges', 'rc_source', "TEXT NOT NULL DEFAULT ''" ),
00407             array( 'addPgField', 'page', 'page_links_updated', "TIMESTAMPTZ NULL" ),
00408             array( 'addPgField', 'mwuser', 'user_password_expires', 'TIMESTAMPTZ NULL' ),
00409             array( 'changeFieldPurgeTable', 'l10n_cache', 'lc_value', 'bytea', "replace(lc_value,'\','\\\\')::bytea" ),
00410         );
00411     }
00412 
00413     protected function getOldGlobalUpdates() {
00414         global $wgExtNewTables, $wgExtPGNewFields, $wgExtPGAlteredFields, $wgExtNewIndexes;
00415 
00416         $updates = array();
00417 
00418         # Add missing extension tables
00419         foreach ( $wgExtNewTables as $tableRecord ) {
00420             $updates[] = array(
00421                 'addTable', $tableRecord[0], $tableRecord[1], true
00422             );
00423         }
00424 
00425         # Add missing extension fields
00426         foreach ( $wgExtPGNewFields as $fieldRecord ) {
00427             $updates[] = array(
00428                 'addPgField', $fieldRecord[0], $fieldRecord[1],
00429                 $fieldRecord[2]
00430             );
00431         }
00432 
00433         # Change altered columns
00434         foreach ( $wgExtPGAlteredFields as $fieldRecord ) {
00435             $updates[] = array(
00436                 'changeField', $fieldRecord[0], $fieldRecord[1],
00437                 $fieldRecord[2]
00438             );
00439         }
00440 
00441         # Add missing extension indexes
00442         foreach ( $wgExtNewIndexes as $fieldRecord ) {
00443             $updates[] = array(
00444                 'addPgExtIndex', $fieldRecord[0], $fieldRecord[1],
00445                 $fieldRecord[2]
00446             );
00447         }
00448 
00449         return $updates;
00450     }
00451 
00452     protected function describeTable( $table ) {
00453         $q = <<<END
00454 SELECT attname, attnum FROM pg_namespace, pg_class, pg_attribute
00455     WHERE pg_class.relnamespace = pg_namespace.oid
00456       AND attrelid=pg_class.oid AND attnum > 0
00457       AND relname=%s AND nspname=%s
00458 END;
00459         $res = $this->db->query( sprintf( $q,
00460             $this->db->addQuotes( $table ),
00461             $this->db->addQuotes( $this->db->getCoreSchema() ) ) );
00462         if ( !$res ) {
00463             return null;
00464         }
00465 
00466         $cols = array();
00467         foreach ( $res as $r ) {
00468             $cols[] = array(
00469                 "name" => $r[0],
00470                 "ord" => $r[1],
00471             );
00472         }
00473 
00474         return $cols;
00475     }
00476 
00477     function describeIndex( $idx ) {
00478         // first fetch the key (which is a list of columns ords) and
00479         // the table the index applies to (an oid)
00480         $q = <<<END
00481 SELECT indkey, indrelid FROM pg_namespace, pg_class, pg_index
00482     WHERE nspname=%s
00483       AND pg_class.relnamespace = pg_namespace.oid
00484       AND relname=%s
00485       AND indexrelid=pg_class.oid
00486 END;
00487         $res = $this->db->query(
00488             sprintf(
00489                 $q,
00490                 $this->db->addQuotes( $this->db->getCoreSchema() ),
00491                 $this->db->addQuotes( $idx )
00492             )
00493         );
00494         if ( !$res ) {
00495             return null;
00496         }
00497         if ( !( $r = $this->db->fetchRow( $res ) ) ) {
00498             return null;
00499         }
00500 
00501         $indkey = $r[0];
00502         $relid = intval( $r[1] );
00503         $indkeys = explode( ' ', $indkey );
00504 
00505         $colnames = array();
00506         foreach ( $indkeys as $rid ) {
00507             $query = <<<END
00508 SELECT attname FROM pg_class, pg_attribute
00509     WHERE attrelid=$relid
00510       AND attnum=%d
00511       AND attrelid=pg_class.oid
00512 END;
00513             $r2 = $this->db->query( sprintf( $query, $rid ) );
00514             if ( !$r2 ) {
00515                 return null;
00516             }
00517             if ( !( $row2 = $this->db->fetchRow( $r2 ) ) ) {
00518                 return null;
00519             }
00520             $colnames[] = $row2[0];
00521         }
00522 
00523         return $colnames;
00524     }
00525 
00526     function fkeyDeltype( $fkey ) {
00527         $q = <<<END
00528 SELECT confdeltype FROM pg_constraint, pg_namespace
00529     WHERE connamespace=pg_namespace.oid
00530       AND nspname=%s
00531       AND conname=%s;
00532 END;
00533         $r = $this->db->query(
00534             sprintf(
00535                 $q,
00536                 $this->db->addQuotes( $this->db->getCoreSchema() ),
00537                 $this->db->addQuotes( $fkey )
00538             )
00539         );
00540         if ( !( $row = $this->db->fetchRow( $r ) ) ) {
00541             return null;
00542         }
00543 
00544         return $row[0];
00545     }
00546 
00547     function ruleDef( $table, $rule ) {
00548         $q = <<<END
00549 SELECT definition FROM pg_rules
00550     WHERE schemaname = %s
00551       AND tablename = %s
00552       AND rulename = %s
00553 END;
00554         $r = $this->db->query(
00555             sprintf(
00556                 $q,
00557                 $this->db->addQuotes( $this->db->getCoreSchema() ),
00558                 $this->db->addQuotes( $table ),
00559                 $this->db->addQuotes( $rule )
00560             )
00561         );
00562         $row = $this->db->fetchRow( $r );
00563         if ( !$row ) {
00564             return null;
00565         }
00566         $d = $row[0];
00567 
00568         return $d;
00569     }
00570 
00571     protected function addSequence( $table, $pkey, $ns ) {
00572         if ( !$this->db->sequenceExists( $ns ) ) {
00573             $this->output( "Creating sequence $ns\n" );
00574             $this->db->query( "CREATE SEQUENCE $ns" );
00575             if ( $pkey !== false ) {
00576                 $this->setDefault( $table, $pkey, '"nextval"(\'"' . $ns . '"\'::"regclass")' );
00577             }
00578         }
00579     }
00580 
00581     protected function renameSequence( $old, $new ) {
00582         if ( $this->db->sequenceExists( $new ) ) {
00583             $this->output( "...sequence $new already exists.\n" );
00584 
00585             return;
00586         }
00587         if ( $this->db->sequenceExists( $old ) ) {
00588             $this->output( "Renaming sequence $old to $new\n" );
00589             $this->db->query( "ALTER SEQUENCE $old RENAME TO $new" );
00590         }
00591     }
00592 
00593     protected function renameTable( $old, $new, $patch = false ) {
00594         if ( $this->db->tableExists( $old ) ) {
00595             $this->output( "Renaming table $old to $new\n" );
00596             $old = $this->db->realTableName( $old, "quoted" );
00597             $new = $this->db->realTableName( $new, "quoted" );
00598             $this->db->query( "ALTER TABLE $old RENAME TO $new" );
00599             if ( $patch !== false ) {
00600                 $this->applyPatch( $patch );
00601             }
00602         }
00603     }
00604 
00605     protected function renameIndex(
00606         $table, $old, $new, $skipBothIndexExistWarning = false, $a = false, $b = false
00607     ) {
00608         // First requirement: the table must exist
00609         if ( !$this->db->tableExists( $table, __METHOD__ ) ) {
00610             $this->output( "...skipping: '$table' table doesn't exist yet.\n" );
00611 
00612             return;
00613         }
00614 
00615         // Second requirement: the new index must be missing
00616         if ( $this->db->indexExists( $table, $new, __METHOD__ ) ) {
00617             $this->output( "...index $new already set on $table table.\n" );
00618             if ( !$skipBothIndexExistWarning
00619                 && $this->db->indexExists( $table, $old, __METHOD__ )
00620             ) {
00621                 $this->output( "...WARNING: $old still exists, despite it has been " .
00622                     "renamed into $new (which also exists).\n" .
00623                     "            $old should be manually removed if not needed anymore.\n" );
00624             }
00625 
00626             return;
00627         }
00628 
00629         // Third requirement: the old index must exist
00630         if ( !$this->db->indexExists( $table, $old, __METHOD__ ) ) {
00631             $this->output( "...skipping: index $old doesn't exist.\n" );
00632 
00633             return;
00634         }
00635 
00636         $this->db->query( "ALTER INDEX $old RENAME TO $new" );
00637     }
00638 
00639     protected function addPgField( $table, $field, $type ) {
00640         $fi = $this->db->fieldInfo( $table, $field );
00641         if ( !is_null( $fi ) ) {
00642             $this->output( "...column '$table.$field' already exists\n" );
00643 
00644             return;
00645         } else {
00646             $this->output( "Adding column '$table.$field'\n" );
00647             $this->db->query( "ALTER TABLE $table ADD $field $type" );
00648         }
00649     }
00650 
00651     protected function changeField( $table, $field, $newtype, $default ) {
00652         $fi = $this->db->fieldInfo( $table, $field );
00653         if ( is_null( $fi ) ) {
00654             $this->output( "...ERROR: expected column $table.$field to exist\n" );
00655             exit( 1 );
00656         }
00657 
00658         if ( $fi->type() === $newtype ) {
00659             $this->output( "...column '$table.$field' is already of type '$newtype'\n" );
00660         } else {
00661             $this->output( "Changing column type of '$table.$field' from '{$fi->type()}' to '$newtype'\n" );
00662             $sql = "ALTER TABLE $table ALTER $field TYPE $newtype";
00663             if ( strlen( $default ) ) {
00664                 $res = array();
00665                 if ( preg_match( '/DEFAULT (.+)/', $default, $res ) ) {
00666                     $sqldef = "ALTER TABLE $table ALTER $field SET DEFAULT $res[1]";
00667                     $this->db->query( $sqldef );
00668                     $default = preg_replace( '/\s*DEFAULT .+/', '', $default );
00669                 }
00670                 $sql .= " USING $default";
00671             }
00672             $this->db->query( $sql );
00673         }
00674     }
00675 
00676     protected function changeFieldPurgeTable( $table, $field, $newtype, $default ) {
00677         ## For a cache table, empty it if the field needs to be changed, because the old contents
00678         ## may be corrupted.  If the column is already the desired type, refrain from purging.
00679         $fi = $this->db->fieldInfo( $table, $field );
00680         if ( is_null( $fi ) ) {
00681             $this->output( "...ERROR: expected column $table.$field to exist\n" );
00682             exit( 1 );
00683         }
00684 
00685         if ( $fi->type() === $newtype ) {
00686             $this->output( "...column '$table.$field' is already of type '$newtype'\n" );
00687         } else {
00688             $this->output( "Purging data from cache table '$table'\n" );
00689             $this->db->query("DELETE from $table" );
00690             $this->output( "Changing column type of '$table.$field' from '{$fi->type()}' to '$newtype'\n" );
00691             $sql = "ALTER TABLE $table ALTER $field TYPE $newtype";
00692             if ( strlen( $default ) ) {
00693                 $res = array();
00694                 if ( preg_match( '/DEFAULT (.+)/', $default, $res ) ) {
00695                     $sqldef = "ALTER TABLE $table ALTER $field SET DEFAULT $res[1]";
00696                     $this->db->query( $sqldef );
00697                     $default = preg_replace( '/\s*DEFAULT .+/', '', $default );
00698                 }
00699                 $sql .= " USING $default";
00700             }
00701             $this->db->query( $sql );
00702         }
00703     }
00704 
00705     protected function setDefault( $table, $field, $default ) {
00706 
00707         $info = $this->db->fieldInfo( $table, $field );
00708         if ( $info->defaultValue() !== $default ) {
00709             $this->output( "Changing '$table.$field' default value\n" );
00710             $this->db->query( "ALTER TABLE $table ALTER $field SET DEFAULT " . $default );
00711         }
00712     }
00713 
00714     protected function changeNullableField( $table, $field, $null ) {
00715         $fi = $this->db->fieldInfo( $table, $field );
00716         if ( is_null( $fi ) ) {
00717             $this->output( "...ERROR: expected column $table.$field to exist\n" );
00718             exit( 1 );
00719         }
00720         if ( $fi->isNullable() ) {
00721             # # It's NULL - does it need to be NOT NULL?
00722             if ( 'NOT NULL' === $null ) {
00723                 $this->output( "Changing '$table.$field' to not allow NULLs\n" );
00724                 $this->db->query( "ALTER TABLE $table ALTER $field SET NOT NULL" );
00725             } else {
00726                 $this->output( "...column '$table.$field' is already set as NULL\n" );
00727             }
00728         } else {
00729             # # It's NOT NULL - does it need to be NULL?
00730             if ( 'NULL' === $null ) {
00731                 $this->output( "Changing '$table.$field' to allow NULLs\n" );
00732                 $this->db->query( "ALTER TABLE $table ALTER $field DROP NOT NULL" );
00733             } else {
00734                 $this->output( "...column '$table.$field' is already set as NOT NULL\n" );
00735             }
00736         }
00737     }
00738 
00739     public function addPgIndex( $table, $index, $type ) {
00740         if ( $this->db->indexExists( $table, $index ) ) {
00741             $this->output( "...index '$index' on table '$table' already exists\n" );
00742         } else {
00743             $this->output( "Creating index '$index' on table '$table' $type\n" );
00744             $this->db->query( "CREATE INDEX $index ON $table $type" );
00745         }
00746     }
00747 
00748     public function addPgExtIndex( $table, $index, $type ) {
00749         if ( $this->db->indexExists( $table, $index ) ) {
00750             $this->output( "...index '$index' on table '$table' already exists\n" );
00751         } else {
00752             if ( preg_match( '/^\(/', $type ) ) {
00753                 $this->output( "Creating index '$index' on table '$table'\n" );
00754                 $this->db->query( "CREATE INDEX $index ON $table $type" );
00755             } else {
00756                 $this->applyPatch( $type, true, "Creating index '$index' on table '$table'" );
00757             }
00758         }
00759     }
00760 
00761     protected function changeFkeyDeferrable( $table, $field, $clause ) {
00762         $fi = $this->db->fieldInfo( $table, $field );
00763         if ( is_null( $fi ) ) {
00764             $this->output( "WARNING! Column '$table.$field' does not exist but it should! " .
00765                 "Please report this.\n" );
00766 
00767             return;
00768         }
00769         if ( $fi->is_deferred() && $fi->is_deferrable() ) {
00770             return;
00771         }
00772         $this->output( "Altering column '$table.$field' to be DEFERRABLE INITIALLY DEFERRED\n" );
00773         $conname = $fi->conname();
00774         if ( $fi->conname() ) {
00775             $conclause = "CONSTRAINT \"$conname\"";
00776             $command = "ALTER TABLE $table DROP CONSTRAINT $conname";
00777             $this->db->query( $command );
00778         } else {
00779             $this->output( "Column '$table.$field' does not have a foreign key " .
00780                 "constraint, will be added\n" );
00781             $conclause = "";
00782         }
00783         $command =
00784             "ALTER TABLE $table ADD $conclause " .
00785             "FOREIGN KEY ($field) REFERENCES $clause DEFERRABLE INITIALLY DEFERRED";
00786         $this->db->query( $command );
00787     }
00788 
00789     protected function convertArchive2() {
00790         if ( $this->db->tableExists( "archive2" ) ) {
00791             if ( $this->db->ruleExists( 'archive', 'archive_insert' ) ) {
00792                 $this->output( "Dropping rule 'archive_insert'\n" );
00793                 $this->db->query( 'DROP RULE archive_insert ON archive' );
00794             }
00795             if ( $this->db->ruleExists( 'archive', 'archive_delete' ) ) {
00796                 $this->output( "Dropping rule 'archive_delete'\n" );
00797                 $this->db->query( 'DROP RULE archive_delete ON archive' );
00798             }
00799             $this->applyPatch(
00800                 'patch-remove-archive2.sql',
00801                 false,
00802                 "Converting 'archive2' back to normal archive table"
00803             );
00804         } else {
00805             $this->output( "...obsolete table 'archive2' does not exist\n" );
00806         }
00807     }
00808 
00809     protected function checkOiDeleted() {
00810         if ( $this->db->fieldInfo( 'oldimage', 'oi_deleted' )->type() !== 'smallint' ) {
00811             $this->output( "Changing 'oldimage.oi_deleted' to type 'smallint'\n" );
00812             $this->db->query( "ALTER TABLE oldimage ALTER oi_deleted DROP DEFAULT" );
00813             $this->db->query(
00814                 "ALTER TABLE oldimage ALTER oi_deleted TYPE SMALLINT USING (oi_deleted::smallint)" );
00815             $this->db->query( "ALTER TABLE oldimage ALTER oi_deleted SET DEFAULT 0" );
00816         } else {
00817             $this->output( "...column 'oldimage.oi_deleted' is already of type 'smallint'\n" );
00818         }
00819     }
00820 
00821     protected function checkOiNameConstraint() {
00822         if ( $this->db->hasConstraint( "oldimage_oi_name_fkey_cascaded" ) ) {
00823             $this->output( "...table 'oldimage' has correct cascading delete/update " .
00824                 "foreign key to image\n" );
00825         } else {
00826             if ( $this->db->hasConstraint( "oldimage_oi_name_fkey" ) ) {
00827                 $this->db->query(
00828                     "ALTER TABLE oldimage DROP CONSTRAINT oldimage_oi_name_fkey" );
00829             }
00830             if ( $this->db->hasConstraint( "oldimage_oi_name_fkey_cascade" ) ) {
00831                 $this->db->query(
00832                     "ALTER TABLE oldimage DROP CONSTRAINT oldimage_oi_name_fkey_cascade" );
00833             }
00834             $this->output( "Making foreign key on table 'oldimage' (to image) a cascade delete/update\n" );
00835             $this->db->query(
00836                 "ALTER TABLE oldimage ADD CONSTRAINT oldimage_oi_name_fkey_cascaded " .
00837                 "FOREIGN KEY (oi_name) REFERENCES image(img_name) " .
00838                 "ON DELETE CASCADE ON UPDATE CASCADE" );
00839         }
00840     }
00841 
00842     protected function checkPageDeletedTrigger() {
00843         if ( !$this->db->triggerExists( 'page', 'page_deleted' ) ) {
00844             $this->applyPatch(
00845                 'patch-page_deleted.sql',
00846                 false,
00847                 "Adding function and trigger 'page_deleted' to table 'page'"
00848             );
00849         } else {
00850             $this->output( "...table 'page' has 'page_deleted' trigger\n" );
00851         }
00852     }
00853 
00854     protected function dropIndex( $table, $index, $patch = '', $fullpath = false ) {
00855         if ( $this->db->indexExists( $table, $index ) ) {
00856             $this->output( "Dropping obsolete index '$index'\n" );
00857             $this->db->query( "DROP INDEX \"" . $index . "\"" );
00858         }
00859     }
00860 
00861     protected function checkIndex( $index, $should_be, $good_def ) {
00862         $pu = $this->db->indexAttributes( $index );
00863         if ( !empty( $pu ) && $pu != $should_be ) {
00864             $this->output( "Dropping obsolete version of index '$index'\n" );
00865             $this->db->query( "DROP INDEX \"" . $index . "\"" );
00866             $pu = array();
00867         } else {
00868             $this->output( "...no need to drop index '$index'\n" );
00869         }
00870 
00871         if ( empty( $pu ) ) {
00872             $this->output( "Creating index '$index'\n" );
00873             $this->db->query( $good_def );
00874         } else {
00875             $this->output( "...index '$index' exists\n" );
00876         }
00877     }
00878 
00879     protected function checkRevUserFkey() {
00880         if ( $this->fkeyDeltype( 'revision_rev_user_fkey' ) == 'r' ) {
00881             $this->output( "...constraint 'revision_rev_user_fkey' is ON DELETE RESTRICT\n" );
00882         } else {
00883             $this->applyPatch(
00884                 'patch-revision_rev_user_fkey.sql',
00885                 false,
00886                 "Changing constraint 'revision_rev_user_fkey' to ON DELETE RESTRICT"
00887             );
00888         }
00889     }
00890 
00891     protected function checkIwlPrefix() {
00892         if ( $this->db->indexExists( 'iwlinks', 'iwl_prefix' ) ) {
00893             $this->applyPatch(
00894                 'patch-rename-iwl_prefix.sql',
00895                 false,
00896                 "Replacing index 'iwl_prefix' with 'iwl_prefix_title_from'"
00897             );
00898         }
00899     }
00900 
00901     protected function addInterwikiType() {
00902         $this->applyPatch( 'patch-add_interwiki.sql', false, "Refreshing add_interwiki()" );
00903     }
00904 
00905     protected function tsearchFixes() {
00906         # Tweak the page_title tsearch2 trigger to filter out slashes
00907         # This is create or replace, so harmless to call if not needed
00908         $this->applyPatch( 'patch-ts2pagetitle.sql', false, "Refreshing ts2_page_title()" );
00909 
00910         # If the server is 8.3 or higher, rewrite the tsearch2 triggers
00911         # in case they have the old 'default' versions
00912         # Gather version numbers in case we need them
00913         if ( $this->db->getServerVersion() >= 8.3 ) {
00914             $this->applyPatch( 'patch-tsearch2funcs.sql', false, "Rewriting tsearch2 triggers" );
00915         }
00916     }
00917 }