@@ -910,10 +910,16 @@ public function installSchema(array $request)
910
910
$ this ->assertDbAccessible ();
911
911
$ setup = $ this ->setupFactory ->create ($ this ->context ->getResources ());
912
912
$ this ->setupModuleRegistry ($ setup );
913
+
914
+ $ this ->disableRestrictFKOnNonStandardKey ($ setup );
915
+
913
916
$ this ->setupCoreTables ($ setup );
914
917
$ this ->cleanMemoryTables ($ setup );
915
918
$ this ->log ->logMeta ('Schema creation/updates: ' );
916
919
$ this ->declarativeInstallSchema ($ request );
920
+
921
+ $ this ->revertRestrictFKOnNonStandardKey ($ setup );
922
+
917
923
$ this ->handleDBSchemaData ($ setup , 'schema ' , $ request );
918
924
/** @var Mysql $adapter */
919
925
$ adapter = $ setup ->getConnection ();
@@ -1827,4 +1833,31 @@ private function setIndexerModeSchedule(): void
1827
1833
$ this ->log ->log (__ ("We couldn't change indexer(s)' mode because of an error: " .$ e ->getMessage ()));
1828
1834
}
1829
1835
}
1836
+
1837
+ /***
1838
+ * use of non-unique or partial keys as foreign keys is deprecated in MySQL8.4
1839
+ *
1840
+ * @param $setup
1841
+ * @return void
1842
+ */
1843
+ private function disableRestrictFKOnNonStandardKey ($ setup ): void
1844
+ {
1845
+ $ setup ->getConnection ()->query ("
1846
+ SET @OLD_RESTRICT_FK_ON_NON_STANDARD_KEY=@@GLOBAL.RESTRICT_FK_ON_NON_STANDARD_KEY,
1847
+ @@GLOBAL.RESTRICT_FK_ON_NON_STANDARD_KEY=0
1848
+ " );
1849
+ }
1850
+
1851
+ /***
1852
+ * revert RESTRICT_FK_ON_NON_STANDARD_KEY to previous saved db value
1853
+ *
1854
+ * @param $setup
1855
+ * @return void
1856
+ */
1857
+ private function revertRestrictFKOnNonStandardKey ($ setup ): void
1858
+ {
1859
+ $ setup ->getConnection ()->query ("
1860
+ SET @@GLOBAL.RESTRICT_FK_ON_NON_STANDARD_KEY=IF(@OLD_RESTRICT_FK_ON_NON_STANDARD_KEY=0, 0, 1) "
1861
+ );
1862
+ }
1830
1863
}
0 commit comments