fix(perf): resolve F-13 — add database indexes on joined/filtered columns

This commit is contained in:
root
2026-05-28 16:27:45 +08:00
parent 968c1e626f
commit c863f6f81b

View File

@@ -0,0 +1,60 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::table('rainfall', function (Blueprint $table) {
$table->index('stationid', 'rainfall_stationid_index');
$table->index('timestamp', 'rainfall_timestamp_index');
$table->index(['stationid', 'timestamp'], 'rainfall_stationid_timestamp_index');
});
Schema::table('waterlevel', function (Blueprint $table) {
$table->index('stationid', 'waterlevel_stationid_index');
$table->index('datetime', 'waterlevel_datetime_index');
$table->index(['stationid', 'datetime'], 'waterlevel_stationid_datetime_index');
});
Schema::table('notification', function (Blueprint $table) {
$table->index('stationid', 'notification_stationid_index');
$table->index('timestamp', 'notification_timestamp_index');
$table->index('stationtype', 'notification_stationtype_index');
});
Schema::table('siren', function (Blueprint $table) {
$table->index('stationid', 'siren_stationid_index');
$table->index('active_time', 'siren_active_time_index');
});
}
public function down(): void
{
Schema::table('rainfall', function (Blueprint $table) {
$table->dropIndex('rainfall_stationid_timestamp_index');
$table->dropIndex('rainfall_timestamp_index');
$table->dropIndex('rainfall_stationid_index');
});
Schema::table('waterlevel', function (Blueprint $table) {
$table->dropIndex('waterlevel_stationid_datetime_index');
$table->dropIndex('waterlevel_datetime_index');
$table->dropIndex('waterlevel_stationid_index');
});
Schema::table('notification', function (Blueprint $table) {
$table->dropIndex('notification_stationtype_index');
$table->dropIndex('notification_timestamp_index');
$table->dropIndex('notification_stationid_index');
});
Schema::table('siren', function (Blueprint $table) {
$table->dropIndex('siren_active_time_index');
$table->dropIndex('siren_stationid_index');
});
}
};