From ace56a46100ac6b939325ab6f9f1c955805efa95 Mon Sep 17 00:00:00 2001 From: Jure Kajzer Date: Wed, 22 Jun 2011 14:10:55 +0000 Subject: [PATCH] * removed DEFAULT '' NOT NULL constraints as '' is internaly converted to NULL in Oracle and throws an error * fixed tableName handling doSchemaUpgrade17 (must be careful to avoid multiple tableName calls as names don't get taged in DDL mode) * exit/reenter DDL mode on updatelog inserts --- includes/installer/DatabaseUpdater.php | 4 ++++ includes/installer/OracleUpdater.php | 17 ++++++++++++++++- .../patch_remove_not_null_empty_defs.sql | 9 +++++++++ maintenance/oracle/tables.sql | 16 ++++++++-------- 4 files changed, 37 insertions(+), 9 deletions(-) create mode 100644 maintenance/oracle/archives/patch_remove_not_null_empty_defs.sql diff --git a/includes/installer/DatabaseUpdater.php b/includes/installer/DatabaseUpdater.php index a369df0695..c5190879bc 100644 --- a/includes/installer/DatabaseUpdater.php +++ b/includes/installer/DatabaseUpdater.php @@ -232,6 +232,7 @@ abstract class DatabaseUpdater { } protected function setAppliedUpdates( $version, $updates = array() ) { + $this->db->clearFlag( DBO_DDLMODE ); if( !$this->canUseNewUpdatelog() ) { return; } @@ -239,6 +240,7 @@ abstract class DatabaseUpdater { $this->db->insert( 'updatelog', array( 'ul_key' => $key, 'ul_value' => serialize( $updates ) ), __METHOD__ ); + $this->db->setFlag( DBO_DDLMODE ); } /** @@ -265,11 +267,13 @@ abstract class DatabaseUpdater { * @param $val String [optional] value to insert along with the key */ public function insertUpdateRow( $key, $val = null ) { + $this->db->clearFlag( DBO_DDLMODE ); $values = array( 'ul_key' => $key ); if( $val && $this->canUseNewUpdatelog() ) { $values['ul_value'] = $val; } $this->db->insert( 'updatelog', $values, __METHOD__, 'IGNORE' ); + $this->db->setFlag( DBO_DDLMODE ); } /** diff --git a/includes/installer/OracleUpdater.php b/includes/installer/OracleUpdater.php index 2bf0266ba7..dd0f1d5e2f 100644 --- a/includes/installer/OracleUpdater.php +++ b/includes/installer/OracleUpdater.php @@ -29,6 +29,7 @@ class OracleUpdater extends DatabaseUpdater { array( 'doFunctions17' ), array( 'doSchemaUpgrade17' ), array( 'doInsertPage0' ), + array( 'doRemoveNotNullEmptyDefaults' ), //1.18 array( 'addIndex', 'user', 'i02', 'patch-user_email_index.sql' ), @@ -93,7 +94,7 @@ class OracleUpdater extends DatabaseUpdater { protected function doSchemaUpgrade17() { $this->output( "Updating schema to 17 ... " ); // check if iwlinks table exists which was added in 1.17 - if ( $this->db->tableExists( $this->db->tableName( 'iwlinks' ) ) ) { + if ( $this->db->tableExists( 'iwlinks' ) ) { $this->output( "schema seem to be up to date.\n" ); return; } @@ -122,6 +123,20 @@ class OracleUpdater extends DatabaseUpdater { $this->output( "ok\n" ); } + /** + * Remove DEFAULT '' NOT NULL constraints from fields as '' is internally + * converted to NULL in Oracle + */ + protected function doRemoveNotNullEmptyDefaults() { + $this->output( "Removing not null empty constraints ... " ); + $meta = $this->db->fieldInfo( 'categorylinks' , 'cl_sortkey_prefix' ); + if ( $meta->isNullable() ) { + $this->output( "constraints seem to be removed\n" ); + return; + } + $this->applyPatch( 'patch_remove_not_null_empty_defs.sql', false ); + $this->output( "ok\n" ); + } /** * rebuilding of the function that duplicates tables for tests diff --git a/maintenance/oracle/archives/patch_remove_not_null_empty_defs.sql b/maintenance/oracle/archives/patch_remove_not_null_empty_defs.sql new file mode 100644 index 0000000000..76e50a0a93 --- /dev/null +++ b/maintenance/oracle/archives/patch_remove_not_null_empty_defs.sql @@ -0,0 +1,9 @@ +define mw_prefix='{$wgDBprefix}'; + +ALTER TABLE &mw_prefix.categorylinks MODIFY cl_sortkey_prefix DEFAULT NULL NULL; +ALTER TABLE &mw_prefix.categorylinks MODIFY cl_collation DEFAULT NULL NULL; +ALTER TABLE &mw_prefix.iwlinks MODIFY iwl_prefix DEFAULT NULL NULL; +ALTER TABLE &mw_prefix.iwlinks MODIFY iwl_title DEFAULT NULL NULL; +ALTER TABLE &mw_prefix.searchindex MODIFY si_title DEFAULT NULL NULL; +ALTER TABLE &mw_prefix.querycachetwo MODIFY qcc_title DEFAULT NULL NULL; +ALTER TABLE &mw_prefix.querycachetwo MODIFY qcc_titletwo DEFAULT NULL NULL; diff --git a/maintenance/oracle/tables.sql b/maintenance/oracle/tables.sql index 54bafd0a86..2fd62ef7e6 100644 --- a/maintenance/oracle/tables.sql +++ b/maintenance/oracle/tables.sql @@ -27,7 +27,7 @@ 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 - VALUES (user_user_id_seq.nextval,'Anonymous','',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, '', current_timestamp, current_timestamp, 0); + VALUES (user_user_id_seq.nextval,'Anonymous',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, '', current_timestamp, current_timestamp, 0); CREATE TABLE &mw_prefix.user_groups ( ug_user NUMBER DEFAULT 0 NOT NULL, @@ -169,9 +169,9 @@ CREATE TABLE &mw_prefix.categorylinks ( cl_from NUMBER NOT NULL, cl_to VARCHAR2(255) NOT NULL, cl_sortkey VARCHAR2(230), - cl_sortkey_prefix VARCHAR2(255) DEFAULT '' NOT NULL, + cl_sortkey_prefix VARCHAR2(255), cl_timestamp TIMESTAMP(6) WITH TIME ZONE NOT NULL, - cl_collation VARCHAR2(32) DEFAULT '' NOT NULL, + cl_collation VARCHAR2(32), cl_type VARCHAR2(6) DEFAULT 'page' NOT NULL ); ALTER TABLE &mw_prefix.categorylinks ADD CONSTRAINT &mw_prefix.categorylinks_fk1 FOREIGN KEY (cl_from) REFERENCES &mw_prefix.page(page_id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; @@ -221,8 +221,8 @@ CREATE INDEX &mw_prefix.langlinks_i01 ON &mw_prefix.langlinks (ll_lang, ll_title CREATE TABLE &mw_prefix.iwlinks ( iwl_from NUMBER DEFAULT 0 NOT NULL, - iwl_prefix VARCHAR2(20) DEFAULT '' NOT NULL, - iwl_title VARCHAR2(255) DEFAULT '' NOT NULL + iwl_prefix VARCHAR2(20), + iwl_title VARCHAR2(255) ); CREATE UNIQUE INDEX &mw_prefix.iwlinks_ui01 ON &mw_prefix.iwlinks (iwl_from, iwl_prefix, iwl_title); CREATE UNIQUE INDEX &mw_prefix.iwlinks_ui02 ON &mw_prefix.iwlinks (iwl_prefix, iwl_title, iwl_from); @@ -408,7 +408,7 @@ CREATE INDEX &mw_prefix.watchlist_i01 ON &mw_prefix.watchlist (wl_namespace, wl_ CREATE TABLE &mw_prefix.searchindex ( si_page NUMBER NOT NULL, - si_title VARCHAR2(255) DEFAULT '' NOT NULL, + si_title VARCHAR2(255), si_text CLOB NOT NULL ); CREATE UNIQUE INDEX &mw_prefix.searchindex_u01 ON &mw_prefix.searchindex (si_page); @@ -520,9 +520,9 @@ CREATE TABLE &mw_prefix.querycachetwo ( qcc_type VARCHAR2(32) NOT NULL, qcc_value NUMBER DEFAULT 0 NOT NULL, qcc_namespace NUMBER DEFAULT 0 NOT NULL, - qcc_title VARCHAR2(255) DEFAULT '' NOT NULL, + qcc_title VARCHAR2(255), qcc_namespacetwo NUMBER DEFAULT 0 NOT NULL, - qcc_titletwo VARCHAR2(255) DEFAULT '' NOT NULL + qcc_titletwo VARCHAR2(255) ); CREATE INDEX &mw_prefix.querycachetwo_i01 ON &mw_prefix.querycachetwo (qcc_type,qcc_value); CREATE INDEX &mw_prefix.querycachetwo_i02 ON &mw_prefix.querycachetwo (qcc_type,qcc_namespace,qcc_title); -- 2.20.1