20 lines
687 B
PHP
20 lines
687 B
PHP
|
|
<?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::create('readings', function (Blueprint $t) {
|
||
|
|
$t->bigIncrements('id');
|
||
|
|
$t->foreignId('device_id')->constrained('devices')->cascadeOnDelete();
|
||
|
|
$t->string('metric',60);
|
||
|
|
$t->decimal('value',10,3)->nullable();
|
||
|
|
$t->string('value_text',50)->nullable();
|
||
|
|
$t->timestamp('recorded_at',3);
|
||
|
|
$t->index(['device_id','metric','recorded_at'],'idx_dmt');
|
||
|
|
$t->index('recorded_at','idx_rec');
|
||
|
|
});
|
||
|
|
}
|
||
|
|
public function down(): void { Schema::dropIfExists('readings'); }
|
||
|
|
};
|