Skip to content

Commit 2cc9025

Browse files
committed
AC-11995:Add compatibility with MySQL 8.4 LTS for Magento CE
1 parent 0b49409 commit 2cc9025

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

lib/internal/Magento/Framework/DB/Adapter/Pdo/Mysql.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -251,11 +251,6 @@ class Mysql extends \Zend_Db_Adapter_Pdo_Mysql implements AdapterInterface, Rese
251251
*/
252252
private $parentConnections = [];
253253

254-
/***
255-
* const MYSQL_8_4_VERSION
256-
*/
257-
public const MYSQL_8_4_VERSION = '8.4';
258-
259254
/**
260255
* Constructor
261256
*
@@ -3075,10 +3070,6 @@ public function startSetup()
30753070
$this->rawQuery("SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0");
30763071
$this->rawQuery("SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO'");
30773072

3078-
$version = $this->fetchPairs("SHOW variables LIKE 'version'")['version'] ?? '';
3079-
if (str_contains($version, self::MYSQL_8_4_VERSION)) {
3080-
$this->rawQuery("SET RESTRICT_FK_ON_NON_STANDARD_KEY=0");
3081-
}
30823073
return $this;
30833074
}
30843075

setup/src/Magento/Setup/Model/Installer.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -911,10 +911,12 @@ public function installSchema(array $request)
911911
$setup = $this->setupFactory->create($this->context->getResources());
912912
$this->setupModuleRegistry($setup);
913913
$this->setupCoreTables($setup);
914+
$this->disableRestrictFKOnNonStandardKey($setup);
914915
$this->cleanMemoryTables($setup);
915916
$this->log->logMeta('Schema creation/updates:');
916917
$this->declarativeInstallSchema($request);
917918
$this->handleDBSchemaData($setup, 'schema', $request);
919+
$this->revertRestrictFKOnNonStandardKey($setup);
918920
/** @var Mysql $adapter */
919921
$adapter = $setup->getConnection();
920922
$schemaListener = $adapter->getSchemaListener();
@@ -1827,4 +1829,31 @@ private function setIndexerModeSchedule(): void
18271829
$this->log->log(__("We couldn't change indexer(s)' mode because of an error: ".$e->getMessage()));
18281830
}
18291831
}
1832+
1833+
/***
1834+
* use of non-unique or partial keys as foreign keys is deprecated in MySQL8.4
1835+
*
1836+
* @param $setup
1837+
* @return void
1838+
*/
1839+
private function disableRestrictFKOnNonStandardKey($setup): void
1840+
{
1841+
$setup->getConnection()->query("
1842+
SET @OLD_RESTRICT_FK_ON_NON_STANDARD_KEY=RESTRICT_FK_ON_NON_STANDARD_KEY,
1843+
RESTRICT_FK_ON_NON_STANDARD_KEY=0
1844+
");
1845+
}
1846+
1847+
/***
1848+
* revert RESTRICT_FK_ON_NON_STANDARD_KEY to previous saved db value
1849+
*
1850+
* @param $setup
1851+
* @return void
1852+
*/
1853+
private function revertRestrictFKOnNonStandardKey($setup): void
1854+
{
1855+
$setup->getConnection()->query("
1856+
SET RESTRICT_FK_ON_NON_STANDARD_KEY=IF(@OLD_RESTRICT_FK_ON_NON_STANDARD_KEY=0, 0, 1)"
1857+
);
1858+
}
18301859
}

0 commit comments

Comments
 (0)