1
0

Version010401Date20181207190718.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 OCA\OAuth2\Migration;
  8. use Closure;
  9. use OCP\DB\ISchemaWrapper;
  10. use OCP\Migration\IOutput;
  11. use OCP\Migration\SimpleMigrationStep;
  12. class Version010401Date20181207190718 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. */
  19. public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) {
  20. /** @var ISchemaWrapper $schema */
  21. $schema = $schemaClosure();
  22. if (!$schema->hasTable('oauth2_clients')) {
  23. $table = $schema->createTable('oauth2_clients');
  24. $table->addColumn('id', 'integer', [
  25. 'autoincrement' => true,
  26. 'notnull' => true,
  27. 'unsigned' => true,
  28. ]);
  29. $table->addColumn('name', 'string', [
  30. 'notnull' => true,
  31. 'length' => 64,
  32. ]);
  33. $table->addColumn('redirect_uri', 'string', [
  34. 'notnull' => true,
  35. 'length' => 2000,
  36. ]);
  37. $table->addColumn('client_identifier', 'string', [
  38. 'notnull' => true,
  39. 'length' => 64,
  40. ]);
  41. $table->addColumn('secret', 'string', [
  42. 'notnull' => true,
  43. 'length' => 64,
  44. ]);
  45. $table->setPrimaryKey(['id']);
  46. $table->addIndex(['client_identifier'], 'oauth2_client_id_idx');
  47. }
  48. if (!$schema->hasTable('oauth2_access_tokens')) {
  49. $table = $schema->createTable('oauth2_access_tokens');
  50. $table->addColumn('id', 'integer', [
  51. 'autoincrement' => true,
  52. 'notnull' => true,
  53. 'unsigned' => true,
  54. ]);
  55. $table->addColumn('token_id', 'integer', [
  56. 'notnull' => true,
  57. ]);
  58. $table->addColumn('client_id', 'integer', [
  59. 'notnull' => true,
  60. ]);
  61. $table->addColumn('hashed_code', 'string', [
  62. 'notnull' => true,
  63. 'length' => 128,
  64. ]);
  65. $table->addColumn('encrypted_token', 'string', [
  66. 'notnull' => true,
  67. 'length' => 786,
  68. ]);
  69. $table->setPrimaryKey(['id']);
  70. $table->addUniqueIndex(['hashed_code'], 'oauth2_access_hash_idx');
  71. $table->addIndex(['client_id'], 'oauth2_access_client_id_idx');
  72. }
  73. return $schema;
  74. }
  75. }