|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | + |
| 7 | +namespace Magento\TestSetupModule1\Setup; |
| 8 | + |
| 9 | +use Magento\Framework\Setup\InstallSchemaInterface; |
| 10 | +use Magento\Framework\Setup\ModuleContextInterface; |
| 11 | +use Magento\Framework\Setup\SchemaSetupInterface; |
| 12 | + |
| 13 | +/** |
| 14 | + * @codeCoverageIgnore |
| 15 | + */ |
| 16 | +class InstallSchema implements InstallSchemaInterface |
| 17 | +{ |
| 18 | + /** |
| 19 | + * {@inheritdoc} |
| 20 | + * @SuppressWarnings(PHPMD.ExcessiveMethodLength) |
| 21 | + */ |
| 22 | + public function install(SchemaSetupInterface $setup, ModuleContextInterface $context) |
| 23 | + { |
| 24 | + $installer = $setup; |
| 25 | + |
| 26 | + $installer->startSetup(); |
| 27 | + |
| 28 | + /** |
| 29 | + * Create table 'setup_table1' |
| 30 | + */ |
| 31 | + $table = $installer->getConnection()->newTable( |
| 32 | + $installer->getTable('setup_tests_table1') |
| 33 | + )->addColumn( |
| 34 | + 'column_with_type_boolean', |
| 35 | + \Magento\Framework\DB\Ddl\Table::TYPE_BOOLEAN, |
| 36 | + null, |
| 37 | + ['nullable' => false, 'default' => 0], |
| 38 | + 'Column with type boolean' |
| 39 | + )->addColumn( |
| 40 | + 'column_with_type_smallint', |
| 41 | + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, |
| 42 | + null, |
| 43 | + ['unsigned' => true, 'nullable' => false, 'default' => '0'], |
| 44 | + 'Column with type smallint' |
| 45 | + )->addColumn( |
| 46 | + 'column_with_type_integer', |
| 47 | + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, |
| 48 | + null, |
| 49 | + ['unsigned' => true, 'identity' => true, 'nullable' => false, 'primary' => true], |
| 50 | + 'Column with type integer' |
| 51 | + )->addColumn( |
| 52 | + 'column_with_type_bigint', |
| 53 | + \Magento\Framework\DB\Ddl\Table::TYPE_BIGINT, |
| 54 | + null, |
| 55 | + ['unsigned' => true, 'nullable' => false, 'primary' => true], |
| 56 | + 'Column with type bigint' |
| 57 | + )->addColumn( |
| 58 | + 'column_with_type_float', |
| 59 | + \Magento\Framework\DB\Ddl\Table::TYPE_FLOAT, |
| 60 | + null, |
| 61 | + ['nullable' => true, 'default' => null], |
| 62 | + 'Column with type float' |
| 63 | + )->addColumn( |
| 64 | + 'column_with_type_numeric', |
| 65 | + \Magento\Framework\DB\Ddl\Table::TYPE_NUMERIC, |
| 66 | + '12,4', |
| 67 | + ['unsigned' => true, 'nullable' => true], |
| 68 | + 'Column with type numeric' |
| 69 | + )->addColumn( |
| 70 | + 'column_with_type_decimal', |
| 71 | + \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, |
| 72 | + '12,4', |
| 73 | + ['unsigned' => true, 'nullable' => true], |
| 74 | + 'Column with type decimal' |
| 75 | + )->addColumn( |
| 76 | + 'column_with_type_datetime', |
| 77 | + \Magento\Framework\DB\Ddl\Table::TYPE_DATETIME, |
| 78 | + null, |
| 79 | + ['nullable' => true, 'default' => null], |
| 80 | + 'Column with type datetime' |
| 81 | + )->addColumn( |
| 82 | + 'column_with_type_timestamp_update', |
| 83 | + \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP, |
| 84 | + null, |
| 85 | + ['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_UPDATE], |
| 86 | + 'Column with type timestamp update' |
| 87 | + )->addColumn( |
| 88 | + 'column_with_type_date', |
| 89 | + \Magento\Framework\DB\Ddl\Table::TYPE_DATE, |
| 90 | + null, |
| 91 | + ['nullable' => true, 'default' => null], |
| 92 | + 'Column with type date' |
| 93 | + )->addColumn( |
| 94 | + 'column_with_type_text', |
| 95 | + \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, |
| 96 | + '64k', |
| 97 | + [], |
| 98 | + 'Column with type text' |
| 99 | + )->addColumn( |
| 100 | + 'column_with_type_blob', |
| 101 | + \Magento\Framework\DB\Ddl\Table::TYPE_BLOB, |
| 102 | + 32, |
| 103 | + [], |
| 104 | + 'Column with type blob' |
| 105 | + )->addColumn( |
| 106 | + 'column_with_type_verbinary', |
| 107 | + \Magento\Framework\DB\Ddl\Table::TYPE_VARBINARY, |
| 108 | + '2m', |
| 109 | + [], |
| 110 | + 'Column with type varbinary' |
| 111 | + )->addIndex( |
| 112 | + $installer->getIdxName( |
| 113 | + 'setup_tests_table1', |
| 114 | + ['column_with_type_text'], |
| 115 | + \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_FULLTEXT |
| 116 | + ), |
| 117 | + ['column_with_type_text'], |
| 118 | + ['type' => \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_FULLTEXT] |
| 119 | + )->addIndex( |
| 120 | + $installer->getIdxName( |
| 121 | + 'setup_tests_table1', |
| 122 | + 'column_with_type_integer', |
| 123 | + \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_INDEX |
| 124 | + ), |
| 125 | + 'column_with_type_integer', |
| 126 | + ['type' => \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_INDEX] |
| 127 | + ); |
| 128 | + |
| 129 | + $installer->getConnection()->createTable($table); |
| 130 | + |
| 131 | + $relatedTable = $installer->getConnection()->newTable( |
| 132 | + $installer->getTable('setup_tests_table1_related') |
| 133 | + )->addColumn( |
| 134 | + 'column_with_type_timestamp_init_update', |
| 135 | + \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP, |
| 136 | + null, |
| 137 | + ['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT_UPDATE], |
| 138 | + 'Column with type timestamp init update' |
| 139 | + )->addColumn( |
| 140 | + 'column_with_type_timestamp_init', |
| 141 | + \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP, |
| 142 | + null, |
| 143 | + ['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT], |
| 144 | + 'Column with type timestamp init' |
| 145 | + )->addColumn( |
| 146 | + 'column_with_relation', |
| 147 | + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, |
| 148 | + null, |
| 149 | + ['unsigned' => true, 'nullable' => false], |
| 150 | + 'Column with type integer and relation' |
| 151 | + )->addForeignKey( |
| 152 | + $installer->getFkName( |
| 153 | + 'setup_table1_related', |
| 154 | + 'column_with_relation', |
| 155 | + 'setup_tests_table1', |
| 156 | + 'column_with_type_integer' |
| 157 | + ), |
| 158 | + 'column_with_relation', |
| 159 | + $installer->getTable('setup_tests_table1'), |
| 160 | + 'column_with_type_integer', |
| 161 | + \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE |
| 162 | + )->setComment( |
| 163 | + 'Related Table' |
| 164 | + ); |
| 165 | + $installer->getConnection()->createTable($relatedTable); |
| 166 | + $installer->endSetup(); |
| 167 | + } |
| 168 | +} |
0 commit comments