<?php

$installer = $this;
$installer->startSetup();
$installer->run("\r\n\r\nDROP TABLE IF EXISTS {$this->getTable('luckydraw_code')};\r\nDROP TABLE IF EXISTS {$this->getTable('luckydraw_program')};\r\n\r\nCREATE TABLE {$this->getTable('luckydraw_program')} (\r\n  `program_id` int(10) unsigned NOT NULL auto_increment,\r\n  `name` varchar(255) NOT NULL default '',\r\n  `short_description` text NULL,\r\n  `award_image` varchar(255) NULL,\r\n  `description` mediumtext NULL,\r\n  `url_key` varchar(255) NULL,\r\n  `status` smallint(5) default '0',\r\n  `created_time` datetime NULL,\r\n  `start_time` datetime NULL,\r\n  `end_time` datetime NULL,\r\n  `code_length` smallint(5) default '5',\r\n  `min_user` smallint(5) default '0',\r\n  `auto_prize` tinyint(1) default '0',\r\n  `prize_code` varchar(255) default '',\r\n  `prize_days` int(10) default '0',\r\n  `credit_rate` decimal(12,4) NOT NULL default '0',\r\n  `term_condition` mediumtext NULL,\r\n  `store_ids` text NULL,\r\n  PRIMARY KEY (`program_id`)\r\n) ENGINE=InnoDB DEFAULT CHARSET=utf8;\r\n\r\nCREATE TABLE {$this->getTable('luckydraw_code')} (\r\n  `code_id` int(10) unsigned NOT NULL auto_increment,\r\n  `program_id` int(10) unsigned NOT NULL,\r\n  `customer_id` int(10) unsigned NOT NULL,\r\n  `refer_user` int(10) unsigned NOT NULL,\r\n  `refer_email` varchar(255) NULL,\r\n  `name` varchar(255) NULL,\r\n  `email` varchar(255) NULL,\r\n  `address_id` int(10) unsigned NULL,\r\n  `order_id` int(10) unsigned NOT NULL,\r\n  `order_increment_id` varchar(127) NULL,\r\n  `draw_code` varchar(255) NULL,\r\n  `created_time` datetime NULL,\r\n  `expired_time` datetime NULL,\r\n  `status` smallint(5) default '0',\r\n  `is_prize` tinyint(1) default '0',\r\n  `credit_rate` decimal(12,4) NOT NULL default '0',\r\n  PRIMARY KEY (`code_id`),\r\n  INDEX (`program_id`),\r\n  FOREIGN KEY (`program_id`)\r\n  REFERENCES {$this->getTable('luckydraw_program')} (`program_id`)\r\n  ON DELETE CASCADE\r\n  ON UPDATE CASCADE\r\n) ENGINE=InnoDB DEFAULT CHARSET=utf8;\r\n\r\n    ");
try {
    $installer->run("\r\n\tALTER TABLE {$this->getTable('sales/order')}\r\n\t\tADD COLUMN `luckydraw_discount` decimal(12,4) default NULL,\r\n\t\tADD COLUMN `base_luckydraw_discount` decimal(12,4) default NULL;\r\n\t");
} catch (Exception $e) {
}
try {
    $setup = new Mage_Customer_Model_Entity_Setup();
    $setup->addAttribute('customer', 'national_id', array('group' => 'General', 'type' => 'varchar', 'input' => 'text', 'label' => 'National Identification', 'visible' => 1, 'required' => 0, 'visible_on_front' => 1, 'sort_order' => 120));
    $setup->getConnection()->insertMultiple($setup->getTable('customer/form_attribute'), array(array('form_code' => 'adminhtml_customer', 'attribute_id' => $setup->getAttributeId('customer', 'national_id'))));
} catch (Exception $e) {
}
$installer->endSetup();
<?php

// $installer = $this; //Mage_Core_Model_Resource_Setup
$installer = new Mage_Customer_Model_Entity_Setup('core_setup');
$installer->startSetup();
/**
 * Create table 'adm_abandonedcart/followup'
 */
$table = $installer->getConnection()->newTable($installer->getTable('adm_abandonedcart/followup'))->addColumn('followup_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array('identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true), 'Followup Id')->addColumn('quote_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array('unsigned' => true, 'nullable' => false, 'default' => '0'), 'Quote Id')->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array('unsigned' => true, 'nullable' => false, 'default' => '0'), 'Store Id')->addColumn('abandonned_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array('nullable' => false), 'Cart Abandoned At')->addColumn('customer_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array('unsigned' => true, 'default' => '0'), 'Customer Id')->addColumn('customer_email', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array(), 'Customer Email')->addColumn('base_grand_total', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array('default' => '0.0000'), 'Base Grand Total')->addColumn('coupon_code', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array(), 'Coupon Code')->addColumn('secret_code', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array(), 'Secret code')->addColumn('is_closed', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array('unsigned' => true, 'default' => '0'), 'Is restored')->addColumn('offset', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array('unsigned' => true, 'default' => '0'), 'Offset')->addColumn('mail_scheduled_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array('nullable' => false), 'Mail1 Scheduled At')->addIndex($installer->getIdxName('adm_abandonedcart/followup', array('customer_id', 'store_id')), array('customer_id', 'store_id'))->addIndex($installer->getIdxName('adm_abandonedcart/followup', array('store_id')), array('store_id'))->addForeignKey($installer->getFkName('adm_abandonedcart/followup', 'store_id', 'core/store', 'store_id'), 'store_id', $installer->getTable('core/store'), 'store_id', Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE)->addIndex($installer->getIdxName('adm_abandonedcart/followup', array('quote_id')), array('quote_id'))->addForeignKey($installer->getFkName('adm_abandonedcart/followup', 'quote_id', 'sales/quote', 'entity_id'), 'quote_id', $installer->getTable('sales/quote'), 'entity_id', Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE)->setComment('ADM Cart Abandoned to follow');
$installer->getConnection()->createTable($table);
$table = $installer->getConnection()->newTable($installer->getTable('adm_abandonedcart/tracker'))->addColumn('tracker_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array('identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true), 'Tracker Id')->addColumn('followup_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array('unsigned' => true, 'nullable' => false, 'default' => '0'), 'Followup Id')->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array('unsigned' => true, 'nullable' => false, 'default' => '0'), 'Store Id')->addColumn('restored', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array('unsigned' => true, 'default' => '0'), 'Restored')->addColumn('offset', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array('unsigned' => true, 'default' => '0'), 'Offset')->addColumn('track_code', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array(), 'Message')->addColumn('track_message', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array(), 'Message')->addColumn('remote_ip', Varien_Db_Ddl_Table::TYPE_TEXT, 16, array('nullable' => false), 'Customer IP')->addColumn('created_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array('nullable' => false), 'Created At')->addForeignKey($installer->getFkName('adm_abandonedcart/tracker', 'followup_id', 'adm_abandonedcart/tracker', 'followup_id'), 'followup_id', $installer->getTable('adm_abandonedcart/followup'), 'followup_id', Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE)->setComment('ADM Cart Abandoned tracker');
$installer->getConnection()->createTable($table);
$installer->endSetup();
<?php

$this->startSetup();
$installer = new Mage_Customer_Model_Entity_Setup();
$installer->getConnection()->addColumn($installer->getTable('customer_group'), 'cost_percent', array('type' => Varien_Db_Ddl_Table::TYPE_FLOAT, 'nullable' => true, 'default' => 0.0, 'comment' => 'Default cost addition for dealers'));
$this->endSetup();