Version1002Date20170607104347.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2017 Joas Schilling <coding@schilljs.com>
  5. *
  6. * @author Daniel Kesselberg <mail@danielkesselberg.de>
  7. * @author Joas Schilling <coding@schilljs.com>
  8. * @author Roeland Jago Douma <roeland@famdouma.nl>
  9. *
  10. * @license GNU AGPL version 3 or any later version
  11. *
  12. * This program is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License as
  14. * published by the Free Software Foundation, either version 3 of the
  15. * License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  24. *
  25. */
  26. namespace OCA\TwoFactorBackupCodes\Migration;
  27. use Doctrine\DBAL\Types\Types;
  28. use OCP\DB\ISchemaWrapper;
  29. use OCP\Migration\IOutput;
  30. use OCP\Migration\SimpleMigrationStep;
  31. class Version1002Date20170607104347 extends SimpleMigrationStep {
  32. /**
  33. * @param IOutput $output
  34. * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
  35. * @param array $options
  36. * @return null|ISchemaWrapper
  37. * @since 13.0.0
  38. */
  39. public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) {
  40. /** @var ISchemaWrapper $schema */
  41. $schema = $schemaClosure();
  42. if (!$schema->hasTable('twofactor_backupcodes')) {
  43. $table = $schema->createTable('twofactor_backupcodes');
  44. $table->addColumn('id', Types::INTEGER, [
  45. 'autoincrement' => true,
  46. 'notnull' => true,
  47. 'length' => 20,
  48. ]);
  49. $table->addColumn('user_id', Types::STRING, [
  50. 'notnull' => true,
  51. 'length' => 64,
  52. ]);
  53. $table->addColumn('code', Types::STRING, [
  54. 'notnull' => true,
  55. 'length' => 64,
  56. ]);
  57. $table->addColumn('used', Types::INTEGER, [
  58. 'notnull' => true,
  59. 'length' => 1,
  60. 'default' => 0,
  61. ]);
  62. $table->setPrimaryKey(['id']);
  63. $table->addIndex(['user_id'], 'twofactor_backupcodes_uid');
  64. }
  65. return $schema;
  66. }
  67. }