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