* Oracle schema update to latest (tested with phpunit)
[mediawiki.git] / includes / installer / OracleUpdater.php
blob366cd44865b3f14f22a9a05616e590f219165d0b
1 <?php
2 /**
3 * Oracle-specific updater.
5 * @file
6 * @ingroup Deployment
7 */
9 /**
10 * Class for handling updates to Oracle databases.
12 * @ingroup Deployment
13 * @since 1.17
15 class OracleUpdater extends DatabaseUpdater {
17 /**
18 * Handle to the database subclass
20 * @var DatabaseOracle
22 protected $db;
24 protected function getCoreUpdateList() {
25 return array(
26 // 1.17
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' ),
35 //1.18
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' ),
41 //1.19
42 array( 'addTable', 'config', 'patch-config.sql' ),
43 array( 'addIndex', 'logging', 'i05', 'patch-logging_type_action_index.sql'),
44 array( 'addTable', 'globaltemplatelinks', 'patch-globaltemplatelinks.sql' ),
45 array( 'addTable', 'globalnamespaces', 'patch-globalnamespaces.sql' ),
46 array( 'addTable', 'globalinterwiki', 'patch-globalinterwiki.sql' ),
47 array( 'addField', 'revision', 'rev_sha1', 'patch-rev_sha1_field.sql' ),
48 array( 'addField', 'archive', 'ar_sha1', 'patch-ar_sha1_field.sql' ),
49 array( 'doRemoveNotNullEmptyDefaults2' ),
50 array( 'addIndex', 'page', 'i03', 'patch-page_redirect_namespace_len.sql' ),
51 array( 'modifyField', 'user', 'ug_group', 'patch-ug_group-length-increase.sql' ),
52 array( 'addField', 'uploadstash', 'us_chunk_inx', 'patch-us_chunk_inx_field.sql' ),
53 array( 'addField', 'job', 'job_timestamp', 'patch-job_timestamp_field.sql' ),
54 array( 'addIndex', 'job', 'i02', 'patch-job_timestamp_index.sql' ),
56 // KEEP THIS AT THE BOTTOM!!
57 array( 'doRebuildDuplicateFunction' ),
62 /**
63 * MySQL uses datatype defaults for NULL inserted into NOT NULL fields
64 * In namespace case that results into insert of 0 which is default namespace
65 * Oracle inserts NULL, so namespace fields should have a default value
67 protected function doNamespaceDefaults() {
68 $this->output( "Altering namespace fields with default value ... " );
69 $meta = $this->db->fieldInfo( 'page', 'page_namespace' );
70 if ( $meta->defaultValue() != null ) {
71 $this->output( "defaults seem to present on namespace fields\n" );
72 return;
75 $this->applyPatch( 'patch_namespace_defaults.sql', false );
76 $this->output( "ok\n" );
79 /**
80 * Uniform FK names + deferrable state
82 protected function doFKRenameDeferr() {
83 $this->output( "Altering foreign keys ... " );
84 $meta = $this->db->query( 'SELECT COUNT(*) cnt FROM user_constraints WHERE constraint_type = \'R\' AND deferrable = \'DEFERRABLE\'' );
85 $row = $meta->fetchRow();
86 if ( $row && $row['cnt'] > 0 ) {
87 $this->output( "at least one FK is deferrable, considering up to date\n" );
88 return;
91 $this->applyPatch( 'patch_fk_rename_deferred.sql', false );
92 $this->output( "ok\n" );
95 /**
96 * Recreate functions to 17 schema layout
98 protected function doFunctions17() {
99 $this->output( "Recreating functions ... " );
100 $this->applyPatch( 'patch_create_17_functions.sql', false );
101 $this->output( "ok\n" );
105 * Schema upgrade 16->17
106 * there are no incremental patches prior to this
108 protected function doSchemaUpgrade17() {
109 $this->output( "Updating schema to 17 ... " );
110 // check if iwlinks table exists which was added in 1.17
111 if ( $this->db->tableExists( 'iwlinks' ) ) {
112 $this->output( "schema seem to be up to date.\n" );
113 return;
115 $this->applyPatch( 'patch_16_17_schema_changes.sql', false );
116 $this->output( "ok\n" );
120 * Insert page (page_id = 0) to prevent FK constraint violation
122 protected function doInsertPage0() {
123 $this->output( "Inserting page 0 if missing ... " );
124 $row = array(
125 'page_id' => 0,
126 'page_namespace' => 0,
127 'page_title' => ' ',
128 'page_counter' => 0,
129 'page_is_redirect' => 0,
130 'page_is_new' => 0,
131 'page_random' => 0,
132 'page_touched' => $this->db->timestamp(),
133 'page_latest' => 0,
134 'page_len' => 0
136 $this->db->insert( 'page', $row, 'OracleUpdater:doInserPage0', array( 'IGNORE' ) );
137 $this->output( "ok\n" );
141 * Remove DEFAULT '' NOT NULL constraints from fields as '' is internally
142 * converted to NULL in Oracle
144 protected function doRemoveNotNullEmptyDefaults() {
145 $this->output( "Removing not null empty constraints ... " );
146 $meta = $this->db->fieldInfo( 'categorylinks' , 'cl_sortkey_prefix' );
147 if ( $meta->isNullable() ) {
148 $this->output( "constraints seem to be removed\n" );
149 return;
151 $this->applyPatch( 'patch_remove_not_null_empty_defs.sql', false );
152 $this->output( "ok\n" );
154 protected function doRemoveNotNullEmptyDefaults2() {
155 $this->output( "Removing not null empty constraints ... " );
156 $meta = $this->db->fieldInfo( 'ipblocks' , 'ipb_by_text' );
157 if ( $meta->isNullable() ) {
158 $this->output( "constraints seem to be removed\n" );
159 return;
161 $this->applyPatch( 'patch_remove_not_null_empty_defs2.sql', false );
162 $this->output( "ok\n" );
166 * Removed forcing of invalid state on recentchanges_fk2.
167 * cascading taken in account in the deleting function
169 protected function doRecentchangesFK2Cascade() {
170 $this->output( "Altering RECENTCHANGES_FK2 ... " );
172 $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\'' );
173 $row = $meta->fetchRow();
174 if ( $row ) {
175 $this->output( "FK up to date\n" );
176 return;
179 $this->applyPatch( 'patch_recentchanges_fk2_cascade.sql', false );
180 $this->output( "ok\n" );
184 * rebuilding of the function that duplicates tables for tests
186 protected function doRebuildDuplicateFunction() {
187 $this->output( "Rebuilding duplicate function ... " );
188 $this->applyPatch( 'patch_rebuild_dupfunc.sql', false );
189 $this->output( "ok\n" );
193 * Overload: after this action field info table has to be rebuilt
195 * @param $what array
197 public function doUpdates( $what = array( 'core', 'extensions', 'purge', 'stats' ) ) {
198 parent::doUpdates( $what );
200 $this->db->query( 'BEGIN fill_wiki_info; END;' );
204 * Overload: because of the DDL_MODE tablename escaping is a bit dodgy
206 protected function purgeCache() {
207 # We can't guarantee that the user will be able to use TRUNCATE,
208 # but we know that DELETE is available to us
209 $this->output( "Purging caches..." );
210 $this->db->delete( '/*Q*/'.$this->db->tableName( 'objectcache' ), '*', __METHOD__ );
211 $this->output( "done.\n" );