Skip to content

Commit 0c7b1e4

Browse files
authored
Merge pull request #810 from magento-troll/MAGETWO-63252
MAGETWO-63252: Resolve database upgrade failure from 2.1 version
2 parents 988f3a3 + 98bd0d7 commit 0c7b1e4

File tree

1 file changed

+37
-40
lines changed

1 file changed

+37
-40
lines changed

app/code/Magento/Catalog/Setup/UpgradeSchema.php

Lines changed: 37 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,8 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con
3333
$this->addUniqueKeyToCategoryProductTable($setup);
3434
}
3535

36-
if (version_compare($context->getVersion(), '2.1.0', '<')) {
36+
if (version_compare($context->getVersion(), '2.1.4', '<')) {
3737
$this->addPercentageValueColumn($setup);
38-
}
39-
40-
if (version_compare($context->getVersion(), '2.1.1', '<')) {
4138
$tables = [
4239
'catalog_product_index_price_cfg_opt_agr_idx',
4340
'catalog_product_index_price_cfg_opt_agr_tmp',
@@ -59,13 +56,7 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con
5956
['type' => 'integer', 'nullable' => false]
6057
);
6158
}
62-
}
63-
64-
if (version_compare($context->getVersion(), '2.1.2', '<')) {
6559
$this->addSourceEntityIdToProductEavIndex($setup);
66-
}
67-
68-
if (version_compare($context->getVersion(), '2.1.4', '<')) {
6960
$this->recreateCatalogCategoryProductIndexTmpTable($setup);
7061
}
7162

@@ -93,25 +84,27 @@ private function addSourceEntityIdToProductEavIndex(SchemaSetupInterface $setup)
9384
$connection = $setup->getConnection();
9485
foreach ($tables as $tableName) {
9586
$tableName = $setup->getTable($tableName);
96-
$connection->addColumn(
97-
$tableName,
98-
'source_id',
99-
[
100-
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
101-
'unsigned' => true,
102-
'nullable' => false,
103-
'default' => 0,
104-
'comment' => 'Original entity Id for attribute value',
105-
]
106-
);
107-
$connection->dropIndex($tableName, $connection->getPrimaryKeyName($tableName));
108-
$primaryKeyFields = ['entity_id', 'attribute_id', 'store_id', 'value', 'source_id'];
109-
$setup->getConnection()->addIndex(
110-
$tableName,
111-
$connection->getIndexName($tableName, $primaryKeyFields),
112-
$primaryKeyFields,
113-
\Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_PRIMARY
114-
);
87+
if (!$connection->tableColumnExists($tableName, 'source_id')) {
88+
$connection->addColumn(
89+
$tableName,
90+
'source_id',
91+
[
92+
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
93+
'unsigned' => true,
94+
'nullable' => false,
95+
'default' => 0,
96+
'comment' => 'Original entity Id for attribute value',
97+
]
98+
);
99+
$connection->dropIndex($tableName, $connection->getPrimaryKeyName($tableName));
100+
$primaryKeyFields = ['entity_id', 'attribute_id', 'store_id', 'value', 'source_id'];
101+
$setup->getConnection()->addIndex(
102+
$tableName,
103+
$connection->getIndexName($tableName, $primaryKeyFields),
104+
$primaryKeyFields,
105+
\Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_PRIMARY
106+
);
107+
}
115108
}
116109
}
117110

@@ -367,17 +360,21 @@ private function removeGroupPrice(SchemaSetupInterface $setup)
367360
private function addPercentageValueColumn(SchemaSetupInterface $setup)
368361
{
369362
$connection = $setup->getConnection();
370-
$connection->addColumn(
371-
$setup->getTable('catalog_product_entity_tier_price'),
372-
'percentage_value',
373-
[
374-
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL,
375-
'nullable' => true,
376-
'length' => '5,2',
377-
'comment' => 'Percentage value',
378-
'after' => 'value'
379-
]
380-
);
363+
$tableName = $setup->getTable('catalog_product_entity_tier_price');
364+
365+
if (!$connection->tableColumnExists($tableName, 'percentage_value')) {
366+
$connection->addColumn(
367+
$tableName,
368+
'percentage_value',
369+
[
370+
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL,
371+
'nullable' => true,
372+
'length' => '5,2',
373+
'comment' => 'Percentage value',
374+
'after' => 'value'
375+
]
376+
);
377+
}
381378
}
382379

383380
/**

0 commit comments

Comments
 (0)