Version14000Date20180404140050.php 2.5 KB

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