Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix smallint used as auto increment on snowio_order_relateddata table #14

Merged
merged 1 commit into from
Sep 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion Setup/UpgradeSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con
$this->installOrderRelatedDataSchema($setup);
}

if (version_compare($context->getVersion(), '1.1.1', '<')) {
$this->updateIdColumnToInt10($setup);
}

$setup->endSetup();
}

Expand Down Expand Up @@ -98,4 +102,31 @@ protected function installOrderRelatedDataSchema(SchemaSetupInterface $setup)

$setup->getConnection()->createTable($table);
}
}

/**
* The original `smallint(6)` field had a maximum auto increment value of 32767 which is easily depleted. This
* updates the column to `int(10) unsigned` which has a maximum of 4294967295
*
* @param \Magento\Framework\Setup\SchemaSetupInterface $setup
*/
private function updateIdColumnToInt10(SchemaSetupInterface $setup)
{
$connection = $setup->getConnection();
if (!$connection->tableColumnExists($setup->getTable(ResourceModel\OrderRelatedData::TABLE), 'id')) {
return;
}

$connection->modifyColumn(
$setup->getTable(ResourceModel\OrderRelatedData::TABLE),
'id',
[
'type' => Table::TYPE_INTEGER,
'identity' => true,
'nullable' => false,
'primary' => true,
'unsigned' => true,
'comment' => 'ID'
]
);
}
}
9 changes: 5 additions & 4 deletions etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="SnowIO_ExtendedSalesRepositories" setup_version="1.1.0">
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="SnowIO_ExtendedSalesRepositories" setup_version="1.1.1">
<sequence>
<module name="Magento_Sales" />
<module name="Magento_Sales"/>
</sequence>
</module>
</config>
</config>