1

what is the resource type to use in an upgrade script to do as explained here Multiple setup types in same module but for the newsletter subscriber table
i've tried $installer = Mage::getModel('newsletter/resource_subscriber', 'newsletter_setup'); and doesn't work. What i'm doing wrong or missing?

UPDATE:

the code i've used is:

 {$installer = $this; $installer->startSetup(); $conn = $installer->getConnection(); $subscriberTable = $installer->getTable('newsletter/subscriber'); $conn->addColumn($subscriberTable, 'rjm_utm_source', array( 'type' => 'varchar', 'default' => '', 'nullable' => true, 'comment' => '__utmz::utmcsr'));}

the error i've received is: Invalid column definition

this because doesn't accept as type 'varchar'. the acceptable type are:

protected $_ddlColumnTypes      = array(
    Varien_Db_Ddl_Table::TYPE_BOOLEAN       => 'bool',
    Varien_Db_Ddl_Table::TYPE_SMALLINT      => 'smallint',
    Varien_Db_Ddl_Table::TYPE_INTEGER       => 'int',
    Varien_Db_Ddl_Table::TYPE_BIGINT        => 'bigint',
    Varien_Db_Ddl_Table::TYPE_FLOAT         => 'float',
    Varien_Db_Ddl_Table::TYPE_DECIMAL       => 'decimal',
    Varien_Db_Ddl_Table::TYPE_NUMERIC       => 'decimal',
    Varien_Db_Ddl_Table::TYPE_DATE          => 'date',
    Varien_Db_Ddl_Table::TYPE_TIMESTAMP     => 'timestamp',
    Varien_Db_Ddl_Table::TYPE_DATETIME      => 'datetime',
    Varien_Db_Ddl_Table::TYPE_TEXT          => 'text',
    Varien_Db_Ddl_Table::TYPE_BLOB          => 'blob',
    Varien_Db_Ddl_Table::TYPE_VARBINARY     => 'blob'
);

and varchar is deprecated :

// Deprecated column types, support is left only in MySQL adapter.
const TYPE_TINYINT          = 'tinyint';        // Internally converted to TYPE_SMALLINT
const TYPE_CHAR             = 'char';           // Internally converted to TYPE_TEXT
const TYPE_VARCHAR          = 'varchar';        // Internally converted to TYPE_TEXT
const TYPE_LONGVARCHAR      = 'longvarchar';    // Internally converted to TYPE_TEXT
const TYPE_CLOB             = 'cblob';          // Internally converted to TYPE_TEXT
const TYPE_DOUBLE           = 'double';         // Internally converted to TYPE_FLOAT
const TYPE_REAL             = 'real';           // Internally converted to TYPE_FLOAT
const TYPE_TIME             = 'time';           // Internally converted to TYPE_TIMESTAMP
const TYPE_BINARY           = 'binary';         // Internally converted to TYPE_BLOB
const TYPE_LONGVARBINARY    = 'longvarbinary';  // Internally converted to TYPE_BLOB
3
  • what do you want to achieve? I don't understand the question. Commented May 21, 2014 at 20:33
  • i want to add some columns to newsletter_subscriber table without using sql, this means using addColumn but in the module i want to do this the resource is Mage_Sales_Model_Resource_Setup and so it doesn't have the methods addColumn or getTable. makes sense?
    – springerin
    Commented May 21, 2014 at 22:07
  • Have a look at magento.stackexchange.com/questions/9642/… Commented May 22, 2014 at 9:08

1 Answer 1

1

Yes, makes sense.

To add a column to a table you need a Varien_Db_Adapter_Interface object, this can you get from $installer->getConnection()

with this object you can do a lot, e.g.:

$conn->addColumn($installer->getTable('newsletter/subscriber'), 'new_column', $type);

and $type needs to define all the stuff the column needs:

  • type
    • you can use the constants Varien_Db_Ddl_Table::TYPE_ here
  • primary
  • identity
  • unsigned
  • nullable
  • default
  • scale
  • precision

maybe I'm wrong here (in parts)

The important information is, it doesn't matter which Setup resource model you use. Afaik this is only important when you are working with old-EAV-now-flat-tables aka Mage_Sales_Model_Resource_Setup, maybe the resource is important to write the extended attributes, like show_in_product_listing, I can't memorize this. But this is not important to achieve your goal.

9
  • i've already done this way but it gives me an error. this is the code {$installer = $this; $installer->startSetup(); $conn = $installer->getConnection(); $subscriberTable = $installer->getTable('newsletter/subscriber'); $conn->addColumn($subscriberTable, 'rjm_utm_source', array( 'type' => 'varchar', 'default' => '', 'nullable' => true, 'comment' => '__utmz::utmcsr'));} and this is the error a:5:{i:0;s:178:"Error in file: "/var/www/html/xxx/mysql4-upgrade-1.0.0.0-1.0.0.1.php" - Invalid column definition
    – springerin
    Commented May 22, 2014 at 8:24
  • MAybe you should add this error to your question - or you just debug it by yourself ;-) Commented May 22, 2014 at 8:25
  • sorry, by mistake i hit enter and got posted incomplete. now should be complete.
    – springerin
    Commented May 22, 2014 at 8:27
  • i've looked into it and the error is when you don't define the type in the definition but as you see i pass the type. it's really weird and i'm sure i'm doing something wrong (i'm a newbie with magento) but i can't really figured it out
    – springerin
    Commented May 22, 2014 at 8:38
  • turn xdebug on and check, why the value is not passed to lib/Varien/Db/Adapter/Pdo/Mysql.php:2234 - the code looks good. Please add the code to your question for better formatting Commented May 22, 2014 at 8:39

Not the answer you're looking for? Browse other questions tagged or ask your own question.