Skip to content

Commit

Permalink
Merge pull request #810 from magento-troll/MAGETWO-63252
Browse files Browse the repository at this point in the history
MAGETWO-63252: Resolve database upgrade failure from 2.1 version
  • Loading branch information
rganin authored Feb 9, 2017
2 parents 988f3a3 + 98bd0d7 commit 0c7b1e4
Showing 1 changed file with 37 additions and 40 deletions.
77 changes: 37 additions & 40 deletions app/code/Magento/Catalog/Setup/UpgradeSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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);
}

Expand Down Expand Up @@ -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
);
}
}
}

Expand Down Expand Up @@ -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'
]
);
}
}

/**
Expand Down

0 comments on commit 0c7b1e4

Please sign in to comment.