32 lines
1.1 KiB
PHP
32 lines
1.1 KiB
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('commands', function (Blueprint $table) {
|
|
$table->id();
|
|
$table->uuid()->unique();
|
|
$table->foreignId('device_id')->constrained()->cascadeOnDelete();
|
|
$table->foreignId('entity_id')->nullable()->constrained()->nullOnDelete();
|
|
$table->string('source'); // user | automation | physical
|
|
$table->foreignId('user_id')->nullable()->constrained()->nullOnDelete();
|
|
$table->string('command'); // turn_on | turn_off | reboot | …
|
|
$table->json('payload')->nullable();
|
|
$table->string('result')->nullable(); // ok | error: …
|
|
$table->timestamps();
|
|
|
|
$table->index(['device_id', 'created_at']);
|
|
});
|
|
}
|
|
|
|
public function down(): void
|
|
{
|
|
Schema::dropIfExists('commands');
|
|
}
|
|
};
|