1
0

Version24000Date20211213081604.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OC\Core\Migrations;
  8. use Closure;
  9. use OCP\DB\ISchemaWrapper;
  10. use OCP\DB\Types;
  11. use OCP\Migration\IOutput;
  12. use OCP\Migration\SimpleMigrationStep;
  13. class Version24000Date20211213081604 extends SimpleMigrationStep {
  14. /**
  15. * @param IOutput $output
  16. * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
  17. * @param array $options
  18. * @return null|ISchemaWrapper
  19. */
  20. public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
  21. /** @var ISchemaWrapper $schema */
  22. $schema = $schemaClosure();
  23. $hasTable = $schema->hasTable('ratelimit_entries');
  24. if (!$hasTable) {
  25. $table = $schema->createTable('ratelimit_entries');
  26. $table->addColumn('id', Types::BIGINT, [
  27. 'autoincrement' => true,
  28. 'notnull' => true,
  29. ]);
  30. $table->addColumn('hash', Types::STRING, [
  31. 'notnull' => true,
  32. 'length' => 128,
  33. ]);
  34. $table->addColumn('delete_after', Types::DATETIME, [
  35. 'notnull' => true,
  36. ]);
  37. $table->setPrimaryKey(['id']);
  38. $table->addIndex(['hash'], 'ratelimit_hash');
  39. $table->addIndex(['delete_after'], 'ratelimit_delete_after');
  40. return $schema;
  41. }
  42. return null;
  43. }
  44. }