@@ -65,6 +65,10 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con
65
65
$ this ->addSourceEntityIdToProductEavIndex ($ setup );
66
66
}
67
67
68
+ if (version_compare ($ context ->getVersion (), '2.1.4 ' , '< ' )) {
69
+ $ this ->recreateCatalogCategoryProductIndexTmpTable ($ setup );
70
+ }
71
+
68
72
$ setup ->endSetup ();
69
73
}
70
74
@@ -375,4 +379,74 @@ private function addPercentageValueColumn(SchemaSetupInterface $setup)
375
379
]
376
380
);
377
381
}
382
+
383
+ /**
384
+ * Drop and recreate catalog_category_product_index_tmp table
385
+ *
386
+ * Before this update the catalog_category_product_index_tmp table was created without usage of PK
387
+ * and with engine=MEMORY. Such structure of catalog_category_product_index_tmp table causes
388
+ * issues with MySQL DB replication.
389
+ *
390
+ * To avoid replication issues this method drops catalog_category_product_index_tmp table
391
+ * and creates new one with PK and engine=InnoDB
392
+ *
393
+ * @param SchemaSetupInterface $setup
394
+ * @return void
395
+ */
396
+ private function recreateCatalogCategoryProductIndexTmpTable (SchemaSetupInterface $ setup )
397
+ {
398
+ $ tableName = $ setup ->getTable ('catalog_category_product_index_tmp ' );
399
+
400
+ // Drop catalog_category_product_index_tmp table
401
+ $ setup ->getConnection ()->dropTable ($ tableName );
402
+
403
+ // Create catalog_category_product_index_tmp table with PK and engine=InnoDB
404
+ $ table = $ setup ->getConnection ()
405
+ ->newTable ($ tableName )
406
+ ->addColumn (
407
+ 'category_id ' ,
408
+ \Magento \Framework \DB \Ddl \Table::TYPE_INTEGER ,
409
+ null ,
410
+ ['unsigned ' => true , 'nullable ' => false , 'primary ' => true , 'default ' => '0 ' ],
411
+ 'Category ID '
412
+ )
413
+ ->addColumn (
414
+ 'product_id ' ,
415
+ \Magento \Framework \DB \Ddl \Table::TYPE_INTEGER ,
416
+ null ,
417
+ ['unsigned ' => true , 'nullable ' => false , 'primary ' => true , 'default ' => '0 ' ],
418
+ 'Product ID '
419
+ )
420
+ ->addColumn (
421
+ 'position ' ,
422
+ \Magento \Framework \DB \Ddl \Table::TYPE_INTEGER ,
423
+ null ,
424
+ ['nullable ' => false , 'default ' => '0 ' ],
425
+ 'Position '
426
+ )
427
+ ->addColumn (
428
+ 'is_parent ' ,
429
+ \Magento \Framework \DB \Ddl \Table::TYPE_SMALLINT ,
430
+ null ,
431
+ ['unsigned ' => true , 'nullable ' => false , 'default ' => '0 ' ],
432
+ 'Is Parent '
433
+ )
434
+ ->addColumn (
435
+ 'store_id ' ,
436
+ \Magento \Framework \DB \Ddl \Table::TYPE_SMALLINT ,
437
+ null ,
438
+ ['unsigned ' => true , 'nullable ' => false , 'primary ' => true , 'default ' => '0 ' ],
439
+ 'Store ID '
440
+ )
441
+ ->addColumn (
442
+ 'visibility ' ,
443
+ \Magento \Framework \DB \Ddl \Table::TYPE_SMALLINT ,
444
+ null ,
445
+ ['unsigned ' => true , 'nullable ' => false ],
446
+ 'Visibility '
447
+ )
448
+ ->setComment ('Catalog Category Product Indexer temporary table ' );
449
+
450
+ $ setup ->getConnection ()->createTable ($ table );
451
+ }
378
452
}
0 commit comments