3 * Oracle-specific updater.
10 * Class for handling updates to Oracle databases.
15 class OracleUpdater
extends DatabaseUpdater
{
18 * Handle to the database subclass
24 protected function getCoreUpdateList() {
27 array( 'doNamespaceDefaults' ),
28 array( 'doFKRenameDeferr' ),
29 array( 'doFunctions17' ),
30 array( 'doSchemaUpgrade17' ),
31 array( 'doInsertPage0' ),
32 array( 'doRemoveNotNullEmptyDefaults' ),
33 array( 'addTable', 'user_former_groups', 'patch-user_former_groups.sql' ),
36 array( 'addIndex', 'user', 'i02', 'patch-user_email_index.sql' ),
37 array( 'modifyField', 'user_properties', 'up_property', 'patch-up_property.sql' ),
38 array( 'addTable', 'uploadstash', 'patch-uploadstash.sql' ),
39 array( 'doRecentchangesFK2Cascade' ),
42 array( 'addIndex', 'logging', 'i05', 'patch-logging_type_action_index.sql'),
43 array( 'addTable', 'globaltemplatelinks', 'patch-globaltemplatelinks.sql' ),
44 array( 'addTable', 'globalnamespaces', 'patch-globalnamespaces.sql' ),
45 array( 'addTable', 'globalinterwiki', 'patch-globalinterwiki.sql' ),
46 array( 'addField', 'revision', 'rev_sha1', 'patch-rev_sha1_field.sql' ),
47 array( 'addField', 'archive', 'ar_sha1', 'patch-ar_sha1_field.sql' ),
48 array( 'doRemoveNotNullEmptyDefaults2' ),
49 array( 'addIndex', 'page', 'i03', 'patch-page_redirect_namespace_len.sql' ),
50 array( 'modifyField', 'user', 'ug_group', 'patch-ug_group-length-increase.sql' ),
51 array( 'addField', 'uploadstash', 'us_chunk_inx', 'patch-us_chunk_inx_field.sql' ),
52 array( 'addField', 'job', 'job_timestamp', 'patch-job_timestamp_field.sql' ),
53 array( 'addIndex', 'job', 'i02', 'patch-job_timestamp_index.sql' ),
56 // content model stuff for WikiData
57 array( 'addField', 'revision', 'rev_content_format', 'patch-revision-rev_content_format.sql' ),
58 array( 'addField', 'revision', 'rev_content_model', 'patch-revision-rev_content_model.sql' ),
59 array( 'addField', 'archive', 'ar_content_format', 'patch-archive-ar_content_format.sql' ),
60 array( 'addField', 'archive', 'ar_content_model', 'patch-archive-ar_content_model.sql' ),
61 array( 'addField', 'page', 'page_content_model', 'patch-page-page_content_model.sql' ),
63 array( 'addTable', 'config', 'patch-config.sql' ),
65 // KEEP THIS AT THE BOTTOM!!
66 array( 'doRebuildDuplicateFunction' ),
72 * MySQL uses datatype defaults for NULL inserted into NOT NULL fields
73 * In namespace case that results into insert of 0 which is default namespace
74 * Oracle inserts NULL, so namespace fields should have a default value
76 protected function doNamespaceDefaults() {
77 $this->output( "Altering namespace fields with default value ... " );
78 $meta = $this->db
->fieldInfo( 'page', 'page_namespace' );
79 if ( $meta->defaultValue() != null ) {
80 $this->output( "defaults seem to present on namespace fields\n" );
84 $this->applyPatch( 'patch_namespace_defaults.sql', false );
85 $this->output( "ok\n" );
89 * Uniform FK names + deferrable state
91 protected function doFKRenameDeferr() {
92 $this->output( "Altering foreign keys ... " );
93 $meta = $this->db
->query( 'SELECT COUNT(*) cnt FROM user_constraints WHERE constraint_type = \'R\' AND deferrable = \'DEFERRABLE\'' );
94 $row = $meta->fetchRow();
95 if ( $row && $row['cnt'] > 0 ) {
96 $this->output( "at least one FK is deferrable, considering up to date\n" );
100 $this->applyPatch( 'patch_fk_rename_deferred.sql', false );
101 $this->output( "ok\n" );
105 * Recreate functions to 17 schema layout
107 protected function doFunctions17() {
108 $this->output( "Recreating functions ... " );
109 $this->applyPatch( 'patch_create_17_functions.sql', false );
110 $this->output( "ok\n" );
114 * Schema upgrade 16->17
115 * there are no incremental patches prior to this
117 protected function doSchemaUpgrade17() {
118 $this->output( "Updating schema to 17 ... " );
119 // check if iwlinks table exists which was added in 1.17
120 if ( $this->db
->tableExists( 'iwlinks' ) ) {
121 $this->output( "schema seem to be up to date.\n" );
124 $this->applyPatch( 'patch_16_17_schema_changes.sql', false );
125 $this->output( "ok\n" );
129 * Insert page (page_id = 0) to prevent FK constraint violation
131 protected function doInsertPage0() {
132 $this->output( "Inserting page 0 if missing ... " );
135 'page_namespace' => 0,
138 'page_is_redirect' => 0,
141 'page_touched' => $this->db
->timestamp(),
145 $this->db
->insert( 'page', $row, 'OracleUpdater:doInserPage0', array( 'IGNORE' ) );
146 $this->output( "ok\n" );
150 * Remove DEFAULT '' NOT NULL constraints from fields as '' is internally
151 * converted to NULL in Oracle
153 protected function doRemoveNotNullEmptyDefaults() {
154 $this->output( "Removing not null empty constraints ... " );
155 $meta = $this->db
->fieldInfo( 'categorylinks' , 'cl_sortkey_prefix' );
156 if ( $meta->isNullable() ) {
157 $this->output( "constraints seem to be removed\n" );
160 $this->applyPatch( 'patch_remove_not_null_empty_defs.sql', false );
161 $this->output( "ok\n" );
163 protected function doRemoveNotNullEmptyDefaults2() {
164 $this->output( "Removing not null empty constraints ... " );
165 $meta = $this->db
->fieldInfo( 'ipblocks' , 'ipb_by_text' );
166 if ( $meta->isNullable() ) {
167 $this->output( "constraints seem to be removed\n" );
170 $this->applyPatch( 'patch_remove_not_null_empty_defs2.sql', false );
171 $this->output( "ok\n" );
175 * Removed forcing of invalid state on recentchanges_fk2.
176 * cascading taken in account in the deleting function
178 protected function doRecentchangesFK2Cascade() {
179 $this->output( "Altering RECENTCHANGES_FK2 ... " );
181 $meta = $this->db
->query( 'SELECT 1 FROM all_constraints WHERE owner = \''.strtoupper($this->db
->getDBname()).'\' AND constraint_name = \''.$this->db
->tablePrefix().'RECENTCHANGES_FK2\' AND delete_rule = \'CASCADE\'' );
182 $row = $meta->fetchRow();
184 $this->output( "FK up to date\n" );
188 $this->applyPatch( 'patch_recentchanges_fk2_cascade.sql', false );
189 $this->output( "ok\n" );
193 * rebuilding of the function that duplicates tables for tests
195 protected function doRebuildDuplicateFunction() {
196 $this->output( "Rebuilding duplicate function ... " );
197 $this->applyPatch( 'patch_rebuild_dupfunc.sql', false );
198 $this->output( "ok\n" );
202 * Overload: after this action field info table has to be rebuilt
206 public function doUpdates( $what = array( 'core', 'extensions', 'purge', 'stats' ) ) {
207 parent
::doUpdates( $what );
209 $this->db
->query( 'BEGIN fill_wiki_info; END;' );
213 * Overload: because of the DDL_MODE tablename escaping is a bit dodgy
215 protected function purgeCache() {
216 # We can't guarantee that the user will be able to use TRUNCATE,
217 # but we know that DELETE is available to us
218 $this->output( "Purging caches..." );
219 $this->db
->delete( '/*Q*/'.$this->db
->tableName( 'objectcache' ), '*', __METHOD__
);
220 $this->output( "done.\n" );