1
0

Version14000Date20180404140050.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OC\Core\Migrations;
  8. use OCP\DB\ISchemaWrapper;
  9. use OCP\IDBConnection;
  10. use OCP\Migration\IOutput;
  11. use OCP\Migration\SimpleMigrationStep;
  12. /**
  13. * Auto-generated migration step: Please modify to your needs!
  14. */
  15. class Version14000Date20180404140050 extends SimpleMigrationStep {
  16. public function __construct(
  17. private IDBConnection $connection,
  18. ) {
  19. }
  20. public function name(): string {
  21. return 'Add lowercase user id column to users table';
  22. }
  23. public function description(): string {
  24. return 'Adds "uid_lower" column to the users table and fills the column to allow indexed case-insensitive searches';
  25. }
  26. /**
  27. * @param IOutput $output
  28. * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
  29. * @param array $options
  30. * @return null|ISchemaWrapper
  31. */
  32. public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) {
  33. /** @var ISchemaWrapper $schema */
  34. $schema = $schemaClosure();
  35. $table = $schema->getTable('users');
  36. $table->addColumn('uid_lower', 'string', [
  37. 'notnull' => false,
  38. 'length' => 64,
  39. 'default' => '',
  40. ]);
  41. $table->addIndex(['uid_lower'], 'user_uid_lower');
  42. return $schema;
  43. }
  44. /**
  45. * @param IOutput $output
  46. * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
  47. * @param array $options
  48. */
  49. public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) {
  50. $qb = $this->connection->getQueryBuilder();
  51. $qb->update('users')
  52. ->set('uid_lower', $qb->func()->lower('uid'));
  53. $qb->execute();
  54. }
  55. }