From 6047e22b5e84e395c7d600c6c56a5e6df4106854 Mon Sep 17 00:00:00 2001 From: Jure Kajzer Date: Wed, 1 Jun 2011 08:27:51 +0000 Subject: [PATCH] * upgrade patches for oracle 1.17->1.19 * fixed tableExists to handle possible username-dbname difference * added indexExists for updater * fixed a bug in DatabaseUpdater * tried not to produce bugs (may have failed) --- includes/db/DatabaseOracle.php | 27 ++++++++++++++++--- includes/installer/DatabaseUpdater.php | 2 +- includes/installer/OracleUpdater.php | 10 ++++++- maintenance/oracle/archives/patch-config.sql | 8 ++++++ .../oracle/archives/patch-up_property.sql | 3 +++ .../archives/patch-user_email_index.sql | 4 +++ maintenance/oracle/tables.sql | 11 +++++++- 7 files changed, 59 insertions(+), 6 deletions(-) create mode 100644 maintenance/oracle/archives/patch-config.sql create mode 100644 maintenance/oracle/archives/patch-up_property.sql create mode 100644 maintenance/oracle/archives/patch-user_email_index.sql diff --git a/includes/db/DatabaseOracle.php b/includes/db/DatabaseOracle.php index 8d86b6f34e..50ab4f2002 100644 --- a/includes/db/DatabaseOracle.php +++ b/includes/db/DatabaseOracle.php @@ -893,12 +893,33 @@ class DatabaseOracle extends DatabaseBase { return $row['version']; } + /** + * Query whether a given index exists + */ + function indexExists( $table, $index, $fname = 'DatabaseOracle::indexExists' ) { + $table = $this->tableName( $table ); + $table = strtoupper( $this->removeIdentifierQuotes( $table ) ); + $index = strtoupper( $index ); + $owner = strtoupper( $this->mDBname ); + $SQL = "SELECT 1 FROM all_indexes WHERE owner='$owner' AND index_name='{$table}_{$index}'"; + $res = $this->doQuery( $SQL ); + if ( $res ) { + $count = $res->numRows(); + $res->free(); + } else { + $count = 0; + } + return $count != 0; + } + /** * Query whether a given table exists (in the given schema, or the default mw one if not given) */ function tableExists( $table ) { - $table = $this->removeIdentifierQuotes($table); - $SQL = "SELECT 1 FROM user_tables WHERE table_name='$table'"; + $table = $this->tableName( $table ); + $table = strtoupper( $this->removeIdentifierQuotes( $table ) ); + $owner = strtoupper( $this->mDBname ); + $SQL = "SELECT 1 FROM all_tables WHERE owner='$owner' AND table_name='$table'"; $res = $this->doQuery( $SQL ); if ( $res ) { $count = $res->numRows(); @@ -906,7 +927,7 @@ class DatabaseOracle extends DatabaseBase { } else { $count = 0; } - return $count; + return $count != 0; } /** diff --git a/includes/installer/DatabaseUpdater.php b/includes/installer/DatabaseUpdater.php index c931e34803..00d2d69d3e 100644 --- a/includes/installer/DatabaseUpdater.php +++ b/includes/installer/DatabaseUpdater.php @@ -65,7 +65,7 @@ abstract class DatabaseUpdater { } else { $this->maintenance = new FakeMaintenance; } - $maintenance->setDB( $db ); + $this->maintenance->setDB( $db ); $this->initOldGlobals(); wfRunHooks( 'LoadExtensionSchemaUpdates', array( $this ) ); } diff --git a/includes/installer/OracleUpdater.php b/includes/installer/OracleUpdater.php index 96aa2a0236..22271980fe 100644 --- a/includes/installer/OracleUpdater.php +++ b/includes/installer/OracleUpdater.php @@ -23,12 +23,20 @@ class OracleUpdater extends DatabaseUpdater { protected function getCoreUpdateList() { return array( - // 1.16 + // 1.17 array( 'doNamespaceDefaults' ), array( 'doFKRenameDeferr' ), array( 'doFunctions17' ), array( 'doSchemaUpgrade17' ), array( 'doInsertPage0' ), + + //1.18 + array( 'addIndex', 'user', 'i02', 'patch-user_email_index.sql' ), + array( 'modifyField', 'user_properties', 'up_property', 'patch-up_property.sql' ), + + // 1.19 + array( 'addTable', 'config', 'patch-config.sql' ), + ); } diff --git a/maintenance/oracle/archives/patch-config.sql b/maintenance/oracle/archives/patch-config.sql new file mode 100644 index 0000000000..66714a73ea --- /dev/null +++ b/maintenance/oracle/archives/patch-config.sql @@ -0,0 +1,8 @@ +define mw_prefix='{$wgDBprefix}'; + +CREATE TABLE &mw_prefix.config ( + cf_name VARCHAR2(255) NOT NULL, + cf_value blob NOT NULL +); +ALTER TABLE &mw_prefix.config ADD CONSTRAINT &mw_prefix.config_pk PRIMARY KEY (cf_name); + diff --git a/maintenance/oracle/archives/patch-up_property.sql b/maintenance/oracle/archives/patch-up_property.sql new file mode 100644 index 0000000000..c8e2dd9501 --- /dev/null +++ b/maintenance/oracle/archives/patch-up_property.sql @@ -0,0 +1,3 @@ +define mw_prefix='{$wgDBprefix}'; + +ALTER TABLE &mw_prefix.user_properties MODIFY up_property varchar2(255); diff --git a/maintenance/oracle/archives/patch-user_email_index.sql b/maintenance/oracle/archives/patch-user_email_index.sql new file mode 100644 index 0000000000..975943c1e2 --- /dev/null +++ b/maintenance/oracle/archives/patch-user_email_index.sql @@ -0,0 +1,4 @@ +define mw_prefix='{$wgDBprefix}'; + +CREATE INDEX &mw_prefix.mwuser_i02 ON &mw_prefix.mwuser (user_email, user_name); + diff --git a/maintenance/oracle/tables.sql b/maintenance/oracle/tables.sql index 7312bbee42..d40b102cac 100644 --- a/maintenance/oracle/tables.sql +++ b/maintenance/oracle/tables.sql @@ -23,6 +23,7 @@ CREATE TABLE &mw_prefix.mwuser ( -- replace reserved word 'user' ALTER TABLE &mw_prefix.mwuser ADD CONSTRAINT &mw_prefix.mwuser_pk PRIMARY KEY (user_id); CREATE UNIQUE INDEX &mw_prefix.mwuser_u01 ON &mw_prefix.mwuser (user_name); CREATE INDEX &mw_prefix.mwuser_i01 ON &mw_prefix.mwuser (user_email_token); +CREATE INDEX &mw_prefix.mwuser_i02 ON &mw_prefix.mwuser (user_email, user_name); -- Create a dummy user to satisfy fk contraints especially with revisions INSERT INTO &mw_prefix.mwuser @@ -47,7 +48,7 @@ CREATE INDEX &mw_prefix.user_newtalk_i02 ON &mw_prefix.user_newtalk (user_ip); CREATE TABLE &mw_prefix.user_properties ( up_user NUMBER NOT NULL, - up_property VARCHAR2(32) NOT NULL, + up_property VARCHAR2(255) NOT NULL, up_value CLOB ); CREATE UNIQUE INDEX &mw_prefix.user_properties_u01 on &mw_prefix.user_properties (up_user,up_property); @@ -636,6 +637,14 @@ CREATE TABLE &mw_prefix.module_deps ( ); CREATE UNIQUE INDEX &mw_prefix.module_deps_u01 ON &mw_prefix.module_deps (md_module, md_skin); +CREATE TABLE &mw_prefix.config ( + cf_name VARCHAR2(255) NOT NULL, + cf_value blob NOT NULL +); +ALTER TABLE &mw_prefix.config ADD CONSTRAINT &mw_prefix.config_pk PRIMARY KEY (cf_name); +-- leaving index out for now ... + + -- do not prefix this table as it breaks parserTests CREATE TABLE wiki_field_info_full ( table_name VARCHAR2(35) NOT NULL, -- 2.20.1