MediaWiki
REL1_24
|
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', 'watchlist', 'wl_user_notificationtimestamp', '(wl_user, wl_notificationtimestamp)' ), 00254 array( 'addPgIndex', 'logging', 'logging_user_type_time', 00255 '(log_user, log_type, log_timestamp)' ), 00256 array( 'addPgIndex', 'logging', 'logging_page_id_time', '(log_page,log_timestamp)' ), 00257 array( 'addPgIndex', 'iwlinks', 'iwl_prefix_from_title', '(iwl_prefix, iwl_from, iwl_title)' ), 00258 array( 'addPgIndex', 'iwlinks', 'iwl_prefix_title_from', '(iwl_prefix, iwl_title, iwl_from)' ), 00259 array( 'addPgIndex', 'job', 'job_timestamp_idx', '(job_timestamp)' ), 00260 array( 'addPgIndex', 'job', 'job_sha1', '(job_sha1)' ), 00261 array( 'addPgIndex', 'job', 'job_cmd_token', '(job_cmd, job_token, job_random)' ), 00262 array( 'addPgIndex', 'job', 'job_cmd_token_id', '(job_cmd, job_token, job_id)' ), 00263 array( 'addPgIndex', 'filearchive', 'fa_sha1', '(fa_sha1)' ), 00264 array( 'addPgIndex', 'logging', 'logging_user_text_type_time', 00265 '(log_user_text, log_type, log_timestamp)' ), 00266 array( 'addPgIndex', 'logging', 'logging_user_text_time', '(log_user_text, log_timestamp)' ), 00267 00268 array( 'checkIndex', 'pagelink_unique', array( 00269 array( 'pl_from', 'int4_ops', 'btree', 0 ), 00270 array( 'pl_namespace', 'int2_ops', 'btree', 0 ), 00271 array( 'pl_title', 'text_ops', 'btree', 0 ), 00272 ), 00273 'CREATE UNIQUE INDEX pagelink_unique ON pagelinks (pl_from,pl_namespace,pl_title)' ), 00274 array( 'checkIndex', 'cl_sortkey', array( 00275 array( 'cl_to', 'text_ops', 'btree', 0 ), 00276 array( 'cl_sortkey', 'text_ops', 'btree', 0 ), 00277 array( 'cl_from', 'int4_ops', 'btree', 0 ), 00278 ), 00279 'CREATE INDEX cl_sortkey ON "categorylinks" ' . 00280 'USING "btree" ("cl_to", "cl_sortkey", "cl_from")' ), 00281 array( 'checkIndex', 'iwl_prefix_title_from', array( 00282 array( 'iwl_prefix', 'text_ops', 'btree', 0 ), 00283 array( 'iwl_title', 'text_ops', 'btree', 0 ), 00284 array( 'iwl_from', 'int4_ops', 'btree', 0 ), 00285 ), 00286 'CREATE INDEX iwl_prefix_title_from ON "iwlinks" ' . 00287 'USING "btree" ("iwl_prefix", "iwl_title", "iwl_from")' ), 00288 array( 'checkIndex', 'logging_times', array( 00289 array( 'log_timestamp', 'timestamptz_ops', 'btree', 0 ), 00290 ), 00291 'CREATE INDEX "logging_times" ON "logging" USING "btree" ("log_timestamp")' ), 00292 array( 'dropIndex', 'oldimage', 'oi_name' ), 00293 array( 'checkIndex', 'oi_name_archive_name', array( 00294 array( 'oi_name', 'text_ops', 'btree', 0 ), 00295 array( 'oi_archive_name', 'text_ops', 'btree', 0 ), 00296 ), 00297 'CREATE INDEX "oi_name_archive_name" ON "oldimage" ' . 00298 'USING "btree" ("oi_name", "oi_archive_name")' ), 00299 array( 'checkIndex', 'oi_name_timestamp', array( 00300 array( 'oi_name', 'text_ops', 'btree', 0 ), 00301 array( 'oi_timestamp', 'timestamptz_ops', 'btree', 0 ), 00302 ), 00303 'CREATE INDEX "oi_name_timestamp" ON "oldimage" ' . 00304 'USING "btree" ("oi_name", "oi_timestamp")' ), 00305 array( 'checkIndex', 'page_main_title', array( 00306 array( 'page_title', 'text_pattern_ops', 'btree', 0 ), 00307 ), 00308 'CREATE INDEX "page_main_title" ON "page" ' . 00309 'USING "btree" ("page_title" "text_pattern_ops") WHERE ("page_namespace" = 0)' ), 00310 array( 'checkIndex', 'page_mediawiki_title', array( 00311 array( 'page_title', 'text_pattern_ops', 'btree', 0 ), 00312 ), 00313 'CREATE INDEX "page_mediawiki_title" ON "page" ' . 00314 'USING "btree" ("page_title" "text_pattern_ops") WHERE ("page_namespace" = 8)' ), 00315 array( 'checkIndex', 'page_project_title', array( 00316 array( 'page_title', 'text_pattern_ops', 'btree', 0 ), 00317 ), 00318 'CREATE INDEX "page_project_title" ON "page" ' . 00319 'USING "btree" ("page_title" "text_pattern_ops") ' . 00320 'WHERE ("page_namespace" = 4)' ), 00321 array( 'checkIndex', 'page_talk_title', array( 00322 array( 'page_title', 'text_pattern_ops', 'btree', 0 ), 00323 ), 00324 'CREATE INDEX "page_talk_title" ON "page" ' . 00325 'USING "btree" ("page_title" "text_pattern_ops") ' . 00326 'WHERE ("page_namespace" = 1)' ), 00327 array( 'checkIndex', 'page_user_title', array( 00328 array( 'page_title', 'text_pattern_ops', 'btree', 0 ), 00329 ), 00330 'CREATE INDEX "page_user_title" ON "page" ' . 00331 'USING "btree" ("page_title" "text_pattern_ops") WHERE ' . 00332 '("page_namespace" = 2)' ), 00333 array( 'checkIndex', 'page_utalk_title', array( 00334 array( 'page_title', 'text_pattern_ops', 'btree', 0 ), 00335 ), 00336 'CREATE INDEX "page_utalk_title" ON "page" ' . 00337 'USING "btree" ("page_title" "text_pattern_ops") ' . 00338 'WHERE ("page_namespace" = 3)' ), 00339 array( 'checkIndex', 'ts2_page_text', array( 00340 array( 'textvector', 'tsvector_ops', 'gist', 0 ), 00341 ), 00342 'CREATE INDEX "ts2_page_text" ON "pagecontent" USING "gist" ("textvector")' ), 00343 array( 'checkIndex', 'ts2_page_title', array( 00344 array( 'titlevector', 'tsvector_ops', 'gist', 0 ), 00345 ), 00346 'CREATE INDEX "ts2_page_title" ON "page" USING "gist" ("titlevector")' ), 00347 00348 array( 'checkOiNameConstraint' ), 00349 array( 'checkPageDeletedTrigger' ), 00350 array( 'checkRevUserFkey' ), 00351 array( 'dropIndex', 'ipblocks', 'ipb_address' ), 00352 array( 'checkIndex', 'ipb_address_unique', array( 00353 array( 'ipb_address', 'text_ops', 'btree', 0 ), 00354 array( 'ipb_user', 'int4_ops', 'btree', 0 ), 00355 array( 'ipb_auto', 'int2_ops', 'btree', 0 ), 00356 array( 'ipb_anon_only', 'int2_ops', 'btree', 0 ), 00357 ), 00358 'CREATE UNIQUE INDEX ipb_address_unique ' . 00359 'ON ipblocks (ipb_address,ipb_user,ipb_auto,ipb_anon_only)' ), 00360 00361 array( 'checkIwlPrefix' ), 00362 00363 # All FK columns should be deferred 00364 array( 'changeFkeyDeferrable', 'archive', 'ar_user', 'mwuser(user_id) ON DELETE SET NULL' ), 00365 array( 'changeFkeyDeferrable', 'categorylinks', 'cl_from', 'page(page_id) ON DELETE CASCADE' ), 00366 array( 'changeFkeyDeferrable', 'externallinks', 'el_from', 'page(page_id) ON DELETE CASCADE' ), 00367 array( 'changeFkeyDeferrable', 'filearchive', 'fa_deleted_user', 00368 'mwuser(user_id) ON DELETE SET NULL' ), 00369 array( 'changeFkeyDeferrable', 'filearchive', 'fa_user', 'mwuser(user_id) ON DELETE SET NULL' ), 00370 array( 'changeFkeyDeferrable', 'image', 'img_user', 'mwuser(user_id) ON DELETE SET NULL' ), 00371 array( 'changeFkeyDeferrable', 'imagelinks', 'il_from', 'page(page_id) ON DELETE CASCADE' ), 00372 array( 'changeFkeyDeferrable', 'ipblocks', 'ipb_by', 'mwuser(user_id) ON DELETE CASCADE' ), 00373 array( 'changeFkeyDeferrable', 'ipblocks', 'ipb_user', 'mwuser(user_id) ON DELETE SET NULL' ), 00374 array( 'changeFkeyDeferrable', 'ipblocks', 'ipb_parent_block_id', 00375 'ipblocks(ipb_id) ON DELETE SET NULL' ), 00376 array( 'changeFkeyDeferrable', 'langlinks', 'll_from', 'page(page_id) ON DELETE CASCADE' ), 00377 array( 'changeFkeyDeferrable', 'logging', 'log_user', 'mwuser(user_id) ON DELETE SET NULL' ), 00378 array( 'changeFkeyDeferrable', 'oldimage', 'oi_name', 00379 'image(img_name) ON DELETE CASCADE ON UPDATE CASCADE' ), 00380 array( 'changeFkeyDeferrable', 'oldimage', 'oi_user', 'mwuser(user_id) ON DELETE SET NULL' ), 00381 array( 'changeFkeyDeferrable', 'pagelinks', 'pl_from', 'page(page_id) ON DELETE CASCADE' ), 00382 array( 'changeFkeyDeferrable', 'page_props', 'pp_page', 'page (page_id) ON DELETE CASCADE' ), 00383 array( 'changeFkeyDeferrable', 'page_restrictions', 'pr_page', 00384 'page(page_id) ON DELETE CASCADE' ), 00385 array( 'changeFkeyDeferrable', 'protected_titles', 'pt_user', 00386 'mwuser(user_id) ON DELETE SET NULL' ), 00387 array( 'changeFkeyDeferrable', 'recentchanges', 'rc_cur_id', 00388 'page(page_id) ON DELETE SET NULL' ), 00389 array( 'changeFkeyDeferrable', 'recentchanges', 'rc_user', 00390 'mwuser(user_id) ON DELETE SET NULL' ), 00391 array( 'changeFkeyDeferrable', 'redirect', 'rd_from', 'page(page_id) ON DELETE CASCADE' ), 00392 array( 'changeFkeyDeferrable', 'revision', 'rev_page', 'page (page_id) ON DELETE CASCADE' ), 00393 array( 'changeFkeyDeferrable', 'revision', 'rev_user', 'mwuser(user_id) ON DELETE RESTRICT' ), 00394 array( 'changeFkeyDeferrable', 'templatelinks', 'tl_from', 'page(page_id) ON DELETE CASCADE' ), 00395 array( 'changeFkeyDeferrable', 'user_groups', 'ug_user', 'mwuser(user_id) ON DELETE CASCADE' ), 00396 array( 'changeFkeyDeferrable', 'user_newtalk', 'user_id', 'mwuser(user_id) ON DELETE CASCADE' ), 00397 array( 'changeFkeyDeferrable', 'user_properties', 'up_user', 00398 'mwuser(user_id) ON DELETE CASCADE' ), 00399 array( 'changeFkeyDeferrable', 'watchlist', 'wl_user', 'mwuser(user_id) ON DELETE CASCADE' ), 00400 00401 # r81574 00402 array( 'addInterwikiType' ), 00403 # end 00404 array( 'tsearchFixes' ), 00405 00406 // 1.23 00407 array( 'addPgField', 'recentchanges', 'rc_source', "TEXT NOT NULL DEFAULT ''" ), 00408 array( 'addPgField', 'page', 'page_links_updated', "TIMESTAMPTZ NULL" ), 00409 array( 'addPgField', 'mwuser', 'user_password_expires', 'TIMESTAMPTZ NULL' ), 00410 array( 'changeFieldPurgeTable', 'l10n_cache', 'lc_value', 'bytea', 00411 "replace(lc_value,'\','\\\\')::bytea" ), 00412 00413 // 1.24 00414 array( 'addPgField', 'page_props', 'pp_sortkey', 'float NULL' ), 00415 array( 'addPgIndex', 'page_props', 'pp_propname_sortkey_page', 00416 '( pp_propname, pp_sortkey, pp_page ) WHERE ( pp_sortkey IS NOT NULL )' ), 00417 array( 'addPgField', 'page', 'page_lang', 'TEXT default NULL' ), 00418 array( 'addPgField', 'pagelinks', 'pl_from_namespace', 'INTEGER NOT NULL DEFAULT 0' ), 00419 array( 'addPgField', 'templatelinks', 'tl_from_namespace', 'INTEGER NOT NULL DEFAULT 0' ), 00420 array( 'addPgField', 'imagelinks', 'il_from_namespace', 'INTEGER NOT NULL DEFAULT 0' ), 00421 ); 00422 } 00423 00424 protected function getOldGlobalUpdates() { 00425 global $wgExtNewTables, $wgExtPGNewFields, $wgExtPGAlteredFields, $wgExtNewIndexes; 00426 00427 $updates = array(); 00428 00429 # Add missing extension tables 00430 foreach ( $wgExtNewTables as $tableRecord ) { 00431 $updates[] = array( 00432 'addTable', $tableRecord[0], $tableRecord[1], true 00433 ); 00434 } 00435 00436 # Add missing extension fields 00437 foreach ( $wgExtPGNewFields as $fieldRecord ) { 00438 $updates[] = array( 00439 'addPgField', $fieldRecord[0], $fieldRecord[1], 00440 $fieldRecord[2] 00441 ); 00442 } 00443 00444 # Change altered columns 00445 foreach ( $wgExtPGAlteredFields as $fieldRecord ) { 00446 $updates[] = array( 00447 'changeField', $fieldRecord[0], $fieldRecord[1], 00448 $fieldRecord[2] 00449 ); 00450 } 00451 00452 # Add missing extension indexes 00453 foreach ( $wgExtNewIndexes as $fieldRecord ) { 00454 $updates[] = array( 00455 'addPgExtIndex', $fieldRecord[0], $fieldRecord[1], 00456 $fieldRecord[2] 00457 ); 00458 } 00459 00460 return $updates; 00461 } 00462 00463 protected function describeTable( $table ) { 00464 $q = <<<END 00465 SELECT attname, attnum FROM pg_namespace, pg_class, pg_attribute 00466 WHERE pg_class.relnamespace = pg_namespace.oid 00467 AND attrelid=pg_class.oid AND attnum > 0 00468 AND relname=%s AND nspname=%s 00469 END; 00470 $res = $this->db->query( sprintf( $q, 00471 $this->db->addQuotes( $table ), 00472 $this->db->addQuotes( $this->db->getCoreSchema() ) ) ); 00473 if ( !$res ) { 00474 return null; 00475 } 00476 00477 $cols = array(); 00478 foreach ( $res as $r ) { 00479 $cols[] = array( 00480 "name" => $r[0], 00481 "ord" => $r[1], 00482 ); 00483 } 00484 00485 return $cols; 00486 } 00487 00488 function describeIndex( $idx ) { 00489 // first fetch the key (which is a list of columns ords) and 00490 // the table the index applies to (an oid) 00491 $q = <<<END 00492 SELECT indkey, indrelid FROM pg_namespace, pg_class, pg_index 00493 WHERE nspname=%s 00494 AND pg_class.relnamespace = pg_namespace.oid 00495 AND relname=%s 00496 AND indexrelid=pg_class.oid 00497 END; 00498 $res = $this->db->query( 00499 sprintf( 00500 $q, 00501 $this->db->addQuotes( $this->db->getCoreSchema() ), 00502 $this->db->addQuotes( $idx ) 00503 ) 00504 ); 00505 if ( !$res ) { 00506 return null; 00507 } 00508 if ( !( $r = $this->db->fetchRow( $res ) ) ) { 00509 return null; 00510 } 00511 00512 $indkey = $r[0]; 00513 $relid = intval( $r[1] ); 00514 $indkeys = explode( ' ', $indkey ); 00515 00516 $colnames = array(); 00517 foreach ( $indkeys as $rid ) { 00518 $query = <<<END 00519 SELECT attname FROM pg_class, pg_attribute 00520 WHERE attrelid=$relid 00521 AND attnum=%d 00522 AND attrelid=pg_class.oid 00523 END; 00524 $r2 = $this->db->query( sprintf( $query, $rid ) ); 00525 if ( !$r2 ) { 00526 return null; 00527 } 00528 if ( !( $row2 = $this->db->fetchRow( $r2 ) ) ) { 00529 return null; 00530 } 00531 $colnames[] = $row2[0]; 00532 } 00533 00534 return $colnames; 00535 } 00536 00537 function fkeyDeltype( $fkey ) { 00538 $q = <<<END 00539 SELECT confdeltype FROM pg_constraint, pg_namespace 00540 WHERE connamespace=pg_namespace.oid 00541 AND nspname=%s 00542 AND conname=%s; 00543 END; 00544 $r = $this->db->query( 00545 sprintf( 00546 $q, 00547 $this->db->addQuotes( $this->db->getCoreSchema() ), 00548 $this->db->addQuotes( $fkey ) 00549 ) 00550 ); 00551 if ( !( $row = $this->db->fetchRow( $r ) ) ) { 00552 return null; 00553 } 00554 00555 return $row[0]; 00556 } 00557 00558 function ruleDef( $table, $rule ) { 00559 $q = <<<END 00560 SELECT definition FROM pg_rules 00561 WHERE schemaname = %s 00562 AND tablename = %s 00563 AND rulename = %s 00564 END; 00565 $r = $this->db->query( 00566 sprintf( 00567 $q, 00568 $this->db->addQuotes( $this->db->getCoreSchema() ), 00569 $this->db->addQuotes( $table ), 00570 $this->db->addQuotes( $rule ) 00571 ) 00572 ); 00573 $row = $this->db->fetchRow( $r ); 00574 if ( !$row ) { 00575 return null; 00576 } 00577 $d = $row[0]; 00578 00579 return $d; 00580 } 00581 00582 protected function addSequence( $table, $pkey, $ns ) { 00583 if ( !$this->db->sequenceExists( $ns ) ) { 00584 $this->output( "Creating sequence $ns\n" ); 00585 $this->db->query( "CREATE SEQUENCE $ns" ); 00586 if ( $pkey !== false ) { 00587 $this->setDefault( $table, $pkey, '"nextval"(\'"' . $ns . '"\'::"regclass")' ); 00588 } 00589 } 00590 } 00591 00592 protected function renameSequence( $old, $new ) { 00593 if ( $this->db->sequenceExists( $new ) ) { 00594 $this->output( "...sequence $new already exists.\n" ); 00595 00596 return; 00597 } 00598 if ( $this->db->sequenceExists( $old ) ) { 00599 $this->output( "Renaming sequence $old to $new\n" ); 00600 $this->db->query( "ALTER SEQUENCE $old RENAME TO $new" ); 00601 } 00602 } 00603 00604 protected function renameTable( $old, $new, $patch = false ) { 00605 if ( $this->db->tableExists( $old ) ) { 00606 $this->output( "Renaming table $old to $new\n" ); 00607 $old = $this->db->realTableName( $old, "quoted" ); 00608 $new = $this->db->realTableName( $new, "quoted" ); 00609 $this->db->query( "ALTER TABLE $old RENAME TO $new" ); 00610 if ( $patch !== false ) { 00611 $this->applyPatch( $patch ); 00612 } 00613 } 00614 } 00615 00616 protected function renameIndex( 00617 $table, $old, $new, $skipBothIndexExistWarning = false, $a = false, $b = false 00618 ) { 00619 // First requirement: the table must exist 00620 if ( !$this->db->tableExists( $table, __METHOD__ ) ) { 00621 $this->output( "...skipping: '$table' table doesn't exist yet.\n" ); 00622 00623 return; 00624 } 00625 00626 // Second requirement: the new index must be missing 00627 if ( $this->db->indexExists( $table, $new, __METHOD__ ) ) { 00628 $this->output( "...index $new already set on $table table.\n" ); 00629 if ( !$skipBothIndexExistWarning 00630 && $this->db->indexExists( $table, $old, __METHOD__ ) 00631 ) { 00632 $this->output( "...WARNING: $old still exists, despite it has been " . 00633 "renamed into $new (which also exists).\n" . 00634 " $old should be manually removed if not needed anymore.\n" ); 00635 } 00636 00637 return; 00638 } 00639 00640 // Third requirement: the old index must exist 00641 if ( !$this->db->indexExists( $table, $old, __METHOD__ ) ) { 00642 $this->output( "...skipping: index $old doesn't exist.\n" ); 00643 00644 return; 00645 } 00646 00647 $this->db->query( "ALTER INDEX $old RENAME TO $new" ); 00648 } 00649 00650 protected function addPgField( $table, $field, $type ) { 00651 $fi = $this->db->fieldInfo( $table, $field ); 00652 if ( !is_null( $fi ) ) { 00653 $this->output( "...column '$table.$field' already exists\n" ); 00654 00655 return; 00656 } else { 00657 $this->output( "Adding column '$table.$field'\n" ); 00658 $this->db->query( "ALTER TABLE $table ADD $field $type" ); 00659 } 00660 } 00661 00662 protected function changeField( $table, $field, $newtype, $default ) { 00663 $fi = $this->db->fieldInfo( $table, $field ); 00664 if ( is_null( $fi ) ) { 00665 $this->output( "...ERROR: expected column $table.$field to exist\n" ); 00666 exit( 1 ); 00667 } 00668 00669 if ( $fi->type() === $newtype ) { 00670 $this->output( "...column '$table.$field' is already of type '$newtype'\n" ); 00671 } else { 00672 $this->output( "Changing column type of '$table.$field' from '{$fi->type()}' to '$newtype'\n" ); 00673 $sql = "ALTER TABLE $table ALTER $field TYPE $newtype"; 00674 if ( strlen( $default ) ) { 00675 $res = array(); 00676 if ( preg_match( '/DEFAULT (.+)/', $default, $res ) ) { 00677 $sqldef = "ALTER TABLE $table ALTER $field SET DEFAULT $res[1]"; 00678 $this->db->query( $sqldef ); 00679 $default = preg_replace( '/\s*DEFAULT .+/', '', $default ); 00680 } 00681 $sql .= " USING $default"; 00682 } 00683 $this->db->query( $sql ); 00684 } 00685 } 00686 00687 protected function changeFieldPurgeTable( $table, $field, $newtype, $default ) { 00688 ## For a cache table, empty it if the field needs to be changed, because the old contents 00689 ## may be corrupted. If the column is already the desired type, refrain from purging. 00690 $fi = $this->db->fieldInfo( $table, $field ); 00691 if ( is_null( $fi ) ) { 00692 $this->output( "...ERROR: expected column $table.$field to exist\n" ); 00693 exit( 1 ); 00694 } 00695 00696 if ( $fi->type() === $newtype ) { 00697 $this->output( "...column '$table.$field' is already of type '$newtype'\n" ); 00698 } else { 00699 $this->output( "Purging data from cache table '$table'\n" ); 00700 $this->db->query( "DELETE from $table" ); 00701 $this->output( "Changing column type of '$table.$field' from '{$fi->type()}' to '$newtype'\n" ); 00702 $sql = "ALTER TABLE $table ALTER $field TYPE $newtype"; 00703 if ( strlen( $default ) ) { 00704 $res = array(); 00705 if ( preg_match( '/DEFAULT (.+)/', $default, $res ) ) { 00706 $sqldef = "ALTER TABLE $table ALTER $field SET DEFAULT $res[1]"; 00707 $this->db->query( $sqldef ); 00708 $default = preg_replace( '/\s*DEFAULT .+/', '', $default ); 00709 } 00710 $sql .= " USING $default"; 00711 } 00712 $this->db->query( $sql ); 00713 } 00714 } 00715 00716 protected function setDefault( $table, $field, $default ) { 00717 00718 $info = $this->db->fieldInfo( $table, $field ); 00719 if ( $info->defaultValue() !== $default ) { 00720 $this->output( "Changing '$table.$field' default value\n" ); 00721 $this->db->query( "ALTER TABLE $table ALTER $field SET DEFAULT " . $default ); 00722 } 00723 } 00724 00725 protected function changeNullableField( $table, $field, $null ) { 00726 $fi = $this->db->fieldInfo( $table, $field ); 00727 if ( is_null( $fi ) ) { 00728 $this->output( "...ERROR: expected column $table.$field to exist\n" ); 00729 exit( 1 ); 00730 } 00731 if ( $fi->isNullable() ) { 00732 # # It's NULL - does it need to be NOT NULL? 00733 if ( 'NOT NULL' === $null ) { 00734 $this->output( "Changing '$table.$field' to not allow NULLs\n" ); 00735 $this->db->query( "ALTER TABLE $table ALTER $field SET NOT NULL" ); 00736 } else { 00737 $this->output( "...column '$table.$field' is already set as NULL\n" ); 00738 } 00739 } else { 00740 # # It's NOT NULL - does it need to be NULL? 00741 if ( 'NULL' === $null ) { 00742 $this->output( "Changing '$table.$field' to allow NULLs\n" ); 00743 $this->db->query( "ALTER TABLE $table ALTER $field DROP NOT NULL" ); 00744 } else { 00745 $this->output( "...column '$table.$field' is already set as NOT NULL\n" ); 00746 } 00747 } 00748 } 00749 00750 public function addPgIndex( $table, $index, $type ) { 00751 if ( $this->db->indexExists( $table, $index ) ) { 00752 $this->output( "...index '$index' on table '$table' already exists\n" ); 00753 } else { 00754 $this->output( "Creating index '$index' on table '$table' $type\n" ); 00755 $this->db->query( "CREATE INDEX $index ON $table $type" ); 00756 } 00757 } 00758 00759 public function addPgExtIndex( $table, $index, $type ) { 00760 if ( $this->db->indexExists( $table, $index ) ) { 00761 $this->output( "...index '$index' on table '$table' already exists\n" ); 00762 } else { 00763 if ( preg_match( '/^\(/', $type ) ) { 00764 $this->output( "Creating index '$index' on table '$table'\n" ); 00765 $this->db->query( "CREATE INDEX $index ON $table $type" ); 00766 } else { 00767 $this->applyPatch( $type, true, "Creating index '$index' on table '$table'" ); 00768 } 00769 } 00770 } 00771 00772 protected function changeFkeyDeferrable( $table, $field, $clause ) { 00773 $fi = $this->db->fieldInfo( $table, $field ); 00774 if ( is_null( $fi ) ) { 00775 $this->output( "WARNING! Column '$table.$field' does not exist but it should! " . 00776 "Please report this.\n" ); 00777 00778 return; 00779 } 00780 if ( $fi->is_deferred() && $fi->is_deferrable() ) { 00781 return; 00782 } 00783 $this->output( "Altering column '$table.$field' to be DEFERRABLE INITIALLY DEFERRED\n" ); 00784 $conname = $fi->conname(); 00785 if ( $fi->conname() ) { 00786 $conclause = "CONSTRAINT \"$conname\""; 00787 $command = "ALTER TABLE $table DROP CONSTRAINT $conname"; 00788 $this->db->query( $command ); 00789 } else { 00790 $this->output( "Column '$table.$field' does not have a foreign key " . 00791 "constraint, will be added\n" ); 00792 $conclause = ""; 00793 } 00794 $command = 00795 "ALTER TABLE $table ADD $conclause " . 00796 "FOREIGN KEY ($field) REFERENCES $clause DEFERRABLE INITIALLY DEFERRED"; 00797 $this->db->query( $command ); 00798 } 00799 00800 protected function convertArchive2() { 00801 if ( $this->db->tableExists( "archive2" ) ) { 00802 if ( $this->db->ruleExists( 'archive', 'archive_insert' ) ) { 00803 $this->output( "Dropping rule 'archive_insert'\n" ); 00804 $this->db->query( 'DROP RULE archive_insert ON archive' ); 00805 } 00806 if ( $this->db->ruleExists( 'archive', 'archive_delete' ) ) { 00807 $this->output( "Dropping rule 'archive_delete'\n" ); 00808 $this->db->query( 'DROP RULE archive_delete ON archive' ); 00809 } 00810 $this->applyPatch( 00811 'patch-remove-archive2.sql', 00812 false, 00813 "Converting 'archive2' back to normal archive table" 00814 ); 00815 } else { 00816 $this->output( "...obsolete table 'archive2' does not exist\n" ); 00817 } 00818 } 00819 00820 protected function checkOiDeleted() { 00821 if ( $this->db->fieldInfo( 'oldimage', 'oi_deleted' )->type() !== 'smallint' ) { 00822 $this->output( "Changing 'oldimage.oi_deleted' to type 'smallint'\n" ); 00823 $this->db->query( "ALTER TABLE oldimage ALTER oi_deleted DROP DEFAULT" ); 00824 $this->db->query( 00825 "ALTER TABLE oldimage ALTER oi_deleted TYPE SMALLINT USING (oi_deleted::smallint)" ); 00826 $this->db->query( "ALTER TABLE oldimage ALTER oi_deleted SET DEFAULT 0" ); 00827 } else { 00828 $this->output( "...column 'oldimage.oi_deleted' is already of type 'smallint'\n" ); 00829 } 00830 } 00831 00832 protected function checkOiNameConstraint() { 00833 if ( $this->db->hasConstraint( "oldimage_oi_name_fkey_cascaded" ) ) { 00834 $this->output( "...table 'oldimage' has correct cascading delete/update " . 00835 "foreign key to image\n" ); 00836 } else { 00837 if ( $this->db->hasConstraint( "oldimage_oi_name_fkey" ) ) { 00838 $this->db->query( 00839 "ALTER TABLE oldimage DROP CONSTRAINT oldimage_oi_name_fkey" ); 00840 } 00841 if ( $this->db->hasConstraint( "oldimage_oi_name_fkey_cascade" ) ) { 00842 $this->db->query( 00843 "ALTER TABLE oldimage DROP CONSTRAINT oldimage_oi_name_fkey_cascade" ); 00844 } 00845 $this->output( "Making foreign key on table 'oldimage' (to image) a cascade delete/update\n" ); 00846 $this->db->query( 00847 "ALTER TABLE oldimage ADD CONSTRAINT oldimage_oi_name_fkey_cascaded " . 00848 "FOREIGN KEY (oi_name) REFERENCES image(img_name) " . 00849 "ON DELETE CASCADE ON UPDATE CASCADE" ); 00850 } 00851 } 00852 00853 protected function checkPageDeletedTrigger() { 00854 if ( !$this->db->triggerExists( 'page', 'page_deleted' ) ) { 00855 $this->applyPatch( 00856 'patch-page_deleted.sql', 00857 false, 00858 "Adding function and trigger 'page_deleted' to table 'page'" 00859 ); 00860 } else { 00861 $this->output( "...table 'page' has 'page_deleted' trigger\n" ); 00862 } 00863 } 00864 00865 protected function dropIndex( $table, $index, $patch = '', $fullpath = false ) { 00866 if ( $this->db->indexExists( $table, $index ) ) { 00867 $this->output( "Dropping obsolete index '$index'\n" ); 00868 $this->db->query( "DROP INDEX \"" . $index . "\"" ); 00869 } 00870 } 00871 00872 protected function checkIndex( $index, $should_be, $good_def ) { 00873 $pu = $this->db->indexAttributes( $index ); 00874 if ( !empty( $pu ) && $pu != $should_be ) { 00875 $this->output( "Dropping obsolete version of index '$index'\n" ); 00876 $this->db->query( "DROP INDEX \"" . $index . "\"" ); 00877 $pu = array(); 00878 } else { 00879 $this->output( "...no need to drop index '$index'\n" ); 00880 } 00881 00882 if ( empty( $pu ) ) { 00883 $this->output( "Creating index '$index'\n" ); 00884 $this->db->query( $good_def ); 00885 } else { 00886 $this->output( "...index '$index' exists\n" ); 00887 } 00888 } 00889 00890 protected function checkRevUserFkey() { 00891 if ( $this->fkeyDeltype( 'revision_rev_user_fkey' ) == 'r' ) { 00892 $this->output( "...constraint 'revision_rev_user_fkey' is ON DELETE RESTRICT\n" ); 00893 } else { 00894 $this->applyPatch( 00895 'patch-revision_rev_user_fkey.sql', 00896 false, 00897 "Changing constraint 'revision_rev_user_fkey' to ON DELETE RESTRICT" 00898 ); 00899 } 00900 } 00901 00902 protected function checkIwlPrefix() { 00903 if ( $this->db->indexExists( 'iwlinks', 'iwl_prefix' ) ) { 00904 $this->applyPatch( 00905 'patch-rename-iwl_prefix.sql', 00906 false, 00907 "Replacing index 'iwl_prefix' with 'iwl_prefix_title_from'" 00908 ); 00909 } 00910 } 00911 00912 protected function addInterwikiType() { 00913 $this->applyPatch( 'patch-add_interwiki.sql', false, "Refreshing add_interwiki()" ); 00914 } 00915 00916 protected function tsearchFixes() { 00917 # Tweak the page_title tsearch2 trigger to filter out slashes 00918 # This is create or replace, so harmless to call if not needed 00919 $this->applyPatch( 'patch-ts2pagetitle.sql', false, "Refreshing ts2_page_title()" ); 00920 00921 # If the server is 8.3 or higher, rewrite the tsearch2 triggers 00922 # in case they have the old 'default' versions 00923 # Gather version numbers in case we need them 00924 if ( $this->db->getServerVersion() >= 8.3 ) { 00925 $this->applyPatch( 'patch-tsearch2funcs.sql', false, "Rewriting tsearch2 triggers" ); 00926 } 00927 } 00928 }