diff options
author | Lukas Reschke <lukas@statuscode.ch> | 2021-09-06 16:31:01 +0200 |
---|---|---|
committer | Lukas Reschke <lukas@statuscode.ch> | 2021-09-06 16:31:01 +0200 |
commit | d4f97affc1a0ecfaacfbdc26aab820cad1650a06 (patch) | |
tree | aa77abd5adf02edd735159cc3c0c07cf7fd4c847 /core/Migrations/Version23000Date20210906132259.php | |
parent | 33a0b75c83a1c56fa84b98d3a07a26b5c4932b65 (diff) | |
download | nextcloud-server-d4f97affc1a0ecfaacfbdc26aab820cad1650a06.tar.gz nextcloud-server-d4f97affc1a0ecfaacfbdc26aab820cad1650a06.zip |
Add database ratelimiting backend
In case no distributed memory cache is specified this adds
a database backend for ratelimit purposes.
Signed-off-by: Lukas Reschke <lukas@statuscode.ch>
Diffstat (limited to 'core/Migrations/Version23000Date20210906132259.php')
-rw-r--r-- | core/Migrations/Version23000Date20210906132259.php | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/core/Migrations/Version23000Date20210906132259.php b/core/Migrations/Version23000Date20210906132259.php new file mode 100644 index 00000000000..b0eb7bc4dcc --- /dev/null +++ b/core/Migrations/Version23000Date20210906132259.php @@ -0,0 +1,47 @@ +<?php + +declare(strict_types=1); + +namespace OC\Core\Migrations; + +use Closure; +use OCP\DB\ISchemaWrapper; +use OCP\DB\Types; +use OCP\Migration\IOutput; +use OCP\Migration\SimpleMigrationStep; + +/** + * Auto-generated migration step: Please modify to your needs! + */ +class Version23000Date20210906132259 extends SimpleMigrationStep { + private const TABLE_NAME = 'ratelimit_entries'; + + /** + * @param IOutput $output + * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` + * @param array $options + * @return null|ISchemaWrapper + */ + public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { + /** @var ISchemaWrapper $schema */ + $schema = $schemaClosure(); + + $hasTable = $schema->hasTable(self::TABLE_NAME); + + if(!$hasTable) + { + $table = $schema->createTable(self::TABLE_NAME); + $table->addColumn('hash', Types::STRING, [ + 'notnull' => true, + 'length' => 128, + ]); + $table->addColumn('timestamp', 'datetime', [ + 'notnull' => true, + ]); + $table->addIndex(['hash'], 'ratelimit_hash_idx'); + $table->addIndex(['timestamp'], 'ratelimit_timestamp_idx'); + } + + return $schema; + } +} |