Search code examples
mysqlmagentomagento-1.9

Magento customer entity table remove UNIQUE KEY in table properties


I need to change default customer_entity table description in magento with my plugin's setup script, is it possible to make it remove the UNIQUE KEY field ?

The magento customer_entity table structure described as:

CREATE TABLE `customer_entity` (
  `entity_id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Entity Id',
  `entity_type_id` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT 'Entity Type Id',
  `attribute_set_id` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT 'Attribute Set Id',
  `website_id` smallint(5) unsigned DEFAULT NULL COMMENT 'Website Id',
  `email` varchar(255) DEFAULT NULL COMMENT 'Email',
  ...
  UNIQUE KEY `UNQ_CUSTOMER_ENTITY_EMAIL_WEBSITE_ID` (`email`,`website_id`),
  ...

So what I need is to make it remove this one with installation script

UNIQUE KEY `UNQ_CUSTOMER_ENTITY_EMAIL_WEBSITE_ID` (`email`,`website_id`)

Solution

  • you could run sql queries in an update/install script:

    <?php
    $installer = $this;
    $installer->startSetup();
    $sql= 'ALTER TABLE `customer_entity` DROP INDEX `UNQ_CUSTOMER_ENTITY_EMAIL_WEBSITE_ID`'
    $installer->run($sql);
    $installer->endSetup();
    

    Or you could do it in the "magento way" like this (untested code!)

    <?php
    $installer = $this;
    $installer->getConnection()->dropKey('customer_entity', 'UNQ_CUSTOMER_ENTITY_EMAIL_WEBSITE_ID')
    $installer->endSetup();