1
0

Version1002Date20170607104347.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\TwoFactorBackupCodes\Migration;
  8. use Doctrine\DBAL\Types\Types;
  9. use OCP\DB\ISchemaWrapper;
  10. use OCP\Migration\IOutput;
  11. use OCP\Migration\SimpleMigrationStep;
  12. class Version1002Date20170607104347 extends SimpleMigrationStep {
  13. /**
  14. * @param IOutput $output
  15. * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
  16. * @param array $options
  17. * @return null|ISchemaWrapper
  18. * @since 13.0.0
  19. */
  20. public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) {
  21. /** @var ISchemaWrapper $schema */
  22. $schema = $schemaClosure();
  23. if (!$schema->hasTable('twofactor_backupcodes')) {
  24. $table = $schema->createTable('twofactor_backupcodes');
  25. $table->addColumn('id', Types::INTEGER, [
  26. 'autoincrement' => true,
  27. 'notnull' => true,
  28. 'length' => 20,
  29. ]);
  30. $table->addColumn('user_id', Types::STRING, [
  31. 'notnull' => true,
  32. 'length' => 64,
  33. ]);
  34. $table->addColumn('code', Types::STRING, [
  35. 'notnull' => true,
  36. 'length' => 64,
  37. ]);
  38. $table->addColumn('used', Types::INTEGER, [
  39. 'notnull' => true,
  40. 'length' => 1,
  41. 'default' => 0,
  42. ]);
  43. $table->setPrimaryKey(['id']);
  44. $table->addIndex(['user_id'], 'twofactor_backupcodes_uid');
  45. }
  46. return $schema;
  47. }
  48. }