cloudflare/Cloudflare-Magento
Publicmirrored fromhttps://github.com/cloudflare/Cloudflare-Magento
Setup/InstallSchema.php
61lines · modecode
Added Model/KeyValue.php and Model/ResourceModel/KeyValue.php so Magento will generate a Model/ResourceModel/KeyValueFactory.php to interact with our DB table.7a598ec
9 years ago
| 1 | <?php |
| 2 | |
| 3 | namespace CloudFlare\Plugin\Setup; |
| 4 | |
| 5 | use Magento\Framework\Setup\InstallSchemaInterface; |
| 6 | use Magento\Framework\Setup\ModuleContextInterface; |
| 7 | use Magento\Framework\Setup\SchemaSetupInterface; |
| 8 | use Magento\Framework\DB\Ddl\Table; |
| 9 | |
| 10 | class InstallSchema implements InstallSchemaInterface |
| 11 | { |
| 12 | const CLOUDFLARE_DATA_TABLE_NAME = "cloudflare_data"; |
| 13 | const CLOUDFLARE_DATA_TABLE_ID_COLUMN = "id"; |
| 14 | const CLOUDFLARE_DATA_TABLE_KEY_COLUMN = "key"; |
| 15 | const CLOUDFLARE_DATA_TABLE_VALUE_COLUMN = "value"; |
| 16 | |
| 17 | public function install(SchemaSetupInterface $setup, ModuleContextInterface $context) |
| 18 | { |
| 19 | $installer = $setup; |
| 20 | $installer->startSetup(); |
| 21 | |
| 22 | $tableName = $installer->getTable(self::CLOUDFLARE_DATA_TABLE_NAME); |
| 23 | |
| 24 | if ($installer->getConnection()->isTableExists($tableName) != true) { |
| 25 | $table = $installer->getConnection() |
| 26 | ->newTable($tableName) |
| 27 | ->addColumn( |
| 28 | self::CLOUDFLARE_DATA_TABLE_ID_COLUMN, |
| 29 | Table::TYPE_INTEGER, |
| 30 | null, |
| 31 | [ |
| 32 | 'identity' => true, |
| 33 | 'unsigned' => true, |
| 34 | 'nullable' => false, |
| 35 | 'primary' => true |
| 36 | ], |
| 37 | 'ID' |
| 38 | ) |
| 39 | ->addColumn( |
| 40 | self::CLOUDFLARE_DATA_TABLE_KEY_COLUMN, |
| 41 | Table::TYPE_TEXT, |
| 42 | null, |
| 43 | ['nullable' => false, 'default' => ''], |
| 44 | 'Key' |
| 45 | ) |
| 46 | ->addColumn( |
| 47 | self::CLOUDFLARE_DATA_TABLE_VALUE_COLUMN, |
| 48 | Table::TYPE_TEXT, |
| 49 | null, |
| 50 | ['nullable' => true, 'default' => ''], |
| 51 | 'Value' |
| 52 | ) |
| 53 | ->setComment('CloudFlare Key/Value Store.') |
| 54 | ->setOption('type', 'InnoDB') |
| 55 | ->setOption('charset', 'utf8'); |
| 56 | $installer->getConnection()->createTable($table); |
| 57 | } |
| 58 | |
| 59 | $installer->endSetup(); |
| 60 | } |
| 61 | } |