| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
namespace MediaWiki\Installer; |
| 25 |
|
| 26 |
use FixInconsistentRedirects; |
| 27 |
use MediaWiki\Maintenance\FixAutoblockLogTitles; |
| 28 |
use MigrateExternallinks; |
| 29 |
use MigrateRevisionActorTemp; |
| 30 |
use MigrateRevisionCommentTemp; |
| 31 |
use PopulateUserIsTemp; |
| 32 |
use UpdateRestrictions; |
| 33 |
use Wikimedia\Rdbms\DatabasePostgres; |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
class PostgresUpdater extends DatabaseUpdater { |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
protected $db; |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
protected function getCoreUpdateList() { |
| 52 |
return [ |
| 53 |
|
| 54 |
|
| 55 |
[ 'renameTable', 'pagecontent', 'text' ], |
| 56 |
|
| 57 |
[ 'renameTable', 'mwuser', 'user' ], |
| 58 |
|
| 59 |
|
| 60 |
[ 'setDefault', 'bot_passwords', 'bp_token', '' ], |
| 61 |
[ 'changeField', 'comment', 'comment_id', 'BIGINT', '' ], |
| 62 |
[ 'changeField', 'slots', 'slot_revision_id', 'BIGINT', '' ], |
| 63 |
[ 'changeField', 'slots', 'slot_content_id', 'BIGINT', '' ], |
| 64 |
[ 'changeField', 'slots', 'slot_origin', 'BIGINT', '' ], |
| 65 |
[ 'changeField', 'site_stats', 'ss_total_edits', 'BIGINT', '' ], |
| 66 |
[ 'changeField', 'site_stats', 'ss_good_articles', 'BIGINT', '' ], |
| 67 |
[ 'changeField', 'site_stats', 'ss_total_pages', 'BIGINT', '' ], |
| 68 |
[ 'changeField', 'site_stats', 'ss_users', 'BIGINT', '' ], |
| 69 |
[ 'changeField', 'site_stats', 'ss_active_users', 'BIGINT', '' ], |
| 70 |
[ 'changeField', 'site_stats', 'ss_images', 'BIGINT', '' ], |
| 71 |
[ 'dropFkey', 'user_properties', 'up_user' ], |
| 72 |
[ 'addIndex', 'user_properties', 'user_properties_pkey', 'patch-user_properties-pk.sql' ], |
| 73 |
[ 'changeField', 'log_search', 'ls_value', 'VARCHAR(255)', '' ], |
| 74 |
[ 'changeField', 'content', 'content_id', 'BIGINT', '' ], |
| 75 |
[ 'changeField', 'l10n_cache', 'lc_value', 'TEXT', '' ], |
| 76 |
[ 'changeField', 'l10n_cache', 'lc_key', 'VARCHAR(255)', '' ], |
| 77 |
[ 'addIndex', 'l10n_cache', 'l10n_cache_pkey', 'patch-l10n_cache-pk.sql' ], |
| 78 |
[ 'addIndex', 'module_deps', 'module_deps_pkey', 'patch-module_deps-pk.sql' ], |
| 79 |
[ 'changeField', 'redirect', 'rd_namespace', 'INT', 'rd_namespace::INT DEFAULT 0' ], |
| 80 |
[ 'setDefault', 'redirect', 'rd_title', '' ], |
| 81 |
[ 'setDefault', 'redirect', 'rd_from', 0 ], |
| 82 |
[ 'dropFkey', 'redirect', 'rd_from' ], |
| 83 |
[ 'changeField', 'redirect', 'rd_interwiki', 'VARCHAR(32)', '' ], |
| 84 |
[ 'dropFkey', 'pagelinks', 'pl_from' ], |
| 85 |
[ 'dropPgIndex', 'pagelinks', 'pagelink_unique' ], |
| 86 |
[ 'dropPgIndex', 'pagelinks', 'pagelinks_title' ], |
| 87 |
[ 'dropFkey', 'templatelinks', 'tl_from' ], |
| 88 |
[ 'dropPgIndex', 'templatelinks', 'templatelinks_unique' ], |
| 89 |
[ 'dropPgIndex', 'templatelinks', 'templatelinks_from' ], |
| 90 |
[ 'dropFkey', 'imagelinks', 'il_from' ], |
| 91 |
[ 'setDefault', 'imagelinks', 'il_to', '' ], |
| 92 |
[ 'addPgIndex', 'imagelinks', 'il_to', '(il_to, il_from)' ], |
| 93 |
[ 'addPgIndex', 'imagelinks', 'il_backlinks_namespace', |
| 94 |
'(il_from_namespace, il_to, il_from)' ], |
| 95 |
[ 'dropPgIndex', 'imagelinks', 'il_from' ], |
| 96 |
[ 'dropFkey', 'langlinks', 'll_from' ], |
| 97 |
[ 'addIndex', 'langlinks', 'langlinks_pkey', 'patch-langlinks-pk.sql' ], |
| 98 |
[ 'renameIndex', 'langlinks', 'langlinks_lang_title', 'll_lang' ], |
| 99 |
[ 'setDefault', 'langlinks', 'll_lang', '' ], |
| 100 |
[ 'setDefault', 'langlinks', 'll_from', 0 ], |
| 101 |
[ 'setDefault', 'langlinks', 'll_title', '' ], |
| 102 |
[ 'changeNullableField', 'langlinks', 'll_lang', 'NOT NULL', true ], |
| 103 |
[ 'changeNullableField', 'langlinks', 'll_title', 'NOT NULL', true ], |
| 104 |
[ 'addIndex', 'iwlinks', 'iwlinks_pkey', 'patch-iwlinks-pk.sql' ], |
| 105 |
[ 'renameIndex', 'category', 'category_title', 'cat_title' ], |
| 106 |
[ 'renameIndex', 'category', 'category_pages', 'cat_pages' ], |
| 107 |
[ 'dropSequence', 'watchlist_expiry', 'watchlist_expiry_we_item_seq' ], |
| 108 |
[ 'changeField', 'change_tag_def', 'ctd_count', 'BIGINT', 'ctd_count::BIGINT DEFAULT 0' ], |
| 109 |
[ 'dropDefault', 'change_tag_def', 'ctd_user_defined' ], |
| 110 |
[ 'dropFkey', 'ipblocks_restrictions', 'ir_ipb_id' ], |
| 111 |
[ 'setDefault', 'querycache', 'qc_value', 0 ], |
| 112 |
[ 'changeField', 'querycache', 'qc_namespace', 'INT', 'qc_namespace::INT DEFAULT 0' ], |
| 113 |
[ 'setDefault', 'querycache', 'qc_title', '' ], |
| 114 |
[ 'renameIndex', 'querycache', 'querycache_type_value', 'qc_type' ], |
| 115 |
[ 'renameIndex', 'querycachetwo', 'querycachetwo_type_value', 'qcc_type' ], |
| 116 |
[ 'renameIndex', 'querycachetwo', 'querycachetwo_title', 'qcc_title' ], |
| 117 |
[ 'renameIndex', 'querycachetwo', 'querycachetwo_titletwo', 'qcc_titletwo' ], |
| 118 |
[ 'dropFkey', 'page_restrictions', 'pr_page' ], |
| 119 |
[ 'addPgIndex', 'page_restrictions', 'pr_pagetype', '(pr_page, pr_type)', true ], |
| 120 |
[ 'addPgIndex', 'page_restrictions', 'pr_typelevel', '(pr_type, pr_level)' ], |
| 121 |
[ 'addPgIndex', 'page_restrictions', 'pr_level', '(pr_level)' ], |
| 122 |
[ 'addPgIndex', 'page_restrictions', 'pr_cascade', '(pr_cascade)' ], |
| 123 |
[ 'changePrimaryKey', 'page_restrictions', [ 'pr_id' ], 'page_restrictions_pk' ], |
| 124 |
[ 'changeNullableField', 'page_restrictions', 'pr_page', 'NOT NULL', true ], |
| 125 |
[ 'dropFkey', 'user_groups', 'ug_user' ], |
| 126 |
[ 'setDefault', 'user_groups', 'ug_user', 0 ], |
| 127 |
[ 'setDefault', 'user_groups', 'ug_group', '' ], |
| 128 |
[ 'renameIndex', 'user_groups', 'user_groups_group', 'ug_group' ], |
| 129 |
[ 'renameIndex', 'user_groups', 'user_groups_expiry', 'ug_expiry' ], |
| 130 |
[ 'setDefault', 'querycache_info', 'qci_type', '' ], |
| 131 |
[ 'setDefault', 'querycache_info', 'qci_timestamp', '1970-01-01 00:00:00+00' ], |
| 132 |
[ 'changeNullableField', 'querycache_info', 'qci_type', 'NOT NULL', true ], |
| 133 |
[ 'changeNullableField', 'querycache_info', 'qci_timestamp', 'NOT NULL', true ], |
| 134 |
[ 'addIndex', 'querycache_info', 'querycache_info_pkey', 'patch-querycache_info-pk.sql' ], |
| 135 |
[ 'setDefault', 'watchlist', 'wl_title', '' ], |
| 136 |
[ 'changeField', 'watchlist', 'wl_namespace', 'INT', 'wl_namespace::INT DEFAULT 0' ], |
| 137 |
[ 'dropFkey', 'watchlist', 'wl_user' ], |
| 138 |
[ 'dropPgIndex', 'watchlist', 'wl_user_namespace_title' ], |
| 139 |
[ 'addPgIndex', 'watchlist', 'namespace_title', '(wl_namespace, wl_title)' ], |
| 140 |
[ 'checkIndex', 'wl_user', [ |
| 141 |
[ 'wl_user', 'text_ops', 'btree', 1 ], |
| 142 |
[ 'wl_namespace', 'int4_ops', 'btree', 1 ], |
| 143 |
[ 'wl_title', 'text_ops', 'btree', 1 ], |
| 144 |
], |
| 145 |
'CREATE UNIQUE INDEX "wl_user" ON "watchlist" (wl_user, wl_namespace, wl_title)' |
| 146 |
], |
| 147 |
[ 'changeField', 'sites', 'site_domain', 'VARCHAR(255)', '' ], |
| 148 |
[ 'renameIndex', 'sites', 'site_global_key', 'sites_global_key' ], |
| 149 |
[ 'renameIndex', 'sites', 'site_type', 'sites_type' ], |
| 150 |
[ 'renameIndex', 'sites', 'site_group', 'sites_group' ], |
| 151 |
[ 'renameIndex', 'sites', 'site_source', 'sites_source' ], |
| 152 |
[ 'renameIndex', 'sites', 'site_language', 'sites_language' ], |
| 153 |
[ 'renameIndex', 'sites', 'site_protocol', 'sites_protocol' ], |
| 154 |
[ 'renameIndex', 'sites', 'site_domain', 'sites_domain' ], |
| 155 |
[ 'renameIndex', 'sites', 'site_forward', 'sites_forward' ], |
| 156 |
[ 'dropFkey', 'user_newtalk', 'user_id' ], |
| 157 |
[ 'renameIndex', 'user_newtalk', 'user_newtalk_id', 'un_user_id' ], |
| 158 |
[ 'renameIndex', 'user_newtalk', 'user_newtalk_ip', 'un_user_ip' ], |
| 159 |
[ 'changeField', 'interwiki', 'iw_prefix', 'VARCHAR(32)', '' ], |
| 160 |
[ 'changeField', 'interwiki', 'iw_wikiid', 'VARCHAR(64)', '' ], |
| 161 |
[ 'dropFkey', 'protected_titles', 'pt_user' ], |
| 162 |
[ 'changeNullableField', 'protected_titles', 'pt_user', 'NOT NULL', true ], |
| 163 |
[ 'changeNullableField', 'protected_titles', 'pt_expiry', 'NOT NULL', true ], |
| 164 |
[ 'changeField', 'protected_titles', 'pt_reason_id', 'BIGINT', '' ], |
| 165 |
[ 'dropDefault', 'protected_titles', 'pt_create_perm' ], |
| 166 |
[ 'dropFkey', 'externallinks', 'el_from' ], |
| 167 |
[ 'renameIndex', 'externallinks', 'externallinks_from_to', 'el_from' ], |
| 168 |
[ 'renameIndex', 'externallinks', 'externallinks_index', 'el_index' ], |
| 169 |
[ 'dropSequence', 'ip_changes', 'ip_changes_ipc_rev_id_seq' ], |
| 170 |
[ 'changeField', 'ip_changes', 'ipc_hex', 'TEXT', "ipc_hex::TEXT DEFAULT ''" ], |
| 171 |
[ 'setDefault', 'ip_changes', 'ipc_rev_id', 0 ], |
| 172 |
[ 'renameIndex', 'watchlist', 'namespace_title', 'wl_namespace_title' ], |
| 173 |
[ 'dropFkey', 'page_props', 'pp_page' ], |
| 174 |
|
| 175 |
[ 'changePrimaryKey', 'page_props', [ 'pp_page', 'pp_propname' ], 'page_props_pk' ], |
| 176 |
[ 'setDefault', 'job', 'job_cmd', '' ], |
| 177 |
[ 'changeField', 'job', 'job_namespace', 'INTEGER', '' ], |
| 178 |
[ 'dropPgIndex', 'job', 'job_cmd_namespace_title' ], |
| 179 |
[ 'addPgIndex', 'job', 'job_cmd', '(job_cmd, job_namespace, job_title, job_params)' ], |
| 180 |
[ 'renameIndex', 'job', 'job_timestamp_idx', 'job_timestamp' ], |
| 181 |
[ 'changeField', 'slot_roles', 'role_id', 'INTEGER', '' ], |
| 182 |
[ 'changeField', 'content_models', 'model_id', 'INTEGER', '' ], |
| 183 |
[ 'renameIndex', 'page', 'page_len_idx', 'page_len' ], |
| 184 |
[ 'renameIndex', 'page', 'page_random_idx', 'page_random' ], |
| 185 |
[ 'renameIndex', 'page', 'page_unique_name', 'page_name_title' ], |
| 186 |
[ 'addPGIndex', 'page', 'page_redirect_namespace_len', '(page_is_redirect, page_namespace, page_len)' ], |
| 187 |
[ 'dropFkey', 'categorylinks', 'cl_from' ], |
| 188 |
[ 'setDefault', 'categorylinks', 'cl_from', 0 ], |
| 189 |
[ 'setDefault', 'categorylinks', 'cl_to', '' ], |
| 190 |
[ 'setDefault', 'categorylinks', 'cl_sortkey', '' ], |
| 191 |
[ 'setDefault', 'categorylinks', 'cl_collation', '' ], |
| 192 |
[ 'changeNullableField', 'categorylinks', 'cl_sortkey', 'NOT NULL', true ], |
| 193 |
[ 'addIndex', 'categorylinks', 'categorylinks_pkey', 'patch-categorylinks-pk.sql' ], |
| 194 |
[ 'addPgIndex', 'categorylinks', 'cl_timestamp', '(cl_to, cl_timestamp)' ], |
| 195 |
[ 'addPgIndex', 'categorylinks', 'cl_collation_ext', '(cl_collation, cl_to, cl_type, cl_from)' ], |
| 196 |
[ 'checkIndex', 'cl_sortkey', [ |
| 197 |
[ 'cl_to', 'text_ops', 'btree', 1 ], |
| 198 |
[ 'cl_type', 'text_ops', 'btree', 1 ], |
| 199 |
[ 'cl_sortkey', 'text_ops', 'btree', 1 ], |
| 200 |
[ 'cl_from', 'text_ops', 'btree', 1 ], |
| 201 |
], |
| 202 |
'CREATE INDEX cl_sortkey ON categorylinks (cl_to, cl_type, cl_sortkey, cl_from)' |
| 203 |
], |
| 204 |
[ 'renameIndex', 'logging', 'logging_type_name', 'type_time' ], |
| 205 |
[ 'renameIndex', 'logging', 'logging_actor_time_backwards', 'actor_time' ], |
| 206 |
[ 'renameIndex', 'logging', 'logging_page_time', 'page_time' ], |
| 207 |
[ 'renameIndex', 'logging', 'logging_times', 'times' ], |
| 208 |
[ 'renameIndex', 'logging', 'logging_actor_type_time', 'log_actor_type_time' ], |
| 209 |
[ 'renameIndex', 'logging', 'logging_page_id_time', 'log_page_id_time' ], |
| 210 |
[ 'renameIndex', 'logging', 'logging_type_action', 'log_type_action' ], |
| 211 |
[ 'changeNullableField', 'logging', 'log_params', 'NOT NULL', true ], |
| 212 |
[ 'setDefault', 'logging', 'log_action', '' ], |
| 213 |
[ 'setDefault', 'logging', 'log_type', '' ], |
| 214 |
[ 'setDefault', 'logging', 'log_title', '' ], |
| 215 |
[ 'setDefault', 'logging', 'log_timestamp', '1970-01-01 00:00:00+00' ], |
| 216 |
[ 'changeField', 'logging', 'log_actor', 'BIGINT', '' ], |
| 217 |
[ 'changeField', 'logging', 'log_comment_id', 'BIGINT', '' ], |
| 218 |
[ 'changeField', 'logging', 'log_namespace', 'INT', 'log_namespace::INT DEFAULT 0' ], |
| 219 |
[ 'dropPgIndex', 'logging', 'logging_actor_time' ], |
| 220 |
[ 'changeField', 'uploadstash', 'us_key', 'VARCHAR(255)', '' ], |
| 221 |
[ 'changeField', 'uploadstash', 'us_orig_path', 'VARCHAR(255)', '' ], |
| 222 |
[ 'changeField', 'uploadstash', 'us_path', 'VARCHAR(255)', '' ], |
| 223 |
[ 'changeField', 'uploadstash', 'us_source_type', 'VARCHAR(50)', '' ], |
| 224 |
[ 'changeField', 'uploadstash', 'us_props', 'TEXT', '' ], |
| 225 |
[ 'changeField', 'uploadstash', 'us_status', 'VARCHAR(50)', '' ], |
| 226 |
[ 'changeField', 'uploadstash', 'us_sha1', 'VARCHAR(31)', '' ], |
| 227 |
[ 'changeField', 'uploadstash', 'us_mime', 'VARCHAR(255)', '' ], |
| 228 |
[ 'changeNullableField', 'uploadstash', 'us_key', 'NOT NULL', true ], |
| 229 |
[ 'changeNullableField', 'uploadstash', 'us_user', 'NOT NULL', true ], |
| 230 |
[ 'changeNullableField', 'uploadstash', 'us_orig_path', 'NOT NULL', true ], |
| 231 |
[ 'changeNullableField', 'uploadstash', 'us_path', 'NOT NULL', true ], |
| 232 |
[ 'changeNullableField', 'uploadstash', 'us_timestamp', 'NOT NULL', true ], |
| 233 |
[ 'changeNullableField', 'uploadstash', 'us_status', 'NOT NULL', true ], |
| 234 |
[ 'changeNullableField', 'uploadstash', 'us_size', 'NOT NULL', true ], |
| 235 |
[ 'changeNullableField', 'uploadstash', 'us_sha1', 'NOT NULL', true ], |
| 236 |
[ 'renameIndex', 'uploadstash', 'us_user_idx', 'us_user' ], |
| 237 |
[ 'renameIndex', 'uploadstash', 'us_key_idx', 'us_key' ], |
| 238 |
[ 'renameIndex', 'uploadstash', 'us_timestamp_idx', 'us_timestamp' ], |
| 239 |
[ 'renameIndex', 'user_properties', 'user_properties_property', 'up_property' ], |
| 240 |
[ 'renameIndex', 'sites', 'sites_global_key', 'site_global_key' ], |
| 241 |
[ 'renameIndex', 'sites', 'sites_type', 'site_type' ], |
| 242 |
[ 'renameIndex', 'sites', 'sites_group', 'site_group' ], |
| 243 |
[ 'renameIndex', 'sites', 'sites_source', 'site_source' ], |
| 244 |
[ 'renameIndex', 'sites', 'sites_language', 'site_language' ], |
| 245 |
[ 'renameIndex', 'sites', 'sites_protocol', 'site_protocol' ], |
| 246 |
[ 'renameIndex', 'sites', 'sites_domain', 'site_domain' ], |
| 247 |
[ 'renameIndex', 'sites', 'sites_forward', 'site_forward' ], |
| 248 |
[ 'renameIndex', 'logging', 'type_name', 'log_type_time' ], |
| 249 |
[ 'renameIndex', 'logging', 'actor_time', 'log_actor_time' ], |
| 250 |
[ 'renameIndex', 'logging', 'page_time', 'log_page_time' ], |
| 251 |
[ 'renameIndex', 'logging', 'times', 'log_times' ], |
| 252 |
[ 'setDefault', 'filearchive', 'fa_name', '' ], |
| 253 |
[ 'setDefault', 'filearchive', 'fa_archive_name', '' ], |
| 254 |
[ 'setDefault', 'filearchive', 'fa_storage_key', '' ], |
| 255 |
[ 'dropFkey', 'filearchive', 'fa_deleted_user' ], |
| 256 |
[ 'changeField', 'filearchive', 'fa_deleted_reason_id', 'BIGINT', '' ], |
| 257 |
[ 'changeField', 'filearchive', 'fa_metadata', 'TEXT', '' ], |
| 258 |
[ 'changeField', 'filearchive', 'fa_bits', 'INTEGER', '' ], |
| 259 |
[ 'changeField', 'filearchive', 'fa_description_id', 'BIGINT', '' ], |
| 260 |
[ 'changeField', 'filearchive', 'fa_actor', 'BIGINT', '' ], |
| 261 |
[ 'renameIndex', 'filearchive', 'fa_name_time', 'fa_name' ], |
| 262 |
[ 'renameIndex', 'filearchive', 'fa_dupe', 'fa_storage_group' ], |
| 263 |
[ 'renameIndex', 'filearchive', 'fa_notime', 'fa_deleted_timestamp' ], |
| 264 |
[ 'dropPgIndex', 'filearchive', 'fa_nouser' ], |
| 265 |
[ 'addPgIndex', 'filearchive', 'fa_actor_timestamp', '(fa_actor, fa_timestamp)' ], |
| 266 |
[ 'addPgIndex', 'ipblocks', 'ipb_expiry', '(ipb_expiry)' ], |
| 267 |
[ 'addPgIndex', 'ipblocks', 'ipb_timestamp', '(ipb_timestamp)' ], |
| 268 |
[ 'renameIndex', 'text', 'pagecontent_pkey', 'text_pkey' ], |
| 269 |
[ 'changeNullableField', 'text', 'old_text', 'NOT NULL', true ], |
| 270 |
[ 'changeNullableField', 'text', 'old_flags', 'NOT NULL', true ], |
| 271 |
[ 'setDefault', 'oldimage', 'oi_name', '' ], |
| 272 |
[ 'setDefault', 'oldimage', 'oi_archive_name', '' ], |
| 273 |
[ 'setDefault', 'oldimage', 'oi_size', 0 ], |
| 274 |
[ 'setDefault', 'oldimage', 'oi_width', 0 ], |
| 275 |
[ 'setDefault', 'oldimage', 'oi_height', 0 ], |
| 276 |
[ 'setDefault', 'oldimage', 'oi_bits', 0 ], |
| 277 |
[ 'setDefault', 'oldimage', 'oi_name', '' ], |
| 278 |
[ 'changeField', 'oldimage', 'oi_bits', 'INTEGER', '' ], |
| 279 |
[ 'changeField', 'oldimage', 'oi_description_id', 'BIGINT', '' ], |
| 280 |
[ 'changeField', 'oldimage', 'oi_actor', 'BIGINT', '' ], |
| 281 |
[ 'changeField', 'oldimage', 'oi_metadata', 'TEXT', '' ], |
| 282 |
[ 'dropDefault', 'oldimage', 'oi_metadata' ], |
| 283 |
[ 'changeNullableField', 'oldimage', 'oi_minor_mime', 'NOT NULL', true ], |
| 284 |
[ 'changeNullableField', 'oldimage', 'oi_minor_mime', 'NOT NULL', true ], |
| 285 |
[ 'dropFkey', 'oldimage', 'oi_name' ], |
| 286 |
[ 'addPgIndex', 'oldimage', 'oi_actor_timestamp', '(oi_actor, oi_timestamp)' ], |
| 287 |
[ 'dropPgIndex', 'recentchanges', 'rc_timestamp_bot' ], |
| 288 |
[ 'addPgIndex', 'recentchanges', 'rc_ns_actor', '(rc_namespace, rc_actor)' ], |
| 289 |
[ 'addPgIndex', 'recentchanges', 'rc_actor', '(rc_actor, rc_timestamp)' ], |
| 290 |
[ 'dropIndex', 'objectcache', 'keyname', 'patch-objectcache_keyname-pk.sql' ], |
| 291 |
[ 'changeField', 'objectcache', 'value', 'TEXT', '' ], |
| 292 |
[ 'changeNullableField', 'objectcache', 'value', 'NULL', true ], |
| 293 |
[ 'dropFkey', 'ipblocks', 'ipb_user' ], |
| 294 |
[ 'dropFkey', 'ipblocks', 'ipb_parent_block_id' ], |
| 295 |
[ 'setDefault', 'ipblocks', 'ipb_user', 0 ], |
| 296 |
[ 'changeNullableField', 'ipblocks', 'ipb_user', 'NOT NULL', true ], |
| 297 |
[ 'changeNullableField', 'ipblocks', 'ipb_range_start', 'NOT NULL', true ], |
| 298 |
[ 'changeNullableField', 'ipblocks', 'ipb_range_end', 'NOT NULL', true ], |
| 299 |
[ 'changeField', 'ipblocks', 'ipb_by_actor', 'BIGINT', '' ], |
| 300 |
[ 'changeField', 'ipblocks', 'ipb_reason_id', 'BIGINT', '' ], |
| 301 |
[ 'renameIndex', 'archive', 'archive_name_title_timestamp', 'ar_name_title_timestamp' ], |
| 302 |
[ 'dropPgIndex', 'archive', 'archive_actor' ], |
| 303 |
[ 'addPgIndex', 'archive', 'ar_actor_timestamp', '(ar_actor,ar_timestamp)' ], |
| 304 |
[ 'setDefault', 'image', 'img_name', '' ], |
| 305 |
[ 'setDefault', 'image', 'img_size', 0 ], |
| 306 |
[ 'setDefault', 'image', 'img_width', 0 ], |
| 307 |
[ 'setDefault', 'image', 'img_height', 0 ], |
| 308 |
[ 'setDefault', 'image', 'img_bits', 0 ], |
| 309 |
[ 'changeField', 'image', 'img_bits', 'INTEGER', '' ], |
| 310 |
[ 'changeField', 'image', 'img_description_id', 'BIGINT', '' ], |
| 311 |
[ 'changeField', 'image', 'img_actor', 'BIGINT', '' ], |
| 312 |
[ 'changeField', 'image', 'img_metadata', 'TEXT', '' ], |
| 313 |
[ 'dropDefault', 'image', 'img_metadata' ], |
| 314 |
[ 'changeNullableField', 'image', 'img_major_mime', 'NOT NULL', true ], |
| 315 |
[ 'changeNullableField', 'image', 'img_minor_mime', 'NOT NULL', true ], |
| 316 |
[ 'changeNullableField', 'image', 'img_timestamp', 'NOT NULL', true ], |
| 317 |
[ 'renameIndex', 'image', 'img_size_idx', 'img_size' ], |
| 318 |
[ 'renameIndex', 'image', 'img_timestamp_idx', 'img_timestamp' ], |
| 319 |
[ 'addPgIndex', 'image', 'img_actor_timestamp', '(img_actor, img_timestamp)' ], |
| 320 |
[ 'addPgIndex', 'image', 'img_media_mime', '(img_media_type, img_major_mime, img_minor_mime)' ], |
| 321 |
[ 'renameIndex', 'site_identifiers', 'site_ids_site', 'si_site' ], |
| 322 |
[ 'renameIndex', 'site_identifiers', 'site_ids_key', 'si_key' ], |
| 323 |
[ 'changeField', 'recentchanges', 'rc_actor', 'BIGINT', '' ], |
| 324 |
[ 'changeField', 'recentchanges', 'rc_comment_id', 'BIGINT', '' ], |
| 325 |
[ 'changeField', 'recentchanges', 'rc_ip', 'TEXT', '' ], |
| 326 |
[ 'changeField', 'recentchanges', 'rc_namespace', 'INTEGER', '' ], |
| 327 |
[ 'setDefault', 'recentchanges', 'rc_title', '' ], |
| 328 |
[ 'setDefault', 'recentchanges', 'rc_source', '' ], |
| 329 |
[ 'setDefault', 'recentchanges', 'rc_ip', '' ], |
| 330 |
[ 'setDefault', 'recentchanges', 'rc_namespace', 0 ], |
| 331 |
[ 'setDefault', 'recentchanges', 'rc_cur_id', 0 ], |
| 332 |
[ 'setDefault', 'recentchanges', 'rc_this_oldid', 0 ], |
| 333 |
[ 'setDefault', 'recentchanges', 'rc_last_oldid', 0 ], |
| 334 |
[ 'changeNullableField', 'recentchanges', 'rc_cur_id', 'NOT NULL', true ], |
| 335 |
[ 'changeNullableField', 'recentchanges', 'rc_ip', 'NOT NULL', true ], |
| 336 |
[ 'renameIndex', 'recentchanges', 'new_name_timestamp', 'rc_new_name_timestamp', false, |
| 337 |
'patch-recentchanges-rc_new_name_timestamp.sql' ], |
| 338 |
[ 'changeField', 'archive', 'ar_namespace', 'INTEGER', '' ], |
| 339 |
[ 'setDefault', 'archive', 'ar_namespace', 0 ], |
| 340 |
[ 'setDefault', 'archive', 'ar_title', '' ], |
| 341 |
[ 'changeField', 'archive', 'ar_comment_id', 'BIGINT', '' ], |
| 342 |
[ 'changeField', 'archive', 'ar_actor', 'BIGINT', '' ], |
| 343 |
[ 'renameIndex', 'user', 'user_email_token_idx', 'user_email_token' ], |
| 344 |
[ 'addPgIndex', 'user', 'user_email', '(user_email)' ], |
| 345 |
[ 'addPgIndex', 'user', 'user_name', '(user_name)', true ], |
| 346 |
[ 'changeField', 'page', 'page_namespace', 'INTEGER', '' ], |
| 347 |
[ 'changeNullableField', 'page', 'page_touched', 'NOT NULL', true ], |
| 348 |
[ 'changeField', 'page', 'page_random', 'FLOAT', '' ], |
| 349 |
[ 'renameIndex', 'revision', 'revision_unique', 'rev_page_id' ], |
| 350 |
[ 'renameIndex', 'revision', 'rev_timestamp_idx', 'rev_timestamp' ], |
| 351 |
[ 'addPgIndex', 'revision', 'rev_page_timestamp', '(rev_page,rev_timestamp)' ], |
| 352 |
[ 'changeNullableField', 'user', 'user_touched', 'NOT NULL', true ], |
| 353 |
|
| 354 |
|
| 355 |
[ 'setDefault', 'user', 'user_name', '' ], |
| 356 |
[ 'setDefault', 'user', 'user_token', '' ], |
| 357 |
[ 'setDefault', 'user', 'user_real_name', '' ], |
| 358 |
[ 'setDefault', 'user', 'user_email', '' ], |
| 359 |
[ 'setDefault', 'user', 'user_newpassword', '' ], |
| 360 |
[ 'setDefault', 'user', 'user_password', '' ], |
| 361 |
[ 'changeNullableField', 'user', 'user_token', 'NOT NULL', true ], |
| 362 |
[ 'changeNullableField', 'user', 'user_real_name', 'NOT NULL', true ], |
| 363 |
[ 'changeNullableField', 'user', 'user_email', 'NOT NULL', true ], |
| 364 |
[ 'changeNullableField', 'user', 'user_newpassword', 'NOT NULL', true ], |
| 365 |
[ 'changeNullableField', 'user', 'user_password', 'NOT NULL', true ], |
| 366 |
[ 'dropDefault', 'user', 'user_email' ], |
| 367 |
[ 'dropDefault', 'user', 'user_newpassword' ], |
| 368 |
[ 'dropDefault', 'user', 'user_password' ], |
| 369 |
[ 'dropConstraint', 'user', 'user_name', 'unique' ], |
| 370 |
[ 'addField', 'objectcache', 'modtoken', 'patch-objectcache-modtoken.sql' ], |
| 371 |
[ 'dropFkey', 'revision', 'rev_page' ], |
| 372 |
[ 'changeNullableField', 'revision', 'rev_page', 'NOT NULL', true ], |
| 373 |
[ 'changeField', 'revision', 'rev_comment_id', 'BIGINT', 'rev_comment_id::BIGINT DEFAULT 0' ], |
| 374 |
[ 'changeField', 'revision', 'rev_actor', 'BIGINT', 'rev_actor::BIGINT DEFAULT 0' ], |
| 375 |
[ 'checkIndex', 'rev_page_id', [ |
| 376 |
[ 'rev_page', 'int4_ops', 'btree', 1 ], |
| 377 |
[ 'rev_id', 'int4_ops', 'btree', 1 ], |
| 378 |
], |
| 379 |
'CREATE INDEX rev_page_id ON revision (rev_page,rev_id)' |
| 380 |
], |
| 381 |
[ 'addTable', 'searchindex', 'patch-searchindex-table.sql' ], |
| 382 |
[ 'addPgIndex', 'oldimage', 'oi_timestamp', '(oi_timestamp)' ], |
| 383 |
[ 'renameIndex', 'page', 'name_title', 'page_name_title' ], |
| 384 |
[ 'renameIndex', 'change_tag', 'change_tag_rc_tag_id', 'ct_rc_tag_id' ], |
| 385 |
[ 'renameIndex', 'change_tag', 'change_tag_log_tag_id', 'ct_log_tag_id' ], |
| 386 |
[ 'renameIndex', 'change_tag', 'change_tag_rev_tag_id', 'ct_rev_tag_id' ], |
| 387 |
[ 'renameIndex', 'change_tag', 'change_tag_tag_id_id', 'ct_tag_id_id' ], |
| 388 |
|
| 389 |
|
| 390 |
[ 'doConvertDjvuMetadata' ], |
| 391 |
[ 'dropPgField', 'page_restrictions', 'pr_user' ], |
| 392 |
[ 'addTable', 'linktarget', 'patch-linktarget.sql' ], |
| 393 |
[ 'dropIndex', 'revision', 'rev_page_id', 'patch-drop-rev_page_id.sql' ], |
| 394 |
[ 'addField', 'templatelinks', 'tl_target_id', 'patch-templatelinks-target_id.sql' ], |
| 395 |
|
| 396 |
|
| 397 |
[ 'addTable', 'user_autocreate_serial', 'patch-user_autocreate_serial.sql' ], |
| 398 |
[ 'runMaintenance', MigrateRevisionActorTemp::class ], |
| 399 |
[ 'dropTable', 'revision_actor_temp' ], |
| 400 |
[ 'runMaintenance', UpdateRestrictions::class ], |
| 401 |
[ 'dropPgField', 'page', 'page_restrictions' ], |
| 402 |
[ 'migrateTemplatelinks' ], |
| 403 |
[ 'changeNullableField', 'templatelinks', 'tl_target_id', 'NOT NULL', true ], |
| 404 |
[ 'changePrimaryKey', 'templatelinks', [ 'tl_from', 'tl_target_id' ] ], |
| 405 |
[ 'dropField', 'templatelinks', 'tl_title', 'patch-templatelinks-drop-tl_title.sql' ], |
| 406 |
|
| 407 |
|
| 408 |
[ 'addField', 'externallinks', 'el_to_path', 'patch-externallinks-el_to_path.sql' ], |
| 409 |
|
| 410 |
|
| 411 |
[ 'addField', 'user', 'user_is_temp', 'patch-user-user_is_temp.sql' ], |
| 412 |
[ 'runMaintenance', MigrateRevisionCommentTemp::class ], |
| 413 |
[ 'dropTable', 'revision_comment_temp' ], |
| 414 |
[ 'runMaintenance', MigrateExternallinks::class ], |
| 415 |
[ 'modifyField', 'externallinks', 'el_to', 'patch-externallinks-el_to_default.sql' ], |
| 416 |
[ 'addField', 'pagelinks', 'pl_target_id', 'patch-pagelinks-target_id.sql' ], |
| 417 |
[ 'dropField', 'externallinks', 'el_to', 'patch-externallinks-drop-el_to.sql' ], |
| 418 |
[ 'runMaintenance', FixInconsistentRedirects::class ], |
| 419 |
[ 'modifyField', 'image', 'img_size', 'patch-image-img_size_to_bigint.sql' ], |
| 420 |
[ 'modifyField', 'filearchive', 'fa_size', 'patch-filearchive-fa_size_to_bigint.sql' ], |
| 421 |
[ 'modifyField', 'oldimage', 'oi_size', 'patch-oldimage-oi_size_to_bigint.sql' ], |
| 422 |
[ 'modifyField', 'uploadstash', 'us_size', 'patch-uploadstash-us_size_to_bigint.sql' ], |
| 423 |
|
| 424 |
|
| 425 |
[ 'addField', 'user_autocreate_serial', 'uas_year', 'patch-user_autocreate_serial-uas_year.sql' ], |
| 426 |
[ 'addTable', 'block_target', 'patch-block_target.sql' ], |
| 427 |
[ 'dropIndex', 'categorylinks', 'cl_collation_ext', 'patch-drop-cl_collation_ext.sql' ], |
| 428 |
[ 'runMaintenance', PopulateUserIsTemp::class ], |
| 429 |
[ 'dropIndex', 'sites', 'site_type', 'patch-sites-drop_indexes.sql' ], |
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
[ 'dropIndex', 'sites', 'site_group', 'patch-sites-drop_site_group_index.sql' ], |
| 439 |
[ 'dropIndex', 'sites', 'site_source', 'patch-sites-drop_site_source_index.sql' ], |
| 440 |
[ 'dropIndex', 'sites', 'site_language', 'patch-sites-drop_site_language_index.sql' ], |
| 441 |
[ 'dropIndex', 'sites', 'site_protocol', 'patch-sites-drop_site_protocol_index.sql' ], |
| 442 |
[ 'dropIndex', 'sites', 'site_domain', 'patch-sites-drop_site_domain_index.sql' ], |
| 443 |
[ 'dropIndex', 'sites', 'site_forward', 'patch-sites-drop_site_forward_index.sql' ], |
| 444 |
[ 'dropIndex', 'iwlinks', 'iwl_prefix_from_title', 'patch-iwlinks-drop-iwl_prefix_from_title.sql' ], |
| 445 |
|
| 446 |
|
| 447 |
[ 'migratePagelinks' ], |
| 448 |
[ 'dropDefault', 'revision', 'rev_actor' ], |
| 449 |
[ 'dropDefault', 'revision', 'rev_comment_id' ], |
| 450 |
[ 'changeField', 'revision', 'rev_id', 'BIGINT', '' ], |
| 451 |
[ 'changeField', 'revision', 'rev_parent_id', 'BIGINT', '' ], |
| 452 |
[ 'changeField', 'recentchanges', 'rc_id', 'BIGINT', '' ], |
| 453 |
[ 'changeField', 'change_tag', 'ct_rc_id', 'BIGINT', '' ], |
| 454 |
[ 'runMaintenance', \MigrateBlocks::class ], |
| 455 |
[ 'dropTable', 'ipblocks' ], |
| 456 |
[ 'dropField', 'pagelinks', 'pl_title', 'patch-pagelinks-drop-pl_title.sql' ], |
| 457 |
[ 'addPostDatabaseUpdateMaintenance', FixAutoblockLogTitles::class ], |
| 458 |
[ 'migrateSearchindex' ], |
| 459 |
]; |
| 460 |
} |
| 461 |
|
| 462 |
protected function getInitialUpdateKeys() { |
| 463 |
return [ |
| 464 |
'filearchive-fa_major_mime-patch-fa_major_mime-chemical.sql', |
| 465 |
'image-img_major_mime-patch-img_major_mime-chemical.sql', |
| 466 |
'oldimage-oi_major_mime-patch-oi_major_mime-chemical.sql', |
| 467 |
'user_groups-ug_group-patch-ug_group-length-increase-255.sql', |
| 468 |
'user_former_groups-ufg_group-patch-ufg_group-length-increase-255.sql', |
| 469 |
'user_properties-up_property-patch-up_property.sql', |
| 470 |
]; |
| 471 |
} |
| 472 |
|
| 473 |
protected function describeTable( $table ) { |
| 474 |
$q = <<<END |
| 475 |
SELECT attname, attnum FROM pg_namespace, pg_class, pg_attribute |
| 476 |
WHERE pg_class.relnamespace = pg_namespace.oid |
| 477 |
AND attrelid=pg_class.oid AND attnum > 0 |
| 478 |
AND relname=%s AND nspname=%s |
| 479 |
END; |
| 480 |
$res = $this->db->query( |
| 481 |
sprintf( $q, |
| 482 |
$this->db->addQuotes( $table ), |
| 483 |
$this->db->addQuotes( $this->db->getCoreSchema() ) |
| 484 |
), |
| 485 |
__METHOD__ |
| 486 |
); |
| 487 |
if ( !$res ) { |
| 488 |
return null; |
| 489 |
} |
| 490 |
|
| 491 |
$cols = []; |
| 492 |
foreach ( $res as $r ) { |
| 493 |
$cols[] = [ |
| 494 |
"name" => $r[0], |
| 495 |
"ord" => $r[1], |
| 496 |
]; |
| 497 |
} |
| 498 |
|
| 499 |
return $cols; |
| 500 |
} |
| 501 |
|
| 502 |
protected function describeIndex( $idx ) { |
| 503 |
|
| 504 |
|
| 505 |
$q = <<<END |
| 506 |
SELECT indkey, indrelid FROM pg_namespace, pg_class, pg_index |
| 507 |
WHERE nspname=%s |
| 508 |
AND pg_class.relnamespace = pg_namespace.oid |
| 509 |
AND relname=%s |
| 510 |
AND indexrelid=pg_class.oid |
| 511 |
END; |
| 512 |
$res = $this->db->query( |
| 513 |
sprintf( |
| 514 |
$q, |
| 515 |
$this->db->addQuotes( $this->db->getCoreSchema() ), |
| 516 |
$this->db->addQuotes( $idx ) |
| 517 |
), |
| 518 |
__METHOD__ |
| 519 |
); |
| 520 |
if ( !$res ) { |
| 521 |
return null; |
| 522 |
} |
| 523 |
$r = $res->fetchRow(); |
| 524 |
if ( !$r ) { |
| 525 |
return null; |
| 526 |
} |
| 527 |
|
| 528 |
$indkey = $r[0]; |
| 529 |
$relid = intval( $r[1] ); |
| 530 |
$indkeys = explode( ' ', $indkey ); |
| 531 |
|
| 532 |
$colnames = []; |
| 533 |
foreach ( $indkeys as $rid ) { |
| 534 |
$query = <<<END |
| 535 |
SELECT attname FROM pg_class, pg_attribute |
| 536 |
WHERE attrelid=$relid |
| 537 |
AND attnum=%d |
| 538 |
AND attrelid=pg_class.oid |
| 539 |
END; |
| 540 |
$r2 = $this->db->query( sprintf( $query, $rid ), __METHOD__ ); |
| 541 |
if ( !$r2 ) { |
| 542 |
return null; |
| 543 |
} |
| 544 |
$row2 = $r2->fetchRow(); |
| 545 |
if ( !$row2 ) { |
| 546 |
return null; |
| 547 |
} |
| 548 |
$colnames[] = $row2[0]; |
| 549 |
} |
| 550 |
|
| 551 |
return $colnames; |
| 552 |
} |
| 553 |
|
| 554 |
protected function fkeyDeltype( $fkey ) { |
| 555 |
$q = <<<END |
| 556 |
SELECT confdeltype FROM pg_constraint, pg_namespace |
| 557 |
WHERE connamespace=pg_namespace.oid |
| 558 |
AND nspname=%s |
| 559 |
AND conname=%s; |
| 560 |
END; |
| 561 |
$r = $this->db->query( |
| 562 |
sprintf( |
| 563 |
$q, |
| 564 |
$this->db->addQuotes( $this->db->getCoreSchema() ), |
| 565 |
$this->db->addQuotes( $fkey ) |
| 566 |
), |
| 567 |
__METHOD__ |
| 568 |
); |
| 569 |
$row = $r->fetchRow(); |
| 570 |
return $row ? $row[0] : null; |
| 571 |
} |
| 572 |
|
| 573 |
protected function ruleDef( $table, $rule ) { |
| 574 |
$q = <<<END |
| 575 |
SELECT definition FROM pg_rules |
| 576 |
WHERE schemaname = %s |
| 577 |
AND tablename = %s |
| 578 |
AND rulename = %s |
| 579 |
END; |
| 580 |
$r = $this->db->query( |
| 581 |
sprintf( |
| 582 |
$q, |
| 583 |
$this->db->addQuotes( $this->db->getCoreSchema() ), |
| 584 |
$this->db->addQuotes( $table ), |
| 585 |
$this->db->addQuotes( $rule ) |
| 586 |
), |
| 587 |
__METHOD__ |
| 588 |
); |
| 589 |
$row = $r->fetchRow(); |
| 590 |
if ( !$row ) { |
| 591 |
return null; |
| 592 |
} |
| 593 |
$d = $row[0]; |
| 594 |
|
| 595 |
return $d; |
| 596 |
} |
| 597 |
|
| 598 |
protected function addSequence( $table, $pkey, $ns ) { |
| 599 |
if ( !$this->db->sequenceExists( $ns ) ) { |
| 600 |
$this->output( "Creating sequence $ns\n" ); |
| 601 |
if ( $pkey !== false ) { |
| 602 |
$table = $this->db->addIdentifierQuotes( $table ); |
| 603 |
$this->db->query( "CREATE SEQUENCE $ns OWNED BY $table.$pkey", __METHOD__ ); |
| 604 |
$this->setDefault( $table, $pkey, '"nextval"(\'"' . $ns . '"\'::"regclass")' ); |
| 605 |
} else { |
| 606 |
$this->db->query( "CREATE SEQUENCE $ns", __METHOD__ ); |
| 607 |
} |
| 608 |
} |
| 609 |
} |
| 610 |
|
| 611 |
protected function dropSequence( $table, $ns ) { |
| 612 |
if ( $this->db->sequenceExists( $ns ) ) { |
| 613 |
$this->output( "Dropping sequence $ns\n" ); |
| 614 |
$this->db->query( "DROP SEQUENCE $ns CASCADE", __METHOD__ ); |
| 615 |
} |
| 616 |
} |
| 617 |
|
| 618 |
protected function renameSequence( $old, $new ) { |
| 619 |
if ( $this->db->sequenceExists( $new ) ) { |
| 620 |
$this->output( "...sequence $new already exists.\n" ); |
| 621 |
|
| 622 |
return; |
| 623 |
} |
| 624 |
if ( $this->db->sequenceExists( $old ) ) { |
| 625 |
$this->output( "Renaming sequence $old to $new\n" ); |
| 626 |
$this->db->query( "ALTER SEQUENCE $old RENAME TO $new", __METHOD__ ); |
| 627 |
} |
| 628 |
} |
| 629 |
|
| 630 |
protected function setSequenceOwner( $table, $pkey, $seq ) { |
| 631 |
if ( $this->db->sequenceExists( $seq ) ) { |
| 632 |
$this->output( "Setting sequence $seq owner to $table.$pkey\n" ); |
| 633 |
$table = $this->db->addIdentifierQuotes( $table ); |
| 634 |
$this->db->query( "ALTER SEQUENCE $seq OWNED BY $table.$pkey", __METHOD__ ); |
| 635 |
} |
| 636 |
} |
| 637 |
|
| 638 |
protected function renameTable( $old, $new, $patch = false ) { |
| 639 |
if ( $this->db->tableExists( $old, __METHOD__ ) ) { |
| 640 |
$this->output( "Renaming table $old to $new\n" ); |
| 641 |
$old = $this->db->addIdentifierQuotes( $old ); |
| 642 |
$new = $this->db->addIdentifierQuotes( $new ); |
| 643 |
$this->db->query( "ALTER TABLE $old RENAME TO $new", __METHOD__ ); |
| 644 |
if ( $patch !== false ) { |
| 645 |
$this->applyPatch( $patch ); |
| 646 |
} |
| 647 |
} |
| 648 |
} |
| 649 |
|
| 650 |
protected function renameIndex( |
| 651 |
$table, $old, $new, $skipBothIndexExistWarning = false, $a = false, $b = false |
| 652 |
) { |
| 653 |
|
| 654 |
if ( !$this->db->tableExists( $table, __METHOD__ ) ) { |
| 655 |
$this->output( "...skipping: '$table' table doesn't exist yet.\n" ); |
| 656 |
|
| 657 |
return true; |
| 658 |
} |
| 659 |
|
| 660 |
|
| 661 |
if ( $this->db->indexExists( $table, $new, __METHOD__ ) ) { |
| 662 |
$this->output( "...index $new already set on $table table.\n" ); |
| 663 |
if ( !$skipBothIndexExistWarning |
| 664 |
&& $this->db->indexExists( $table, $old, __METHOD__ ) |
| 665 |
) { |
| 666 |
$this->output( "...WARNING: $old still exists, despite it has been " . |
| 667 |
"renamed into $new (which also exists).\n" . |
| 668 |
" $old should be manually removed if not needed anymore.\n" ); |
| 669 |
} |
| 670 |
|
| 671 |
return true; |
| 672 |
} |
| 673 |
|
| 674 |
|
| 675 |
if ( !$this->db->indexExists( $table, $old, __METHOD__ ) ) { |
| 676 |
$this->output( "...skipping: index $old doesn't exist.\n" ); |
| 677 |
|
| 678 |
return true; |
| 679 |
} |
| 680 |
|
| 681 |
$this->db->query( "ALTER INDEX $old RENAME TO $new", __METHOD__ ); |
| 682 |
return true; |
| 683 |
} |
| 684 |
|
| 685 |
protected function dropPgField( $table, $field ) { |
| 686 |
$fi = $this->db->fieldInfo( $table, $field ); |
| 687 |
if ( $fi === null ) { |
| 688 |
$this->output( "...$table table does not contain $field field.\n" ); |
| 689 |
} else { |
| 690 |
$this->output( "Dropping column '$table.$field'\n" ); |
| 691 |
$table = $this->db->addIdentifierQuotes( $table ); |
| 692 |
$this->db->query( "ALTER TABLE $table DROP COLUMN $field", __METHOD__ ); |
| 693 |
} |
| 694 |
} |
| 695 |
|
| 696 |
protected function addPgField( $table, $field, $type ) { |
| 697 |
$fi = $this->db->fieldInfo( $table, $field ); |
| 698 |
if ( $fi !== null ) { |
| 699 |
$this->output( "...column '$table.$field' already exists\n" ); |
| 700 |
} else { |
| 701 |
$this->output( "Adding column '$table.$field'\n" ); |
| 702 |
$table = $this->db->addIdentifierQuotes( $table ); |
| 703 |
$this->db->query( "ALTER TABLE $table ADD $field $type", __METHOD__ ); |
| 704 |
} |
| 705 |
} |
| 706 |
|
| 707 |
protected function changeField( $table, $field, $newtype, $default ) { |
| 708 |
if ( !$this->db->tableExists( $table, __METHOD__ ) ) { |
| 709 |
$this->output( "...$table table does not exist, skipping default change.\n" ); |
| 710 |
return; |
| 711 |
} |
| 712 |
$fi = $this->db->fieldInfo( $table, $field ); |
| 713 |
if ( $fi === null ) { |
| 714 |
$this->output( "...ERROR: expected column $table.$field to exist\n" ); |
| 715 |
exit( 1 ); |
| 716 |
} |
| 717 |
|
| 718 |
if ( $fi->type() === strtolower( $newtype ) ) { |
| 719 |
$this->output( "...column '$table.$field' is already of type '$newtype'\n" ); |
| 720 |
} else { |
| 721 |
$this->output( "Changing column type of '$table.$field' from '{$fi->type()}' to '$newtype'\n" ); |
| 722 |
$table = $this->db->addIdentifierQuotes( $table ); |
| 723 |
$sql = "ALTER TABLE $table ALTER $field TYPE $newtype"; |
| 724 |
if ( strlen( $default ) ) { |
| 725 |
$res = []; |
| 726 |
if ( preg_match( '/DEFAULT (.+)/', $default, $res ) ) { |
| 727 |
$sqldef = "ALTER TABLE $table ALTER $field SET DEFAULT $res[1]"; |
| 728 |
$this->db->query( $sqldef, __METHOD__ ); |
| 729 |
$default = preg_replace( '/\s*DEFAULT .+/', '', $default ); |
| 730 |
} |
| 731 |
$sql .= " USING $default"; |
| 732 |
} |
| 733 |
$this->db->query( $sql, __METHOD__ ); |
| 734 |
} |
| 735 |
} |
| 736 |
|
| 737 |
protected function changeFieldPurgeTable( $table, $field, $newtype, $default ) { |
| 738 |
|
| 739 |
|
| 740 |
$fi = $this->db->fieldInfo( $table, $field ); |
| 741 |
if ( $fi === null ) { |
| 742 |
$this->output( "...ERROR: expected column $table.$field to exist\n" ); |
| 743 |
exit( 1 ); |
| 744 |
} |
| 745 |
|
| 746 |
if ( $fi->type() === $newtype ) { |
| 747 |
$this->output( "...column '$table.$field' is already of type '$newtype'\n" ); |
| 748 |
} else { |
| 749 |
$this->output( "Purging data from cache table '$table'\n" ); |
| 750 |
$table = $this->db->addIdentifierQuotes( $table ); |
| 751 |
$this->db->query( "DELETE from $table", __METHOD__ ); |
| 752 |
$this->output( "Changing column type of '$table.$field' from '{$fi->type()}' to '$newtype'\n" ); |
| 753 |
$sql = "ALTER TABLE $table ALTER $field TYPE $newtype"; |
| 754 |
if ( strlen( $default ) ) { |
| 755 |
$res = []; |
| 756 |
if ( preg_match( '/DEFAULT (.+)/', $default, $res ) ) { |
| 757 |
$sqldef = "ALTER TABLE $table ALTER $field SET DEFAULT $res[1]"; |
| 758 |
$this->db->query( $sqldef, __METHOD__ ); |
| 759 |
$default = preg_replace( '/\s*DEFAULT .+/', '', $default ); |
| 760 |
} |
| 761 |
$sql .= " USING $default"; |
| 762 |
} |
| 763 |
$this->db->query( $sql, __METHOD__ ); |
| 764 |
} |
| 765 |
} |
| 766 |
|
| 767 |
protected function setDefault( $table, $field, $default ) { |
| 768 |
if ( !$this->db->tableExists( $table, __METHOD__ ) ) { |
| 769 |
$this->output( "...$table table does not exist, skipping default change.\n" ); |
| 770 |
return; |
| 771 |
} |
| 772 |
$info = $this->db->fieldInfo( $table, $field ); |
| 773 |
if ( $info && $info->defaultValue() !== $default ) { |
| 774 |
$this->output( "Changing '$table.$field' default value\n" ); |
| 775 |
$table = $this->db->addIdentifierQuotes( $table ); |
| 776 |
$this->db->query( "ALTER TABLE $table ALTER $field SET DEFAULT " |
| 777 |
. $this->db->addQuotes( $default ), __METHOD__ ); |
| 778 |
} |
| 779 |
} |
| 780 |
|
| 781 |
|
| 782 |
|
| 783 |
|
| 784 |
|
| 785 |
|
| 786 |
|
| 787 |
protected function dropDefault( $table, $field ) { |
| 788 |
$info = $this->db->fieldInfo( $table, $field ); |
| 789 |
if ( $info && $info->defaultValue() !== false ) { |
| 790 |
$this->output( "Removing '$table.$field' default value\n" ); |
| 791 |
$table = $this->db->addIdentifierQuotes( $table ); |
| 792 |
$this->db->query( "ALTER TABLE $table ALTER $field DROP DEFAULT", __METHOD__ ); |
| 793 |
} |
| 794 |
} |
| 795 |
|
| 796 |
protected function changeNullableField( $table, $field, $null, $update = false ) { |
| 797 |
$fi = $this->db->fieldInfo( $table, $field ); |
| 798 |
if ( $fi === null ) { |
| 799 |
return; |
| 800 |
} |
| 801 |
if ( $fi->isNullable() ) { |
| 802 |
|
| 803 |
if ( $null === 'NOT NULL' ) { |
| 804 |
$this->output( "Changing '$table.$field' to not allow NULLs\n" ); |
| 805 |
$table = $this->db->addIdentifierQuotes( $table ); |
| 806 |
if ( $update ) { |
| 807 |
$this->db->query( "UPDATE $table SET $field = DEFAULT WHERE $field IS NULL", __METHOD__ ); |
| 808 |
} |
| 809 |
$this->db->query( "ALTER TABLE $table ALTER $field SET NOT NULL", __METHOD__ ); |
| 810 |
} else { |
| 811 |
$this->output( "...column '$table.$field' is already set as NULL\n" ); |
| 812 |
} |
| 813 |
} else { |
| 814 |
|
| 815 |
if ( $null === 'NULL' ) { |
| 816 |
$this->output( "Changing '$table.$field' to allow NULLs\n" ); |
| 817 |
$table = $this->db->addIdentifierQuotes( $table ); |
| 818 |
$this->db->query( "ALTER TABLE $table ALTER $field DROP NOT NULL", __METHOD__ ); |
| 819 |
} else { |
| 820 |
$this->output( "...column '$table.$field' is already set as NOT NULL\n" ); |
| 821 |
} |
| 822 |
} |
| 823 |
} |
| 824 |
|
| 825 |
protected function addPgIndex( $table, $index, $type, $unique = false ) { |
| 826 |
if ( !$this->db->tableExists( $table, __METHOD__ ) ) { |
| 827 |
$this->output( "...$table table does not exist, skipping index.\n" ); |
| 828 |
} elseif ( $this->db->indexExists( $table, $index, __METHOD__ ) ) { |
| 829 |
$this->output( "...index '$index' on table '$table' already exists\n" ); |
| 830 |
} else { |
| 831 |
$this->output( "Creating index '$index' on table '$table' $type\n" ); |
| 832 |
$table = $this->db->addIdentifierQuotes( $table ); |
| 833 |
$unique = $unique ? 'UNIQUE' : ''; |
| 834 |
$this->db->query( "CREATE $unique INDEX $index ON $table $type", __METHOD__ ); |
| 835 |
} |
| 836 |
} |
| 837 |
|
| 838 |
protected function addPgExtIndex( $table, $index, $type ) { |
| 839 |
if ( $this->db->indexExists( $table, $index, __METHOD__ ) ) { |
| 840 |
$this->output( "...index '$index' on table '$table' already exists\n" ); |
| 841 |
} elseif ( preg_match( '/^\(/', $type ) ) { |
| 842 |
$this->output( "Creating index '$index' on table '$table'\n" ); |
| 843 |
$table = $this->db->addIdentifierQuotes( $table ); |
| 844 |
$this->db->query( "CREATE INDEX $index ON $table $type", __METHOD__ ); |
| 845 |
} else { |
| 846 |
$this->applyPatch( $type, true, "Creating index '$index' on table '$table'" ); |
| 847 |
} |
| 848 |
} |
| 849 |
|
| 850 |
protected function dropFkey( $table, $field ) { |
| 851 |
if ( !$this->db->tableExists( $table, __METHOD__ ) ) { |
| 852 |
$this->output( "...$table table does not exist, skipping constraint change.\n" ); |
| 853 |
return; |
| 854 |
} |
| 855 |
$fi = $this->db->fieldInfo( $table, $field ); |
| 856 |
if ( $fi === null ) { |
| 857 |
$this->output( "WARNING! Column '$table.$field' does not exist but it should! " . |
| 858 |
"Please report this.\n" ); |
| 859 |
return; |
| 860 |
} |
| 861 |
|
| 862 |
if ( $this->dropConstraint( $table, $field, 'foreignkey', $fi->conname() ) ) { |
| 863 |
$this->output( "Dropping foreign key constraint on '$table.$field'\n" ); |
| 864 |
} else { |
| 865 |
$this->output( "...foreign key constraint on '$table.$field' already does not exist\n" ); |
| 866 |
} |
| 867 |
} |
| 868 |
|
| 869 |
protected function changeFkeyDeferrable( $table, $field, $clause ) { |
| 870 |
$fi = $this->db->fieldInfo( $table, $field ); |
| 871 |
if ( $fi === null ) { |
| 872 |
$this->output( "WARNING! Column '$table.$field' does not exist but it should! " . |
| 873 |
"Please report this.\n" ); |
| 874 |
|
| 875 |
return; |
| 876 |
} |
| 877 |
if ( $fi->is_deferred() && $fi->is_deferrable() ) { |
| 878 |
return; |
| 879 |
} |
| 880 |
$this->output( "Altering column '$table.$field' to be DEFERRABLE INITIALLY DEFERRED\n" ); |
| 881 |
|
| 882 |
$conname = $fi->conname(); |
| 883 |
$conclause = "CONSTRAINT \"$conname\""; |
| 884 |
|
| 885 |
if ( !$this->dropConstraint( $table, $field, 'foreignkey', $conname ) ) { |
| 886 |
$this->output( "Column '$table.$field' does not have a foreign key " . |
| 887 |
"constraint, will be added\n" ); |
| 888 |
$conclause = ""; |
| 889 |
} |
| 890 |
|
| 891 |
$command = |
| 892 |
"ALTER TABLE $table ADD $conclause " . |
| 893 |
"FOREIGN KEY ($field) REFERENCES $clause DEFERRABLE INITIALLY DEFERRED"; |
| 894 |
$this->db->query( $command, __METHOD__ ); |
| 895 |
} |
| 896 |
|
| 897 |
protected function dropPgIndex( $table, $index ) { |
| 898 |
if ( $this->db->indexExists( $table, $index, __METHOD__ ) ) { |
| 899 |
$this->output( "Dropping obsolete index '$index'\n" ); |
| 900 |
$this->db->query( "DROP INDEX \"" . $index . "\"", __METHOD__ ); |
| 901 |
} |
| 902 |
} |
| 903 |
|
| 904 |
protected function checkIndex( $index, $should_be, $good_def ) { |
| 905 |
$pu = $this->db->indexAttributes( $index ); |
| 906 |
if ( $pu && $pu != $should_be ) { |
| 907 |
$this->output( "Dropping obsolete version of index '$index'\n" ); |
| 908 |
$this->db->query( "DROP INDEX \"" . $index . "\"", __METHOD__ ); |
| 909 |
$pu = []; |
| 910 |
} else { |
| 911 |
$this->output( "...no need to drop index '$index'\n" ); |
| 912 |
} |
| 913 |
|
| 914 |
if ( !$pu ) { |
| 915 |
$this->output( "Creating index '$index'\n" ); |
| 916 |
$this->db->query( $good_def, __METHOD__ ); |
| 917 |
} else { |
| 918 |
$this->output( "...index '$index' exists\n" ); |
| 919 |
} |
| 920 |
} |
| 921 |
|
| 922 |
protected function changePrimaryKey( $table, $shouldBe, $constraintName = null ) { |
| 923 |
|
| 924 |
$result = $this->db->query( |
| 925 |
"SELECT a.attname as column " . |
| 926 |
"FROM pg_index i " . |
| 927 |
"JOIN pg_attribute a ON a.attrelid = i.indrelid " . |
| 928 |
"AND a.attnum = ANY(i.indkey) " . |
| 929 |
"WHERE i.indrelid = '\"$table\"'::regclass " . |
| 930 |
"AND i.indisprimary", |
| 931 |
__METHOD__ |
| 932 |
); |
| 933 |
$currentColumns = []; |
| 934 |
foreach ( $result as $row ) { |
| 935 |
$currentColumns[] = $row->column; |
| 936 |
} |
| 937 |
|
| 938 |
if ( $currentColumns == $shouldBe ) { |
| 939 |
$this->output( "...no need to change primary key of '$table'\n" ); |
| 940 |
return true; |
| 941 |
} |
| 942 |
|
| 943 |
$this->dropConstraint( $table, '', 'primary', $constraintName ); |
| 944 |
|
| 945 |
$table = $this->db->addIdentifierQuotes( $table ); |
| 946 |
$this->db->query( |
| 947 |
"ALTER TABLE $table" . |
| 948 |
" ADD PRIMARY KEY (" . implode( ',', $shouldBe ) . ');', |
| 949 |
__METHOD__ |
| 950 |
); |
| 951 |
} |
| 952 |
|
| 953 |
|
| 954 |
|
| 955 |
|
| 956 |
|
| 957 |
|
| 958 |
|
| 959 |
|
| 960 |
|
| 961 |
|
| 962 |
|
| 963 |
|
| 964 |
protected function dropConstraint( $table, $field, $type, $conname = null ) { |
| 965 |
if ( $conname === null ) { |
| 966 |
if ( $type == 'primary' ) { |
| 967 |
$conname = "{$table}_pkey"; |
| 968 |
} else { |
| 969 |
$map = [ 'unique' => 'key', 'check' => 'check', 'foreignkey' => 'fkey' ]; |
| 970 |
$conname = "{$table}_{$field}_{$map[$type]}"; |
| 971 |
} |
| 972 |
} |
| 973 |
|
| 974 |
if ( $this->db->constraintExists( $table, $conname ) ) { |
| 975 |
$table = $this->db->addIdentifierQuotes( $table ); |
| 976 |
$this->db->query( |
| 977 |
"ALTER TABLE $table DROP CONSTRAINT $conname;", |
| 978 |
__METHOD__ |
| 979 |
); |
| 980 |
|
| 981 |
return true; |
| 982 |
} |
| 983 |
|
| 984 |
return false; |
| 985 |
} |
| 986 |
|
| 987 |
|
| 988 |
|
| 989 |
|
| 990 |
|
| 991 |
|
| 992 |
|
| 993 |
protected function migrateSearchindex() { |
| 994 |
$updateKey = 'searchindex-pk-titlelength'; |
| 995 |
if ( !$this->tableExists( 'searchindex' ) ) { |
| 996 |
return; |
| 997 |
} |
| 998 |
|
| 999 |
$primaryIndexExists = $this->db->indexExists( 'searchindex', 'searchindex_pkey' ); |
| 1000 |
if ( $this->updateRowExists( $updateKey ) || ( $primaryIndexExists ) ) { |
| 1001 |
$this->output( "...searchindex table has already been migrated.\n" ); |
| 1002 |
if ( !$this->updateRowExists( $updateKey ) ) { |
| 1003 |
$this->insertUpdateRow( $updateKey ); |
| 1004 |
} |
| 1005 |
return; |
| 1006 |
} |
| 1007 |
|
| 1008 |
$apply = $this->applyPatch( 'patch-searchindex-pk-titlelength.sql', false, '...migrating searchindex table' ); |
| 1009 |
|
| 1010 |
if ( $apply ) { |
| 1011 |
$this->insertUpdateRow( $updateKey ); |
| 1012 |
} |
| 1013 |
} |
| 1014 |
} |