Skip to content

Commit e73e327

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

File tree

2 files changed

+14
-30
lines changed

2 files changed

+14
-30
lines changed

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,11 @@ 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+
254259
/**
255260
* Constructor
256261
*
@@ -3070,6 +3075,11 @@ public function startSetup()
30703075
$this->rawQuery("SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0");
30713076
$this->rawQuery("SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO'");
30723077

3078+
$version = $this->fetchPairs("SHOW variables LIKE 'version'")['version'] ?? '';
3079+
if (str_contains($version, '8.4')) {
3080+
$this->rawQuery("SET @OLD_RESTRICT_FK_ON_NON_STANDARD_KEY=@@RESTRICT_FK_ON_NON_STANDARD_KEY");
3081+
$this->rawQuery("SET RESTRICT_FK_ON_NON_STANDARD_KEY=0");
3082+
}
30733083
return $this;
30743084
}
30753085

@@ -3082,7 +3092,10 @@ public function endSetup()
30823092
{
30833093
$this->rawQuery("SET SQL_MODE=IFNULL(@OLD_SQL_MODE,'')");
30843094
$this->rawQuery("SET FOREIGN_KEY_CHECKS=IF(@OLD_FOREIGN_KEY_CHECKS=0, 0, 1)");
3085-
3095+
$version = $this->fetchPairs("SHOW variables LIKE 'version'")['version'] ?? '';
3096+
if (str_contains($version, '8.4')) {
3097+
$this->rawQuery("SET RESTRICT_FK_ON_NON_STANDARD_KEY=IF(@OLD_RESTRICT_FK_ON_NON_STANDARD_KEY=0, 0, 1)");
3098+
}
30863099
return $this;
30873100
}
30883101

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

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -911,12 +911,10 @@ 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);
915914
$this->cleanMemoryTables($setup);
916915
$this->log->logMeta('Schema creation/updates:');
917916
$this->declarativeInstallSchema($request);
918917
$this->handleDBSchemaData($setup, 'schema', $request);
919-
$this->revertRestrictFKOnNonStandardKey($setup);
920918
/** @var Mysql $adapter */
921919
$adapter = $setup->getConnection();
922920
$schemaListener = $adapter->getSchemaListener();
@@ -1829,31 +1827,4 @@ private function setIndexerModeSchedule(): void
18291827
$this->log->log(__("We couldn't change indexer(s)' mode because of an error: ".$e->getMessage()));
18301828
}
18311829
}
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-
}
18591830
}

0 commit comments

Comments
 (0)