diff --git a/app/code/Magento/Catalog/Setup/UpgradeSchema.php b/app/code/Magento/Catalog/Setup/UpgradeSchema.php index 1be49fc30e4ef..db0aaa3a010e3 100755 --- a/app/code/Magento/Catalog/Setup/UpgradeSchema.php +++ b/app/code/Magento/Catalog/Setup/UpgradeSchema.php @@ -33,11 +33,8 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con $this->addUniqueKeyToCategoryProductTable($setup); } - if (version_compare($context->getVersion(), '2.1.0', '<')) { + if (version_compare($context->getVersion(), '2.1.4', '<')) { $this->addPercentageValueColumn($setup); - } - - if (version_compare($context->getVersion(), '2.1.1', '<')) { $tables = [ 'catalog_product_index_price_cfg_opt_agr_idx', 'catalog_product_index_price_cfg_opt_agr_tmp', @@ -59,13 +56,7 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con ['type' => 'integer', 'nullable' => false] ); } - } - - if (version_compare($context->getVersion(), '2.1.2', '<')) { $this->addSourceEntityIdToProductEavIndex($setup); - } - - if (version_compare($context->getVersion(), '2.1.4', '<')) { $this->recreateCatalogCategoryProductIndexTmpTable($setup); } @@ -93,25 +84,27 @@ private function addSourceEntityIdToProductEavIndex(SchemaSetupInterface $setup) $connection = $setup->getConnection(); foreach ($tables as $tableName) { $tableName = $setup->getTable($tableName); - $connection->addColumn( - $tableName, - 'source_id', - [ - 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - 'unsigned' => true, - 'nullable' => false, - 'default' => 0, - 'comment' => 'Original entity Id for attribute value', - ] - ); - $connection->dropIndex($tableName, $connection->getPrimaryKeyName($tableName)); - $primaryKeyFields = ['entity_id', 'attribute_id', 'store_id', 'value', 'source_id']; - $setup->getConnection()->addIndex( - $tableName, - $connection->getIndexName($tableName, $primaryKeyFields), - $primaryKeyFields, - \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_PRIMARY - ); + if (!$connection->tableColumnExists($tableName, 'source_id')) { + $connection->addColumn( + $tableName, + 'source_id', + [ + 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + 'unsigned' => true, + 'nullable' => false, + 'default' => 0, + 'comment' => 'Original entity Id for attribute value', + ] + ); + $connection->dropIndex($tableName, $connection->getPrimaryKeyName($tableName)); + $primaryKeyFields = ['entity_id', 'attribute_id', 'store_id', 'value', 'source_id']; + $setup->getConnection()->addIndex( + $tableName, + $connection->getIndexName($tableName, $primaryKeyFields), + $primaryKeyFields, + \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_PRIMARY + ); + } } } @@ -367,17 +360,21 @@ private function removeGroupPrice(SchemaSetupInterface $setup) private function addPercentageValueColumn(SchemaSetupInterface $setup) { $connection = $setup->getConnection(); - $connection->addColumn( - $setup->getTable('catalog_product_entity_tier_price'), - 'percentage_value', - [ - 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, - 'nullable' => true, - 'length' => '5,2', - 'comment' => 'Percentage value', - 'after' => 'value' - ] - ); + $tableName = $setup->getTable('catalog_product_entity_tier_price'); + + if (!$connection->tableColumnExists($tableName, 'percentage_value')) { + $connection->addColumn( + $tableName, + 'percentage_value', + [ + 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, + 'nullable' => true, + 'length' => '5,2', + 'comment' => 'Percentage value', + 'after' => 'value' + ] + ); + } } /**