You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Version23000Date20210906132259.php 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. declare(strict_types=1);
  3. namespace OC\Core\Migrations;
  4. use Closure;
  5. use OCP\DB\ISchemaWrapper;
  6. use OCP\DB\Types;
  7. use OCP\Migration\IOutput;
  8. use OCP\Migration\SimpleMigrationStep;
  9. /**
  10. * Auto-generated migration step: Please modify to your needs!
  11. */
  12. class Version23000Date20210906132259 extends SimpleMigrationStep {
  13. private const TABLE_NAME = 'ratelimit_entries';
  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(self::TABLE_NAME);
  24. if(!$hasTable)
  25. {
  26. $table = $schema->createTable(self::TABLE_NAME);
  27. $table->addColumn('hash', Types::STRING, [
  28. 'notnull' => true,
  29. 'length' => 128,
  30. ]);
  31. $table->addColumn('timestamp', 'datetime', [
  32. 'notnull' => true,
  33. ]);
  34. $table->addIndex(['hash'], 'ratelimit_hash_idx');
  35. $table->addIndex(['timestamp'], 'ratelimit_timestamp_idx');
  36. }
  37. return $schema;
  38. }
  39. }