Created
April 26, 2016 13:46
-
-
Save herveguetin/90cd9d6e100fee2b328cae5d34e1c53c to your computer and use it in GitHub Desktop.
Add a column after another one in Magento 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace My\Module\Setup; | |
use Magento\Framework\Setup\ModuleContextInterface; | |
use Magento\Framework\Setup\SchemaSetupInterface; | |
use Magento\Framework\Setup\UpgradeSchemaInterface; | |
/** | |
* @codeCoverageIgnore | |
*/ | |
class UpgradeSchema implements UpgradeSchemaInterface | |
{ | |
/** | |
* {@inheritdoc} | |
*/ | |
public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context) | |
{ | |
$setup->startSetup(); | |
if (version_compare($context->getVersion(), '[SOME_VERSION]', '<')) { | |
$setup->getConnection()->addColumn( | |
$setup->getTable('my_module_table'), | |
'my_column_name', | |
[ | |
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, // Or any other type | |
'nullable' => true, // Or false | |
'comment' => 'Some comment', | |
'after' => 'some_column_to_place_the_new_one_after' | |
] | |
); | |
} | |
$setup->endSetup(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment