1
0

Version31000Date20241018063111.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2024 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 Doctrine\DBAL\Types\Types;
  10. use OCP\DB\ISchemaWrapper;
  11. use OCP\Migration\Attributes\AddColumn;
  12. use OCP\Migration\Attributes\AddIndex;
  13. use OCP\Migration\Attributes\ColumnType;
  14. use OCP\Migration\Attributes\IndexType;
  15. use OCP\Migration\IOutput;
  16. use OCP\Migration\SimpleMigrationStep;
  17. /**
  18. * Add objecttype index to systemtag_object_mapping
  19. */
  20. #[AddColumn(table: 'systemtag', name: 'etag', type: ColumnType::STRING, description: 'Adding etag for systemtag table to prevent conflicts')]
  21. #[AddIndex(table: 'systemtag_object_mapping', type: IndexType::INDEX, description: 'Adding objecttype index to systemtag_object_mapping')]
  22. class Version31000Date20241018063111 extends SimpleMigrationStep {
  23. /**
  24. * @param IOutput $output
  25. * @param Closure(): ISchemaWrapper $schemaClosure
  26. * @param array $options
  27. * @return null|ISchemaWrapper
  28. */
  29. public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
  30. /** @var ISchemaWrapper $schema */
  31. $schema = $schemaClosure();
  32. if ($schema->hasTable('systemtag_object_mapping')) {
  33. $table = $schema->getTable('systemtag_object_mapping');
  34. if (!$table->hasIndex('systag_objecttype')) {
  35. $table->addIndex(['objecttype'], 'systag_objecttype');
  36. }
  37. }
  38. if ($schema->hasTable('systemtag')) {
  39. $table = $schema->getTable('systemtag');
  40. if (!$table->hasColumn('etag')) {
  41. $table->addColumn('etag', Types::STRING, [
  42. 'notnull' => false,
  43. 'length' => 32,
  44. ]);
  45. }
  46. }
  47. return $schema;
  48. }
  49. }