Changeset View
Standalone View
src/database/migrations/2021_12_28_103243_create_policy_ratelimit_tables.php
- This file was added.
<?php | |||||
use Illuminate\Database\Migrations\Migration; | |||||
use Illuminate\Database\Schema\Blueprint; | |||||
use Illuminate\Support\Facades\Schema; | |||||
// phpcs:ignore | |||||
class CreatePolicyRatelimitTables extends Migration | |||||
{ | |||||
/** | |||||
* Run the migrations. | |||||
* | |||||
* @return void | |||||
*/ | |||||
public function up() | |||||
{ | |||||
Schema::create( | |||||
'policy_ratelimit', | |||||
function (Blueprint $table) { | |||||
$table->bigIncrements('id'); | |||||
$table->bigInteger('user_id'); | |||||
$table->bigInteger('owner_id'); | |||||
$table->string('recipient_hash', 128); | |||||
$table->tinyInteger('recipient_count')->unsigned(); | |||||
$table->timestamps(); | |||||
machniak: It could be unsignedTinyInteger | |||||
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); | |||||
$table->foreign('owner_id')->references('id')->on('users')->onDelete('cascade'); | |||||
$table->index(['user_id', 'updated_at']); | |||||
$table->index(['owner_id', 'updated_at']); | |||||
$table->index(['user_id', 'recipient_hash', 'updated_at']); | |||||
} | |||||
Done Inline Actionsperhaps make this unique? mollekopf: perhaps make this unique? | |||||
Done Inline ActionsIf a user_id-hash-updated is older than one hour, the record will not have been found by the time we need to insert the new one. A unique constraint would prevent this from completing successfully. vanmeeuwen: If a user_id-hash-updated is older than one hour, the record will not have been found by the… | |||||
); | |||||
Schema::create( | |||||
'policy_ratelimit_wl', | |||||
function (Blueprint $table) { | |||||
Done Inline Actionswhy wl not whitelist? machniak: why `wl` not `whitelist`? | |||||
Done Inline Actionstable name length limitations. vanmeeuwen: table name length limitations. | |||||
$table->bigIncrements('id'); | |||||
$table->bigInteger('whitelistable_id'); | |||||
$table->string('whitelistable_type'); | |||||
$table->timestamps(); | |||||
$table->index(['whitelistable_id', 'whitelistable_type']); | |||||
$table->unique(['whitelistable_id', 'whitelistable_type']); | |||||
Done Inline ActionsIsn't this redundant if you define a unique key below? machniak: Isn't this redundant if you define a unique key below? | |||||
Done Inline ActionsIt isn't. unique constraints' primary purpose is an upon-write restriction, incidentally using some sort of index for duplicate detection purposes, but the type of index can be very bespoke to its use-case (i.e. a list of hash('sha256, '$a.$b') would do it). indexes primary purpose is an upon-read helper with selecting particular records, including range queries and sub-string matches (i.e. a unique constraint duplicate detection table like the one does not help looking up any records). it uses far more complicated routines that are in turn sub-optimal for unique constraints. vanmeeuwen: It isn't.
unique constraints' primary purpose is an upon-write restriction, incidentally using… | |||||
} | |||||
); | |||||
} | |||||
/** | |||||
* Reverse the migrations. | |||||
* | |||||
* @return void | |||||
*/ | |||||
public function down() | |||||
{ | |||||
Schema::dropIfExists('policy_ratelimit'); | |||||
Schema::dropIfExists('policy_ratelimit_wl'); | |||||
} | |||||
} |
It could be unsignedTinyInteger