1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Stockbase\Integration\Setup; |
4
|
|
|
|
5
|
|
|
use Magento\Framework\Setup\UpgradeSchemaInterface; |
6
|
|
|
use Magento\Framework\Setup\ModuleContextInterface; |
7
|
|
|
use Magento\Framework\Setup\SchemaSetupInterface; |
8
|
|
|
use Magento\Framework\DB\Adapter\AdapterInterface; |
9
|
|
|
use Magento\Framework\DB\Ddl\Table; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class UpgradeSchema |
13
|
|
|
*/ |
14
|
|
|
class UpgradeSchema implements UpgradeSchemaInterface |
15
|
|
|
{ |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @param SchemaSetupInterface $setup |
19
|
|
|
* @param ModuleContextInterface $context |
20
|
|
|
*/ |
21
|
|
|
public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context) |
22
|
|
|
{ |
23
|
|
|
if (version_compare($context->getVersion(), '1.1.0') < 0) { |
24
|
|
|
$tableName = $setup->getTable('stockbase_product_images'); |
25
|
|
|
if (!$setup->getConnection()->isTableExists($tableName)) { |
26
|
|
|
$table = $setup->getConnection() |
27
|
|
|
->newTable($tableName) |
28
|
|
|
->setComment('Stockbase product images') |
29
|
|
|
->addColumn( |
30
|
|
|
'id', |
31
|
|
|
Table::TYPE_BIGINT, |
32
|
|
|
null, |
33
|
|
|
['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true], |
34
|
|
|
'Image ID' |
35
|
|
|
) |
36
|
|
|
->addColumn( |
37
|
|
|
'ean', |
38
|
|
|
Table::TYPE_BIGINT, |
39
|
|
|
null, |
40
|
|
|
['identity' => false, 'unsigned' => true, 'nullable' => false], |
41
|
|
|
'International/European Article Number' |
42
|
|
|
) |
43
|
|
|
->addColumn( |
44
|
|
|
'product_id', |
45
|
|
|
Table::TYPE_BIGINT, |
46
|
|
|
null, |
47
|
|
|
['identity' => false, 'unsigned' => true, 'nullable' => false], |
48
|
|
|
'Magento Product ID' |
49
|
|
|
) |
50
|
|
|
->addColumn( |
51
|
|
|
'image', |
52
|
|
|
Table::TYPE_TEXT, |
53
|
|
|
null, |
54
|
|
|
['nullable' => false], |
55
|
|
|
'Image' |
56
|
|
|
) |
57
|
|
|
->addColumn( |
58
|
|
|
'timestamp', |
59
|
|
|
Table::TYPE_DATETIME, |
60
|
|
|
null, |
61
|
|
|
['nullable' => false], |
62
|
|
|
'Latest Sync' |
63
|
|
|
) |
64
|
|
|
->addIndex( |
65
|
|
|
$setup->getIdxName($tableName, ['product_id']), |
66
|
|
|
['product_id'], |
67
|
|
|
['type' => AdapterInterface::INDEX_TYPE_INDEX] |
68
|
|
|
) |
69
|
|
|
->addIndex( |
70
|
|
|
$setup->getIdxName($tableName, ['ean']), |
71
|
|
|
['ean'], |
72
|
|
|
['type' => AdapterInterface::INDEX_TYPE_INDEX] |
73
|
|
|
) |
74
|
|
|
->addIndex( |
75
|
|
|
$setup->getIdxName($tableName, ['timestamp']), |
76
|
|
|
['timestamp'], |
77
|
|
|
['type' => AdapterInterface::INDEX_TYPE_INDEX] |
78
|
|
|
); |
79
|
|
|
$setup->getConnection()->createTable($table); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|