From 8f0ec57ddd73420ab5269bd9da0ff2133e90585f Mon Sep 17 00:00:00 2001 From: Umherirrender Date: Tue, 29 Nov 2022 21:54:43 +0100 Subject: [PATCH] schema: Run cleanup updates for echo_push_subscription separately The addition of the foreign key echo_push_subscription_ibfk_2 in 4abfbd3 did not affected already existing installs, because the updater part was missing. The addition of a foreign key also creates an index under mysql, which is also not part of older installs and needs to be created. Also the new field eps_topic from c188dac is missing and now added. The new index echo_push_subscription_token from 3513c64 is added. The drop patch set d35c502 assumes that the foreign key exists, now every step of the update is running separately to avoid one failing update to skip the remaing update steps. This avoid issues on wikis installed before REL1_35 and updated with the patches from REL1_36 Bug: T322143 Change-Id: I0759b82ad91849880c784e412e04dd53f26df6a2 (cherry picked from commit fcc46964c1012e82bb6cd0559fefcc3e1a07719c) --- includes/Hooks.php | 46 ++++++++++++++++++- ...push_subscription-foreign-keys-indexes.sql | 10 ---- ...push_subscription-add-column-eps_topic.sql | 3 ++ ...sh_subscription-create-index-eps_token.sql | 2 + ..._push_subscription-drop-foreign-keys_1.sql | 2 + ..._push_subscription-drop-foreign-keys_2.sql | 2 + ...push_subscription-drop-index-eps_token.sql | 2 + ...ush_subscription-rename-index-eps_user.sql | 3 ++ 8 files changed, 58 insertions(+), 12 deletions(-) delete mode 100644 sql/mysql/patch-cleanup-push_subscription-foreign-keys-indexes.sql create mode 100644 sql/mysql/patch-echo_push_subscription-add-column-eps_topic.sql create mode 100644 sql/mysql/patch-echo_push_subscription-create-index-eps_token.sql create mode 100644 sql/mysql/patch-echo_push_subscription-drop-foreign-keys_1.sql create mode 100644 sql/mysql/patch-echo_push_subscription-drop-foreign-keys_2.sql create mode 100644 sql/mysql/patch-echo_push_subscription-drop-index-eps_token.sql create mode 100644 sql/mysql/patch-echo_push_subscription-rename-index-eps_user.sql diff --git a/includes/Hooks.php b/includes/Hooks.php index a9de26168..d36392079 100644 --- a/includes/Hooks.php +++ b/includes/Hooks.php @@ -211,7 +211,8 @@ class Hooks implements RecentChange_saveHook { return; } - $dbType = $updater->getDB()->getType(); + $db = $updater->getDB(); + $dbType = $db->getType(); $dir = dirname( __DIR__ ) . '/sql'; @@ -243,7 +244,48 @@ class Hooks implements RecentChange_saveHook { $updater->addExtensionTable( 'echo_push_topic', "$dir/echo_push_topic.sql" ); // 1.39 - if ( $dbType === 'mysql' || $dbType === 'sqlite' ) { + if ( $dbType === 'mysql' && $db->tableExists( 'echo_push_subscription', __METHOD__ ) ) { + // Splitted into single steps to support updates from some releases as well - T322143 + $updater->renameExtensionIndex( + 'echo_push_subscription', + 'echo_push_subscription_user_id', + 'eps_user', + "$dir/$dbType/patch-echo_push_subscription-rename-index-eps_user.sql", + false + ); + $updater->dropExtensionIndex( + 'echo_push_subscription', + 'echo_push_subscription_token', + "$dir/$dbType/patch-echo_push_subscription-drop-index-eps_token.sql" + ); + $updater->addExtensionIndex( + 'echo_push_subscription', + 'eps_token', + "$dir/$dbType/patch-echo_push_subscription-create-index-eps_token.sql" + ); + $updater->addExtensionField( + 'echo_push_subscription', + 'eps_topic', + "$dir/$dbType/patch-echo_push_subscription-add-column-eps_topic.sql" + ); + + $res = $db->query( 'SHOW CREATE TABLE ' . $db->tableName( 'echo_push_subscription' ), __METHOD__ ); + $row = $res ? $res->fetchRow() : false; + $statement = $row ? $row[1] : ''; + if ( str_contains( $statement, $db->addIdentifierQuotes( 'echo_push_subscription_ibfk_1' ) ) ) { + $updater->modifyExtensionTable( + 'echo_push_subscription', + "$dir/$dbType/patch-echo_push_subscription-drop-foreign-keys_1.sql" + ); + } + if ( str_contains( $statement, $db->addIdentifierQuotes( 'echo_push_subscription_ibfk_2' ) ) ) { + $updater->modifyExtensionTable( + 'echo_push_subscription', + "$dir/$dbType/patch-echo_push_subscription-drop-foreign-keys_2.sql" + ); + } + } + if ( $dbType === 'sqlite' ) { $updater->addExtensionIndex( 'echo_push_subscription', 'eps_user', "$dir/$dbType/patch-cleanup-push_subscription-foreign-keys-indexes.sql" ); } diff --git a/sql/mysql/patch-cleanup-push_subscription-foreign-keys-indexes.sql b/sql/mysql/patch-cleanup-push_subscription-foreign-keys-indexes.sql deleted file mode 100644 index d6fa63fb4..000000000 --- a/sql/mysql/patch-cleanup-push_subscription-foreign-keys-indexes.sql +++ /dev/null @@ -1,10 +0,0 @@ --- Drop foreign keys from echo_push_subscription - T306473 -ALTER TABLE /*_*/echo_push_subscription DROP FOREIGN KEY /*_*/echo_push_subscription_ibfk_1; -ALTER TABLE /*_*/echo_push_subscription DROP FOREIGN KEY /*_*/echo_push_subscription_ibfk_2; - --- Rename index to match table prefix -DROP INDEX /*i*/echo_push_subscription_user_id ON /*_*/echo_push_subscription; -CREATE INDEX /*i*/eps_user ON /*_*/echo_push_subscription (eps_user); - -DROP INDEX /*i*/echo_push_subscription_token ON /*_*/echo_push_subscription; -CREATE INDEX /*i*/eps_token ON /*_*/echo_push_subscription (eps_token(10)); diff --git a/sql/mysql/patch-echo_push_subscription-add-column-eps_topic.sql b/sql/mysql/patch-echo_push_subscription-add-column-eps_topic.sql new file mode 100644 index 000000000..98b81291f --- /dev/null +++ b/sql/mysql/patch-echo_push_subscription-add-column-eps_topic.sql @@ -0,0 +1,3 @@ +ALTER TABLE echo_push_subscription +ADD COLUMN eps_topic TINYINT UNSIGNED; +CREATE INDEX /*i*/eps_topic ON /*_*/echo_push_subscription (eps_topic); diff --git a/sql/mysql/patch-echo_push_subscription-create-index-eps_token.sql b/sql/mysql/patch-echo_push_subscription-create-index-eps_token.sql new file mode 100644 index 000000000..34d0f2687 --- /dev/null +++ b/sql/mysql/patch-echo_push_subscription-create-index-eps_token.sql @@ -0,0 +1,2 @@ +-- Rename index to match table prefix - T306473 +CREATE INDEX /*i*/eps_token ON /*_*/echo_push_subscription (eps_token(10)); diff --git a/sql/mysql/patch-echo_push_subscription-drop-foreign-keys_1.sql b/sql/mysql/patch-echo_push_subscription-drop-foreign-keys_1.sql new file mode 100644 index 000000000..dca6b6091 --- /dev/null +++ b/sql/mysql/patch-echo_push_subscription-drop-foreign-keys_1.sql @@ -0,0 +1,2 @@ +-- Drop foreign keys from echo_push_subscription - T306473 +ALTER TABLE /*_*/echo_push_subscription DROP FOREIGN KEY /*_*/echo_push_subscription_ibfk_1; diff --git a/sql/mysql/patch-echo_push_subscription-drop-foreign-keys_2.sql b/sql/mysql/patch-echo_push_subscription-drop-foreign-keys_2.sql new file mode 100644 index 000000000..ba854360f --- /dev/null +++ b/sql/mysql/patch-echo_push_subscription-drop-foreign-keys_2.sql @@ -0,0 +1,2 @@ +-- Drop foreign keys from echo_push_subscription - T306473 / T322143 +ALTER TABLE /*_*/echo_push_subscription DROP FOREIGN KEY /*_*/echo_push_subscription_ibfk_2; diff --git a/sql/mysql/patch-echo_push_subscription-drop-index-eps_token.sql b/sql/mysql/patch-echo_push_subscription-drop-index-eps_token.sql new file mode 100644 index 000000000..dfb1ba735 --- /dev/null +++ b/sql/mysql/patch-echo_push_subscription-drop-index-eps_token.sql @@ -0,0 +1,2 @@ +-- Rename index to match table prefix - T306473 +DROP INDEX /*i*/echo_push_subscription_token ON /*_*/echo_push_subscription; diff --git a/sql/mysql/patch-echo_push_subscription-rename-index-eps_user.sql b/sql/mysql/patch-echo_push_subscription-rename-index-eps_user.sql new file mode 100644 index 000000000..c23794dc8 --- /dev/null +++ b/sql/mysql/patch-echo_push_subscription-rename-index-eps_user.sql @@ -0,0 +1,3 @@ +-- Rename index to match table prefix - T306473 +DROP INDEX /*i*/echo_push_subscription_user_id ON /*_*/echo_push_subscription; +CREATE INDEX /*i*/eps_user ON /*_*/echo_push_subscription (eps_user);