You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Version010000Date20200304152605.php 3.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright 2020 Christoph Wurst <christoph@winzerhof-wurst.at>
  5. *
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. *
  8. * @license GNU AGPL version 3 or any later version
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. namespace OCA\ContactsInteraction\Migration;
  25. use Closure;
  26. use OCA\ContactsInteraction\Db\RecentContactMapper;
  27. use OCP\DB\ISchemaWrapper;
  28. use OCP\Migration\IOutput;
  29. use OCP\Migration\SimpleMigrationStep;
  30. class Version010000Date20200304152605 extends SimpleMigrationStep {
  31. /**
  32. * @param IOutput $output
  33. * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
  34. * @param array $options
  35. *
  36. * @return ISchemaWrapper
  37. */
  38. public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ISchemaWrapper {
  39. /** @var ISchemaWrapper $schema */
  40. $schema = $schemaClosure();
  41. $table = $schema->createTable(RecentContactMapper::TABLE_NAME);
  42. $table->addColumn('id', 'integer', [
  43. 'autoincrement' => true,
  44. 'notnull' => true,
  45. 'length' => 4,
  46. ]);
  47. $table->addColumn('actor_uid', 'string', [
  48. 'notnull' => true,
  49. 'length' => 64,
  50. ]);
  51. $table->addColumn('uid', 'string', [
  52. 'notnull' => false,
  53. 'length' => 64,
  54. ]);
  55. $table->addColumn('email', 'string', [
  56. 'notnull' => false,
  57. 'length' => 255,
  58. ]);
  59. $table->addColumn('federated_cloud_id', 'string', [
  60. 'notnull' => false,
  61. 'length' => 255,
  62. ]);
  63. $table->addColumn('card', 'blob', [
  64. 'notnull' => true,
  65. ]);
  66. $table->addColumn('last_contact', 'integer', [
  67. 'notnull' => true,
  68. 'length' => 4,
  69. ]);
  70. $table->setPrimaryKey(['id']);
  71. // To find all recent entries
  72. $table->addIndex(['actor_uid'], RecentContactMapper::TABLE_NAME . '_actor_uid');
  73. // To find a specific entry
  74. $table->addIndex(['id', 'actor_uid'], RecentContactMapper::TABLE_NAME . '_id_uid');
  75. // To find all recent entries with a given UID
  76. $table->addIndex(['uid'], RecentContactMapper::TABLE_NAME . '_uid');
  77. // To find all recent entries with a given email address
  78. $table->addIndex(['email'], RecentContactMapper::TABLE_NAME . '_email');
  79. // To find all recent entries with a give federated cloud id
  80. $table->addIndex(['federated_cloud_id'], RecentContactMapper::TABLE_NAME . '_fed_id');
  81. // For the cleanup
  82. $table->addIndex(['last_contact'], RecentContactMapper::TABLE_NAME . '_last_contact');
  83. return $schema;
  84. }
  85. }