Version14000Date20180404140050.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2018 Roeland Jago Douma <roeland@famdouma.nl>
  5. *
  6. * @author Robin Appelman <robin@icewind.nl>
  7. * @author Roeland Jago Douma <roeland@famdouma.nl>
  8. *
  9. * @license GNU AGPL version 3 or any later version
  10. *
  11. * This program is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License as
  13. * published by the Free Software Foundation, either version 3 of the
  14. * License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. *
  24. */
  25. namespace OC\Core\Migrations;
  26. use OCP\DB\ISchemaWrapper;
  27. use OCP\IDBConnection;
  28. use OCP\Migration\IOutput;
  29. use OCP\Migration\SimpleMigrationStep;
  30. /**
  31. * Auto-generated migration step: Please modify to your needs!
  32. */
  33. class Version14000Date20180404140050 extends SimpleMigrationStep {
  34. /** @var IDBConnection */
  35. private $connection;
  36. public function __construct(IDBConnection $connection) {
  37. $this->connection = $connection;
  38. }
  39. public function name(): string {
  40. return 'Add lowercase user id column to users table';
  41. }
  42. public function description(): string {
  43. return 'Adds "uid_lower" column to the users table and fills the column to allow indexed case-insensitive searches';
  44. }
  45. /**
  46. * @param IOutput $output
  47. * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
  48. * @param array $options
  49. * @return null|ISchemaWrapper
  50. */
  51. public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) {
  52. /** @var ISchemaWrapper $schema */
  53. $schema = $schemaClosure();
  54. $table = $schema->getTable('users');
  55. $table->addColumn('uid_lower', 'string', [
  56. 'notnull' => false,
  57. 'length' => 64,
  58. 'default' => '',
  59. ]);
  60. $table->addIndex(['uid_lower'], 'user_uid_lower');
  61. return $schema;
  62. }
  63. /**
  64. * @param IOutput $output
  65. * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
  66. * @param array $options
  67. */
  68. public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) {
  69. $qb = $this->connection->getQueryBuilder();
  70. $qb->update('users')
  71. ->set('uid_lower', $qb->func()->lower('uid'));
  72. $qb->execute();
  73. }
  74. }