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