1
0

Version010000Date20200304152605.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\ContactsInteraction\Migration;
  8. use Closure;
  9. use OCA\ContactsInteraction\Db\RecentContactMapper;
  10. use OCP\DB\ISchemaWrapper;
  11. use OCP\Migration\IOutput;
  12. use OCP\Migration\SimpleMigrationStep;
  13. class Version010000Date20200304152605 extends SimpleMigrationStep {
  14. /**
  15. * @param IOutput $output
  16. * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
  17. * @param array $options
  18. *
  19. * @return ISchemaWrapper
  20. */
  21. public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ISchemaWrapper {
  22. /** @var ISchemaWrapper $schema */
  23. $schema = $schemaClosure();
  24. $table = $schema->createTable(RecentContactMapper::TABLE_NAME);
  25. $table->addColumn('id', 'integer', [
  26. 'autoincrement' => true,
  27. 'notnull' => true,
  28. 'length' => 4,
  29. ]);
  30. $table->addColumn('actor_uid', 'string', [
  31. 'notnull' => true,
  32. 'length' => 64,
  33. ]);
  34. $table->addColumn('uid', 'string', [
  35. 'notnull' => false,
  36. 'length' => 64,
  37. ]);
  38. $table->addColumn('email', 'string', [
  39. 'notnull' => false,
  40. 'length' => 255,
  41. ]);
  42. $table->addColumn('federated_cloud_id', 'string', [
  43. 'notnull' => false,
  44. 'length' => 255,
  45. ]);
  46. $table->addColumn('card', 'blob', [
  47. 'notnull' => true,
  48. ]);
  49. $table->addColumn('last_contact', 'integer', [
  50. 'notnull' => true,
  51. 'length' => 4,
  52. ]);
  53. $table->setPrimaryKey(['id']);
  54. // To find all recent entries
  55. $table->addIndex(['actor_uid'], RecentContactMapper::TABLE_NAME . '_actor_uid');
  56. // To find a specific entry
  57. $table->addIndex(['id', 'actor_uid'], RecentContactMapper::TABLE_NAME . '_id_uid');
  58. // To find all recent entries with a given UID
  59. $table->addIndex(['uid'], RecentContactMapper::TABLE_NAME . '_uid');
  60. // To find all recent entries with a given email address
  61. $table->addIndex(['email'], RecentContactMapper::TABLE_NAME . '_email');
  62. // To find all recent entries with a give federated cloud id
  63. $table->addIndex(['federated_cloud_id'], RecentContactMapper::TABLE_NAME . '_fed_id');
  64. // For the cleanup
  65. $table->addIndex(['last_contact'], RecentContactMapper::TABLE_NAME . '_last_contact');
  66. return $schema;
  67. }
  68. }