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 fcc46964c1)
This commit is contained in:
Umherirrender 2022-11-29 21:54:43 +01:00 committed by Gergő Tisza
parent 65786cd308
commit 8f0ec57ddd
8 changed files with 58 additions and 12 deletions

View file

@ -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" );
}

View file

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

View file

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

View file

@ -0,0 +1,2 @@
-- Rename index to match table prefix - T306473
CREATE INDEX /*i*/eps_token ON /*_*/echo_push_subscription (eps_token(10));

View file

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

View file

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

View file

@ -0,0 +1,2 @@
-- Rename index to match table prefix - T306473
DROP INDEX /*i*/echo_push_subscription_token ON /*_*/echo_push_subscription;

View file

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