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);