1
0

Version31000Date20240814184402.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 OCP\DB\ISchemaWrapper;
  10. use OCP\DB\Types;
  11. use OCP\Migration\Attributes\AddColumn;
  12. use OCP\Migration\Attributes\AddIndex;
  13. use OCP\Migration\Attributes\ColumnType;
  14. use OCP\Migration\Attributes\DropIndex;
  15. use OCP\Migration\Attributes\IndexType;
  16. use OCP\Migration\IOutput;
  17. use OCP\Migration\SimpleMigrationStep;
  18. /**
  19. * Create new column and index for lazy loading in preferences for the new IUserPreferences API.
  20. */
  21. #[AddColumn(table: 'preferences', name: 'lazy', type: ColumnType::SMALLINT, description: 'lazy loading to user preferences')]
  22. #[AddColumn(table: 'preferences', name: 'type', type: ColumnType::SMALLINT, description: 'typed values to user preferences')]
  23. #[AddColumn(table: 'preferences', name: 'flag', type: ColumnType::INTEGER, description: 'bitflag about the value')]
  24. #[AddColumn(table: 'preferences', name: 'indexed', type: ColumnType::INTEGER, description: 'non-array value can be set as indexed')]
  25. #[DropIndex(table: 'preferences', type: IndexType::INDEX, description: 'remove previous app/key index', notes: ['will be re-created to include \'indexed\' field'])]
  26. #[AddIndex(table: 'preferences', type: IndexType::INDEX, description: 'new index including user+lazy')]
  27. #[AddIndex(table: 'preferences', type: IndexType::INDEX, description: 'new index including app/key and indexed')]
  28. class Version31000Date20240814184402 extends SimpleMigrationStep {
  29. public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
  30. /** @var ISchemaWrapper $schema */
  31. $schema = $schemaClosure();
  32. $table = $schema->getTable('preferences');
  33. $table->addColumn('lazy', Types::SMALLINT, ['notnull' => true, 'default' => 0, 'length' => 1, 'unsigned' => true]);
  34. $table->addColumn('type', Types::SMALLINT, ['notnull' => true, 'default' => 0, 'unsigned' => true]);
  35. $table->addColumn('flags', Types::INTEGER, ['notnull' => true, 'default' => 0, 'unsigned' => true]);
  36. $table->addColumn('indexed', Types::STRING, ['notnull' => false, 'default' => '', 'length' => 64]);
  37. // removing this index from Version13000Date20170718121200
  38. // $table->addIndex(['appid', 'configkey'], 'preferences_app_key');
  39. if ($table->hasIndex('preferences_app_key')) {
  40. $table->dropIndex('preferences_app_key');
  41. }
  42. $table->addIndex(['userid', 'lazy'], 'prefs_uid_lazy_i');
  43. $table->addIndex(['appid', 'configkey', 'indexed', 'flags'], 'prefs_app_key_ind_fl_i');
  44. return $schema;
  45. }
  46. }