SqliteUpdater.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. <?php
  2. /**
  3. * Sqlite-specific updater.
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program; if not, write to the Free Software Foundation, Inc.,
  17. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. * http://www.gnu.org/copyleft/gpl.html
  19. *
  20. * @file
  21. * @ingroup Deployment
  22. */
  23. use Wikimedia\Rdbms\DatabaseSqlite;
  24. /**
  25. * Class for handling updates to Sqlite databases.
  26. *
  27. * @ingroup Deployment
  28. * @since 1.17
  29. */
  30. class SqliteUpdater extends DatabaseUpdater {
  31. protected function getCoreUpdateList() {
  32. return [
  33. [ 'disableContentHandlerUseDB' ],
  34. // 1.14
  35. [ 'addField', 'site_stats', 'ss_active_users', 'patch-ss_active_users.sql' ],
  36. [ 'doActiveUsersInit' ],
  37. [ 'addField', 'ipblocks', 'ipb_allow_usertalk', 'patch-ipb_allow_usertalk.sql' ],
  38. [ 'sqliteInitialIndexes' ],
  39. // 1.15
  40. [ 'addTable', 'change_tag', 'patch-change_tag.sql' ],
  41. // 1.16
  42. [ 'addTable', 'user_properties', 'patch-user_properties.sql' ],
  43. [ 'addTable', 'log_search', 'patch-log_search.sql' ],
  44. [ 'ifNoActorTable', 'addField', 'logging', 'log_user_text', 'patch-log_user_text.sql' ],
  45. # listed separately from the previous update because 1.16 was released without this update
  46. [ 'ifNoActorTable', 'doLogUsertextPopulation' ],
  47. [ 'doLogSearchPopulation' ],
  48. [ 'addTable', 'l10n_cache', 'patch-l10n_cache.sql' ],
  49. [ 'dropIndex', 'change_tag', 'ct_rc_id', 'patch-change_tag-indexes.sql' ],
  50. [ 'addField', 'redirect', 'rd_interwiki', 'patch-rd_interwiki.sql' ],
  51. [ 'sqliteSetupSearchindex' ],
  52. // 1.17
  53. [ 'addTable', 'iwlinks', 'patch-iwlinks.sql' ],
  54. [ 'addIndex', 'iwlinks', 'iwl_prefix_title_from', 'patch-rename-iwl_prefix.sql' ],
  55. [ 'addField', 'updatelog', 'ul_value', 'patch-ul_value.sql' ],
  56. [ 'addField', 'interwiki', 'iw_api', 'patch-iw_api_and_wikiid.sql' ],
  57. [ 'dropIndex', 'iwlinks', 'iwl_prefix', 'patch-kill-iwl_prefix.sql' ],
  58. [ 'addField', 'categorylinks', 'cl_collation', 'patch-categorylinks-better-collation.sql' ],
  59. [ 'addTable', 'module_deps', 'patch-module_deps.sql' ],
  60. [ 'dropIndex', 'archive', 'ar_page_revid', 'patch-archive_kill_ar_page_revid.sql' ],
  61. [ 'addIndexIfNoneExist',
  62. 'archive', [ 'ar_revid', 'ar_revid_uniq' ], 'patch-archive_ar_revid.sql' ],
  63. // 1.18
  64. [ 'addIndex', 'user', 'user_email', 'patch-user_email_index.sql' ],
  65. [ 'addTable', 'uploadstash', 'patch-uploadstash.sql' ],
  66. [ 'addTable', 'user_former_groups', 'patch-user_former_groups.sql' ],
  67. // 1.19
  68. [ 'doMigrateUserOptions' ],
  69. [ 'dropField', 'user', 'user_options', 'patch-drop-user_options.sql' ],
  70. [ 'addField', 'revision', 'rev_sha1', 'patch-rev_sha1.sql' ],
  71. [ 'addField', 'archive', 'ar_sha1', 'patch-ar_sha1.sql' ],
  72. [ 'addIndex', 'page', 'page_redirect_namespace_len',
  73. 'patch-page_redirect_namespace_len.sql' ],
  74. [ 'addField', 'uploadstash', 'us_chunk_inx', 'patch-uploadstash_chunk.sql' ],
  75. [ 'addfield', 'job', 'job_timestamp', 'patch-jobs-add-timestamp.sql' ],
  76. // 1.20
  77. [ 'addIndex', 'revision', 'page_user_timestamp', 'patch-revision-user-page-index.sql' ],
  78. [ 'addField', 'ipblocks', 'ipb_parent_block_id', 'patch-ipb-parent-block-id.sql' ],
  79. [ 'addIndex', 'ipblocks', 'ipb_parent_block_id', 'patch-ipb-parent-block-id-index.sql' ],
  80. [ 'dropField', 'category', 'cat_hidden', 'patch-cat_hidden.sql' ],
  81. // 1.21
  82. [ 'addField', 'revision', 'rev_content_format', 'patch-revision-rev_content_format.sql' ],
  83. [ 'addField', 'revision', 'rev_content_model', 'patch-revision-rev_content_model.sql' ],
  84. [ 'addField', 'archive', 'ar_content_format', 'patch-archive-ar_content_format.sql' ],
  85. [ 'addField', 'archive', 'ar_content_model', 'patch-archive-ar_content_model.sql' ],
  86. [ 'addField', 'page', 'page_content_model', 'patch-page-page_content_model.sql' ],
  87. [ 'enableContentHandlerUseDB' ],
  88. [ 'dropField', 'site_stats', 'ss_admins', 'patch-drop-ss_admins.sql' ],
  89. [ 'dropField', 'recentchanges', 'rc_moved_to_title', 'patch-rc_moved.sql' ],
  90. [ 'addTable', 'sites', 'patch-sites.sql' ],
  91. [ 'addField', 'filearchive', 'fa_sha1', 'patch-fa_sha1.sql' ],
  92. [ 'addField', 'job', 'job_token', 'patch-job_token.sql' ],
  93. [ 'addField', 'job', 'job_attempts', 'patch-job_attempts.sql' ],
  94. [ 'doEnableProfiling' ],
  95. [ 'addField', 'uploadstash', 'us_props', 'patch-uploadstash-us_props.sql' ],
  96. [ 'modifyField', 'user_groups', 'ug_group', 'patch-ug_group-length-increase-255.sql' ],
  97. [ 'modifyField', 'user_former_groups', 'ufg_group',
  98. 'patch-ufg_group-length-increase-255.sql' ],
  99. [ 'addIndex', 'page_props', 'pp_propname_page',
  100. 'patch-page_props-propname-page-index.sql' ],
  101. [ 'addIndex', 'image', 'img_media_mime', 'patch-img_media_mime-index.sql' ],
  102. // 1.22
  103. [ 'addIndex', 'iwlinks', 'iwl_prefix_from_title', 'patch-iwlinks-from-title-index.sql' ],
  104. [ 'addField', 'archive', 'ar_id', 'patch-archive-ar_id.sql' ],
  105. [ 'addField', 'externallinks', 'el_id', 'patch-externallinks-el_id.sql' ],
  106. // 1.23
  107. [ 'addField', 'recentchanges', 'rc_source', 'patch-rc_source.sql' ],
  108. [ 'ifNoActorTable', 'addIndex', 'logging', 'log_user_text_type_time',
  109. 'patch-logging_user_text_type_time_index.sql' ],
  110. [ 'ifNoActorTable', 'addIndex', 'logging', 'log_user_text_time',
  111. 'patch-logging_user_text_time_index.sql' ],
  112. [ 'addField', 'page', 'page_links_updated', 'patch-page_links_updated.sql' ],
  113. [ 'addField', 'user', 'user_password_expires', 'patch-user_password_expire.sql' ],
  114. // 1.24
  115. [ 'addField', 'page_props', 'pp_sortkey', 'patch-pp_sortkey.sql' ],
  116. [ 'dropField', 'recentchanges', 'rc_cur_time', 'patch-drop-rc_cur_time.sql' ],
  117. [ 'addIndex', 'watchlist', 'wl_user_notificationtimestamp',
  118. 'patch-watchlist-user-notificationtimestamp-index.sql' ],
  119. [ 'addField', 'page', 'page_lang', 'patch-page-page_lang.sql' ],
  120. [ 'addField', 'pagelinks', 'pl_from_namespace', 'patch-pl_from_namespace.sql' ],
  121. [ 'addField', 'templatelinks', 'tl_from_namespace', 'patch-tl_from_namespace.sql' ],
  122. [ 'addField', 'imagelinks', 'il_from_namespace', 'patch-il_from_namespace.sql' ],
  123. // 1.25
  124. [ 'dropTable', 'hitcounter' ],
  125. [ 'dropField', 'site_stats', 'ss_total_views', 'patch-drop-ss_total_views.sql' ],
  126. [ 'dropField', 'page', 'page_counter', 'patch-drop-page_counter.sql' ],
  127. [ 'modifyField', 'filearchive', 'fa_deleted_reason', 'patch-editsummary-length.sql' ],
  128. // 1.27
  129. [ 'dropTable', 'msg_resource_links' ],
  130. [ 'dropTable', 'msg_resource' ],
  131. [ 'addTable', 'bot_passwords', 'patch-bot_passwords.sql' ],
  132. [ 'addField', 'watchlist', 'wl_id', 'patch-watchlist-wl_id.sql' ],
  133. [ 'dropIndex', 'categorylinks', 'cl_collation', 'patch-kill-cl_collation_index.sql' ],
  134. [ 'addIndex', 'categorylinks', 'cl_collation_ext',
  135. 'patch-add-cl_collation_ext_index.sql' ],
  136. [ 'doCollationUpdate' ],
  137. // 1.28
  138. [ 'addIndex', 'recentchanges', 'rc_name_type_patrolled_timestamp',
  139. 'patch-add-rc_name_type_patrolled_timestamp_index.sql' ],
  140. [ 'addField', 'change_tag', 'ct_id', 'patch-change_tag-ct_id.sql' ],
  141. // 1.29
  142. [ 'addField', 'externallinks', 'el_index_60', 'patch-externallinks-el_index_60.sql' ],
  143. [ 'addField', 'user_groups', 'ug_expiry', 'patch-user_groups-ug_expiry.sql' ],
  144. [ 'ifNoActorTable', 'addIndex', 'image', 'img_user_timestamp', 'patch-image-user-index-2.sql' ],
  145. // 1.30
  146. [ 'modifyField', 'image', 'img_media_type', 'patch-add-3d.sql' ],
  147. [ 'addTable', 'ip_changes', 'patch-ip_changes.sql' ],
  148. [ 'renameIndex', 'categorylinks', 'cl_from', 'PRIMARY', false,
  149. 'patch-categorylinks-fix-pk.sql' ],
  150. [ 'renameIndex', 'templatelinks', 'tl_from', 'PRIMARY', false,
  151. 'patch-templatelinks-fix-pk.sql' ],
  152. [ 'renameIndex', 'pagelinks', 'pl_from', 'PRIMARY', false, 'patch-pagelinks-fix-pk.sql' ],
  153. [ 'renameIndex', 'text', 'old_id', 'PRIMARY', false, 'patch-text-fix-pk.sql' ],
  154. [ 'renameIndex', 'imagelinks', 'il_from', 'PRIMARY', false, 'patch-imagelinks-fix-pk.sql' ],
  155. [ 'renameIndex', 'iwlinks', 'iwl_from', 'PRIMARY', false, 'patch-iwlinks-fix-pk.sql' ],
  156. [ 'renameIndex', 'langlinks', 'll_from', 'PRIMARY', false, 'patch-langlinks-fix-pk.sql' ],
  157. [ 'renameIndex', 'log_search', 'ls_field_val', 'PRIMARY', false, 'patch-log_search-fix-pk.sql' ],
  158. [ 'renameIndex', 'module_deps', 'md_module_skin', 'PRIMARY', false,
  159. 'patch-module_deps-fix-pk.sql' ],
  160. [ 'renameIndex', 'objectcache', 'keyname', 'PRIMARY', false, 'patch-objectcache-fix-pk.sql' ],
  161. [ 'renameIndex', 'querycache_info', 'qci_type', 'PRIMARY', false,
  162. 'patch-querycache_info-fix-pk.sql' ],
  163. [ 'renameIndex', 'site_stats', 'ss_row_id', 'PRIMARY', false, 'patch-site_stats-fix-pk.sql' ],
  164. [ 'renameIndex', 'user_former_groups', 'ufg_user_group', 'PRIMARY', false,
  165. 'patch-user_former_groups-fix-pk.sql' ],
  166. [ 'renameIndex', 'user_properties', 'user_properties_user_property', 'PRIMARY', false,
  167. 'patch-user_properties-fix-pk.sql' ],
  168. [ 'addTable', 'comment', 'patch-comment-table.sql' ],
  169. [ 'addTable', 'revision_comment_temp', 'patch-revision_comment_temp-table.sql' ],
  170. // image_comment_temp is no longer needed when upgrading to MW 1.31 or newer,
  171. // as it is dropped later in the update process as part of 'migrateImageCommentTemp'.
  172. // File kept on disk and the updater entry here for historical purposes.
  173. // [ 'addTable', 'image_comment_temp', 'patch-image_comment_temp-table.sql' ],
  174. [ 'addField', 'archive', 'ar_comment_id', 'patch-archive-ar_comment_id.sql' ],
  175. [ 'modifyField', 'image', 'img_description', 'patch-image-img_description-default.sql' ],
  176. [ 'addField', 'ipblocks', 'ipb_reason_id', 'patch-ipblocks-ipb_reason_id.sql' ],
  177. [ 'addField', 'logging', 'log_comment_id', 'patch-logging-log_comment_id.sql' ],
  178. [ 'addField', 'oldimage', 'oi_description_id', 'patch-oldimage-oi_description_id.sql' ],
  179. [ 'addField', 'protected_titles', 'pt_reason_id', 'patch-protected_titles-pt_reason_id.sql' ],
  180. [ 'addField', 'recentchanges', 'rc_comment_id', 'patch-recentchanges-rc_comment_id.sql' ],
  181. [ 'modifyField', 'revision', 'rev_comment', 'patch-revision-rev_comment-default.sql' ],
  182. // This field was added in 1.31, but is put here so it can be used by 'migrateComments'
  183. [ 'addField', 'image', 'img_description_id', 'patch-image-img_description_id.sql' ],
  184. [ 'addField', 'filearchive', 'fa_description_id', 'patch-filearchive-fa_description_id.sql' ],
  185. [ 'migrateComments' ],
  186. [ 'renameIndex', 'l10n_cache', 'lc_lang_key', 'PRIMARY', false,
  187. 'patch-l10n_cache-primary-key.sql' ],
  188. // 1.31
  189. [ 'addTable', 'content', 'patch-content.sql' ],
  190. [ 'addTable', 'content_models', 'patch-content_models.sql' ],
  191. [ 'addTable', 'slots', 'patch-slots.sql' ],
  192. [ 'addField', 'slots', 'slot_origin', 'patch-slot-origin.sql' ],
  193. [ 'addTable', 'slot_roles', 'patch-slot_roles.sql' ],
  194. [ 'migrateArchiveText' ],
  195. [ 'addTable', 'actor', 'patch-actor-table.sql' ],
  196. [ 'addField', 'archive', 'ar_actor', 'patch-archive-ar_actor.sql' ],
  197. [ 'addTable', 'revision_actor_temp', 'patch-revision_actor_temp-table.sql' ],
  198. [ 'addField', 'ipblocks', 'ipb_by_actor', 'patch-ipblocks-ipb_by_actor.sql' ],
  199. [ 'addField', 'image', 'img_actor', 'patch-image-img_actor.sql' ],
  200. [ 'addField', 'oldimage', 'oi_actor', 'patch-oldimage-oi_actor.sql' ],
  201. [ 'addField', 'filearchive', 'fa_actor', 'patch-filearchive-fa_actor.sql' ],
  202. [ 'addField', 'recentchanges', 'rc_actor', 'patch-recentchanges-rc_actor.sql' ],
  203. [ 'addField', 'logging', 'log_actor', 'patch-logging-log_actor.sql' ],
  204. [ 'migrateActors' ],
  205. [ 'modifyField', 'revision', 'rev_text_id', 'patch-rev_text_id-default.sql' ],
  206. [ 'modifyTable', 'site_stats', 'patch-site_stats-modify.sql' ],
  207. [ 'populateArchiveRevId' ],
  208. [ 'addIndex', 'recentchanges', 'rc_namespace_title_timestamp',
  209. 'patch-recentchanges-nttindex.sql' ],
  210. // 1.32
  211. [ 'addTable', 'change_tag_def', 'patch-change_tag_def.sql' ],
  212. [ 'populateExternallinksIndex60' ],
  213. [ 'modifyfield', 'externallinks', 'el_index_60',
  214. 'patch-externallinks-el_index_60-drop-default.sql' ],
  215. [ 'runMaintenance', DeduplicateArchiveRevId::class, 'maintenance/deduplicateArchiveRevId.php' ],
  216. [ 'addField', 'change_tag', 'ct_tag_id', 'patch-change_tag-tag_id.sql' ],
  217. [ 'addIndex', 'archive', 'ar_revid_uniq', 'patch-archive-ar_rev_id-unique.sql' ],
  218. [ 'populateContentTables' ],
  219. [ 'addIndex', 'logging', 'log_type_action', 'patch-logging-log-type-action-index.sql' ],
  220. [ 'dropIndex', 'logging', 'type_action', 'patch-logging-drop-type-action-index.sql' ],
  221. [ 'renameIndex', 'interwiki', 'iw_prefix', 'PRIMARY', false, 'patch-interwiki-fix-pk.sql' ],
  222. [ 'renameIndex', 'page_props', 'pp_page_propname', 'PRIMARY', false,
  223. 'patch-page_props-fix-pk.sql' ],
  224. [ 'renameIndex', 'protected_titles', 'pt_namespace_title', 'PRIMARY', false,
  225. 'patch-protected_titles-fix-pk.sql' ],
  226. [ 'renameIndex', 'site_identifiers', 'site_ids_type', 'PRIMARY', false,
  227. 'patch-site_identifiers-fix-pk.sql' ],
  228. [ 'addIndex', 'recentchanges', 'rc_this_oldid', 'patch-recentchanges-rc_this_oldid-index.sql' ],
  229. [ 'dropTable', 'transcache' ],
  230. [ 'runMaintenance', PopulateChangeTagDef::class, 'maintenance/populateChangeTagDef.php' ],
  231. [ 'addIndex', 'change_tag', 'change_tag_rc_tag_id',
  232. 'patch-change_tag-change_tag_rc_tag_id.sql' ],
  233. [ 'addField', 'ipblocks', 'ipb_sitewide', 'patch-ipb_sitewide.sql' ],
  234. [ 'addTable', 'ipblocks_restrictions', 'patch-ipblocks_restrictions-table.sql' ],
  235. [ 'migrateImageCommentTemp' ],
  236. // 1.33
  237. [ 'dropField', 'change_tag', 'ct_tag', 'patch-drop-ct_tag.sql' ],
  238. [ 'dropTable', 'valid_tag' ],
  239. [ 'dropTable', 'tag_summary' ],
  240. [ 'dropField', 'archive', 'ar_comment', 'patch-archive-drop-ar_comment.sql' ],
  241. [ 'dropField', 'ipblocks', 'ipb_reason', 'patch-ipblocks-drop-ipb_reason.sql' ],
  242. [ 'dropField', 'image', 'img_description', 'patch-image-drop-img_description.sql' ],
  243. [ 'dropField', 'oldimage', 'oi_description', 'patch-oldimage-drop-oi_description.sql' ],
  244. [ 'dropField', 'filearchive', 'fa_description', 'patch-filearchive-drop-fa_description.sql' ],
  245. [ 'dropField', 'recentchanges', 'rc_comment', 'patch-recentchanges-drop-rc_comment.sql' ],
  246. [ 'dropField', 'logging', 'log_comment', 'patch-logging-drop-log_comment.sql' ],
  247. [ 'dropField', 'protected_titles', 'pt_reason', 'patch-protected_titles-drop-pt_reason.sql' ],
  248. // 1.34
  249. [ 'dropField', 'archive', 'ar_user', 'patch-archive-drop-ar_user.sql' ],
  250. [ 'dropField', 'ipblocks', 'ipb_by', 'patch-ipblocks-drop-ipb_by.sql' ],
  251. [ 'dropField', 'image', 'img_user', 'patch-image-drop-img_user.sql' ],
  252. [ 'dropField', 'oldimage', 'oi_user', 'patch-oldimage-drop-oi_user.sql' ],
  253. [ 'dropField', 'filearchive', 'fa_user', 'patch-filearchive-drop-fa_user.sql' ],
  254. [ 'dropField', 'recentchanges', 'rc_user', 'patch-recentchanges-drop-rc_user.sql' ],
  255. [ 'dropField', 'logging', 'log_user', 'patch-logging-drop-log_user.sql' ],
  256. ];
  257. }
  258. protected function sqliteInitialIndexes() {
  259. // initial-indexes.sql fails if the indexes are already present,
  260. // so we perform a quick check if our database is newer.
  261. if ( $this->updateRowExists( 'initial_indexes' ) ||
  262. $this->db->indexExists( 'user', 'user_name', __METHOD__ )
  263. ) {
  264. $this->output( "...have initial indexes\n" );
  265. return;
  266. }
  267. $this->applyPatch( 'initial-indexes.sql', false, "Adding initial indexes" );
  268. }
  269. protected function sqliteSetupSearchindex() {
  270. $module = DatabaseSqlite::getFulltextSearchModule();
  271. $fts3tTable = $this->updateRowExists( 'fts3' );
  272. if ( $fts3tTable && !$module ) {
  273. $this->applyPatch(
  274. 'searchindex-no-fts.sql',
  275. false,
  276. 'PHP is missing FTS3 support, downgrading tables'
  277. );
  278. } elseif ( !$fts3tTable && $module == 'FTS3' ) {
  279. $this->applyPatch( 'searchindex-fts3.sql', false, "Adding FTS3 search capabilities" );
  280. } else {
  281. $this->output( "...fulltext search table appears to be in order.\n" );
  282. }
  283. }
  284. }