UpgradeSchema.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /**
  3. * Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License").
  6. * You may not use this file except in compliance with the License.
  7. * A copy of the License is located at
  8. *
  9. * http://aws.amazon.com/apache2.0
  10. *
  11. * or in the "license" file accompanying this file. This file is distributed
  12. * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
  13. * express or implied. See the License for the specific language governing
  14. * permissions and limitations under the License.
  15. */
  16. namespace Amazon\Login\Setup;
  17. use Amazon\Login\Model\ResourceModel\CustomerLink;
  18. use Magento\Framework\DB\Adapter\AdapterInterface;
  19. use Magento\Framework\Setup\ModuleContextInterface;
  20. use Magento\Framework\Setup\SchemaSetupInterface;
  21. use Magento\Framework\Setup\UpgradeSchemaInterface;
  22. class UpgradeSchema implements UpgradeSchemaInterface
  23. {
  24. public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context)
  25. {
  26. if (version_compare($context->getVersion(), '1.1.0', '<')) {
  27. $table = $setup->getTable('customer_entity');
  28. $setup->getConnection()->addForeignKey(
  29. $setup->getFkName(CustomerLink::TABLE_NAME, 'customer_id', $table, 'entity_id'),
  30. $setup->getTable(CustomerLink::TABLE_NAME),
  31. 'customer_id',
  32. $setup->getTable('customer_entity'),
  33. 'entity_id',
  34. AdapterInterface::FK_ACTION_CASCADE
  35. );
  36. }
  37. if (version_compare($context->getVersion(), '1.2.0', '<')) {
  38. $setup->getConnection()->addIndex(
  39. $setup->getTable(CustomerLink::TABLE_NAME),
  40. $setup->getIdxName(CustomerLink::TABLE_NAME, ['customer_id'], AdapterInterface::INDEX_TYPE_UNIQUE),
  41. ['customer_id'],
  42. AdapterInterface::INDEX_TYPE_UNIQUE
  43. );
  44. }
  45. }
  46. }