Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save evgv/a731f93a1b013eaae97c9c152d44f75f to your computer and use it in GitHub Desktop.
Save evgv/a731f93a1b013eaae97c9c152d44f75f to your computer and use it in GitHub Desktop.
Magento. The right way to alter table (add column) via upgrade script

Right way to alter table (add column) via upgrade script

Add new text column(if it not existed) with name yt_id in table with alias aboutus/aboutus defined in config.xml

/* @var $installer Mage_Core_Model_Resource_Setup */
$installer    = $this;
$aboutusTable = $installer->getTable('aboutus/aboutus');
$connection   = $installer->getConnection();

$installer->startSetup();

$exists = $connection->tableColumnExists($aboutusTable, 'yt_id');

if(!$exists){
    $connection->addColumn(
        $aboutusTable,
        'yt_id',
        array(
            'type'     => Varien_Db_Ddl_Table::TYPE_TEXT,
            'comment'  => 'Youtube video identifier',
            'nullable'  => true
        )
    );
}

$installer->endSetup();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment