cancel
Showing results for 
Search instead for 
Did you mean: 

Schema Upgrade in EE 2.0.2 with split database not working / updating wrong table

SOLVED

Schema Upgrade in EE 2.0.2 with split database not working / updating wrong table

Hi,

 

I'm trying to add a column to sales_invoice table in Magento 2.0.2 EE with my modules setup script.

 

$tableInvoice = $installer->getTable('sales_invoice');
if ( !$installer->getConnection()->tableColumnExists($tableInvoice, 'document_uri')) {
$installer->getConnection()->addColumn(
$tableInvoice,
'document_uri',
array(
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
'length' => '255',
'comment' => 'Uri to invoice document',
)
);
}

 

Unfortunately the upgrade is executed in the "Main" database, the invoice table in "OMS" database does not get the upgrade.

Wenn I add an invoice it is correctly created in the OMS databases invoice table.

 

How can I set the correct database in the setup script (or evaluate which one to use)?

 

 

1 REPLY

Re: Schema Upgrade in EE 2.0.2 with split database not working / updating wrong table

Found the solution by myself:

 

1. Create a constructor in the install script:

public function __construct(\Magento\Framework\App\ResourceConnection $salesResource)
{
$this->_salesResource = $salesResource;
}

 

2. Use that resource to get the correct connection and tables

$salesConnection = $this->_salesResource->getConnection('sales');

/**
* Extend sales_invoice table
*/
$tableInvoice = $salesConnection->getTableName('sales_invoice');
if ( !$salesConnection->tableColumnExists($tableInvoice, 'document_url')) {
$salesConnection->addColumn(
$tableInvoice,
'document_url',
array(
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
'length' => '255',
'comment' => 'Url to invoice document',
)
);
}