Engine23
blogBannerImage
By Engine23

Magento - Adding an index to a table during an upgrade script

I think the title of this says it all. This is how you can add an index and a new column to a table during an upgrade script

$installer= $this;

$installer->startSetup();
$tableName = $installer->getTable('dpc_subscription/event');
$indexName = $installer->getIdxName($tableName, array('is_shipped'));
$installer->getConnection()->addColumn($tableName, 'is_shipped', array(
'type' => Varien_Db_Ddl_Table::TYPE_INTEGER,
'unsigned' => true,
'nullable' => false,
'default' => '0',
'comment' => 'Is shipped'
));
$installer->getConnection()->addIndex($tableName, $indexName, array('is_shipped'));
$installer->endSetup();