InstallSchema.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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\DB\Ddl\Table;
  20. use Magento\Framework\Setup\InstallSchemaInterface;
  21. use Magento\Framework\Setup\ModuleContextInterface;
  22. use Magento\Framework\Setup\SchemaSetupInterface;
  23. class InstallSchema implements InstallSchemaInterface
  24. {
  25. /**
  26. * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  27. */
  28. public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)
  29. {
  30. $table = $setup->getConnection()->newTable($setup->getTable(CustomerLink::TABLE_NAME));
  31. $table
  32. ->addColumn(
  33. 'entity_id',
  34. Table::TYPE_INTEGER,
  35. null,
  36. [
  37. 'identity' => true,
  38. 'unsigned' => true,
  39. 'primary' => true,
  40. 'nullable' => false
  41. ]
  42. )
  43. ->addColumn(
  44. 'customer_id',
  45. Table::TYPE_INTEGER,
  46. null,
  47. [
  48. 'unsigned' => true,
  49. 'nullable' => false
  50. ]
  51. )
  52. ->addColumn(
  53. 'amazon_id',
  54. Table::TYPE_TEXT,
  55. 255,
  56. [
  57. 'nullable' => false
  58. ]
  59. )
  60. ->addIndex(
  61. $setup->getIdxName(
  62. CustomerLink::TABLE_NAME,
  63. ['customer_id', 'amazon_id'],
  64. AdapterInterface::INDEX_TYPE_UNIQUE
  65. ),
  66. ['customer_id', 'amazon_id'],
  67. ['type' => AdapterInterface::INDEX_TYPE_UNIQUE]
  68. );
  69. $setup->getConnection()->createTable($table);
  70. }
  71. }