Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migration Failure with MariaDB Due to ON DUPLICATE KEY UPDATE Syntax #2917

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,25 @@ class UpsertCoreEmergencyAlertInModule extends AbstractMigration
{
public function change(): void
{
// Insert or update core-emergency-alert into the module table
$this->execute('
INSERT INTO `module` (`moduleId`, `enabled`, `previewEnabled`, `defaultDuration`, `settings`)
VALUES (\'core-emergency-alert\', \'1\', \'1\', \'60\', NULL) AS newRow
ON DUPLICATE KEY UPDATE
`enabled` = newRow.enabled,
`previewEnabled` = newRow.previewEnabled,
`defaultDuration` = newRow.defaultDuration,
`settings` = newRow.settings;
');
// Check if the core-emergency-alert row exists
$row = $this->fetchRow("SELECT * FROM `module` WHERE `moduleId` = 'core-emergency-alert'");

if (!$row) {
// Row does not exist, insert new row
$this->execute("
INSERT INTO `module` (`moduleId`, `enabled`, `previewEnabled`, `defaultDuration`, `settings`)
VALUES ('core-emergency-alert', '1', '1', '60', NULL)
");
} else {
// Row exists, update existing row
$this->execute("
UPDATE `module`
SET `enabled` = '1',
`previewEnabled` = '1',
`defaultDuration` = '60',
`settings` = NULL
WHERE `moduleId` = 'core-emergency-alert'
");
}
}
}