1
0

Version28000Date20231004103301.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OC\Core\Migrations;
  8. use Closure;
  9. use OCP\DB\ISchemaWrapper;
  10. use OCP\DB\Types;
  11. use OCP\Migration\IOutput;
  12. use OCP\Migration\SimpleMigrationStep;
  13. // Create new tables for the Metadata API (files_metadata and files_metadata_index).
  14. class Version28000Date20231004103301 extends SimpleMigrationStep {
  15. public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
  16. /** @var ISchemaWrapper $schema */
  17. $schema = $schemaClosure();
  18. $updated = false;
  19. if (!$schema->hasTable('files_metadata')) {
  20. $table = $schema->createTable('files_metadata');
  21. $table->addColumn('id', Types::BIGINT, [
  22. 'autoincrement' => true,
  23. 'notnull' => true,
  24. 'length' => 20,
  25. ]);
  26. $table->addColumn('file_id', Types::BIGINT, [
  27. 'notnull' => true,
  28. 'length' => 20,
  29. ]);
  30. $table->addColumn('json', Types::TEXT);
  31. $table->addColumn('sync_token', Types::STRING, [
  32. 'length' => 15,
  33. ]);
  34. $table->addColumn('last_update', Types::DATETIME);
  35. $table->setPrimaryKey(['id']);
  36. $table->addUniqueIndex(['file_id'], 'files_meta_fileid');
  37. $updated = true;
  38. }
  39. if (!$schema->hasTable('files_metadata_index')) {
  40. $table = $schema->createTable('files_metadata_index');
  41. $table->addColumn('id', Types::BIGINT, [
  42. 'autoincrement' => true,
  43. 'notnull' => true,
  44. 'length' => 20,
  45. ]);
  46. $table->addColumn('file_id', Types::BIGINT, [
  47. 'notnull' => true,
  48. 'length' => 20,
  49. ]);
  50. $table->addColumn('meta_key', Types::STRING, [
  51. 'notnull' => false,
  52. 'length' => 31,
  53. ]);
  54. $table->addColumn('meta_value_string', Types::STRING, [
  55. 'notnull' => false,
  56. 'length' => 63,
  57. ]);
  58. $table->addColumn('meta_value_int', Types::BIGINT, [
  59. 'notnull' => false,
  60. 'length' => 11,
  61. ]);
  62. $table->setPrimaryKey(['id']);
  63. $table->addIndex(['file_id', 'meta_key', 'meta_value_string'], 'f_meta_index');
  64. $table->addIndex(['file_id', 'meta_key', 'meta_value_int'], 'f_meta_index_i');
  65. $updated = true;
  66. }
  67. if (!$updated) {
  68. return null;
  69. }
  70. return $schema;
  71. }
  72. }