File tree Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -817,6 +817,28 @@ public function declarativeInstallSchema(array $request)
817817 $ this ->getDeclarationInstaller ()->installSchema ($ request );
818818 }
819819
820+ /**
821+ * Clear memory tables
822+ *
823+ * Memory tables that used in old versions of Magento for indexing purposes should be cleaned
824+ * Otherwise some supported DB solutions like Galeracluster may have replication error
825+ * when memory engine will be switched to InnoDb
826+ *
827+ * @param SchemaSetupInterface $setup
828+ * @return void
829+ */
830+ private function cleanMemoryTables (SchemaSetupInterface $ setup )
831+ {
832+ $ connection = $ setup ->getConnection ();
833+ $ tables = $ connection ->getTables ();
834+ foreach ($ tables as $ table ) {
835+ $ tableData = $ connection ->showTableStatus ($ table );
836+ if (isset ($ tableData ['Engine ' ]) && $ tableData ['Engine ' ] === 'MEMORY ' ) {
837+ $ connection ->truncateTable ($ table );
838+ }
839+ }
840+ }
841+
820842 /**
821843 * Installs DB schema
822844 *
@@ -835,6 +857,7 @@ public function installSchema(array $request)
835857 $ setup = $ this ->setupFactory ->create ($ this ->context ->getResources ());
836858 $ this ->setupModuleRegistry ($ setup );
837859 $ this ->setupCoreTables ($ setup );
860+ $ this ->cleanMemoryTables ($ setup );
838861 $ this ->log ->log ('Schema creation/updates: ' );
839862 $ this ->declarativeInstallSchema ($ request );
840863 $ this ->handleDBSchemaData ($ setup , 'schema ' , $ request );
Original file line number Diff line number Diff line change @@ -326,9 +326,10 @@ public function testInstall(array $request, array $logMessages)
326326 $ setup = $ this ->createMock (Setup::class);
327327 $ table = $ this ->createMock (Table::class);
328328 $ connection = $ this ->getMockBuilder (AdapterInterface::class)
329- ->setMethods (['getSchemaListener ' , 'newTable ' ])
329+ ->setMethods (['getSchemaListener ' , 'newTable ' , ' getTables ' ])
330330 ->getMockForAbstractClass ();
331331 $ connection ->expects ($ this ->any ())->method ('getSchemaListener ' )->willReturn ($ this ->schemaListenerMock );
332+ $ connection ->expects ($ this ->once ())->method ('getTables ' )->willReturn ([]);
332333 $ setup ->expects ($ this ->any ())->method ('getConnection ' )->willReturn ($ connection );
333334 $ table ->expects ($ this ->any ())->method ('addColumn ' )->willReturn ($ table );
334335 $ table ->expects ($ this ->any ())->method ('setComment ' )->willReturn ($ table );
You can’t perform that action at this time.
0 commit comments