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 2020 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. namespace OCA\ContactsInteraction\Migration;
  24. use Closure;
  25. use OCA\ContactsInteraction\Db\RecentContactMapper;
  26. use OCP\DB\ISchemaWrapper;
  27. use OCP\Migration\IOutput;
  28. use OCP\Migration\SimpleMigrationStep;
  29. class Version010000Date20200304152605 extends SimpleMigrationStep {
  30. /**
  31. * @param IOutput $output
  32. * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
  33. * @param array $options
  34. *
  35. * @return ISchemaWrapper
  36. */
  37. public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ISchemaWrapper {
  38. /** @var ISchemaWrapper $schema */
  39. $schema = $schemaClosure();
  40. $table = $schema->createTable(RecentContactMapper::TABLE_NAME);
  41. $table->addColumn('id', 'integer', [
  42. 'autoincrement' => true,
  43. 'notnull' => true,
  44. 'length' => 4,
  45. ]);
  46. $table->addColumn('actor_uid', 'string', [
  47. 'notnull' => true,
  48. 'length' => 64,
  49. ]);
  50. $table->addColumn('uid', 'string', [
  51. 'notnull' => false,
  52. 'length' => 64,
  53. ]);
  54. $table->addColumn('email', 'string', [
  55. 'notnull' => false,
  56. 'length' => 255,
  57. ]);
  58. $table->addColumn('federated_cloud_id', 'string', [
  59. 'notnull' => false,
  60. 'length' => 255,
  61. ]);
  62. $table->addColumn('card', 'blob', [
  63. 'notnull' => true,
  64. ]);
  65. $table->addColumn('last_contact', 'integer', [
  66. 'notnull' => true,
  67. 'length' => 4,
  68. ]);
  69. $table->setPrimaryKey(['id']);
  70. // To find all recent entries
  71. $table->addIndex(['actor_uid'], RecentContactMapper::TABLE_NAME . '_actor_uid');
  72. // To find a specific entry
  73. $table->addIndex(['id', 'actor_uid'], RecentContactMapper::TABLE_NAME . '_id_uid');
  74. // To find all recent entries with a given UID
  75. $table->addIndex(['uid'], RecentContactMapper::TABLE_NAME . '_uid');
  76. // To find all recent entries with a given email address
  77. $table->addIndex(['email'], RecentContactMapper::TABLE_NAME . '_email');
  78. // To find all recent entries with a give federated cloud id
  79. $table->addIndex(['federated_cloud_id'], RecentContactMapper::TABLE_NAME . '_fed_id');
  80. // For the cleanup
  81. $table->addIndex(['last_contact'], RecentContactMapper::TABLE_NAME . '_last_contact');
  82. return $schema;
  83. }
  84. }