土壤监测日志模型和数据库迁移
parent
df71aeb945
commit
370c3aaaf3
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class SoilMonitoringLog extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $casts = [
|
||||
'monitored_at' => 'datetime',
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
'device_id',
|
||||
'agricultural_base_id',
|
||||
'conductivity',
|
||||
'humidity',
|
||||
'temperature',
|
||||
'n',
|
||||
'p',
|
||||
'k',
|
||||
'monitored_at',
|
||||
];
|
||||
}
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('soil_monitoring_logs', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('device_id')->comment('设备ID');
|
||||
$table->unsignedBigInteger('agricultural_base_id')->comment('农业基地ID');
|
||||
$table->decimal('conductivity', 8, 2)->nullable()->comment('电导率 (单位: us/cm)');
|
||||
$table->decimal('humidity', 8, 2)->nullable()->comment('湿度 (单位: %RH)');
|
||||
$table->decimal('temperature', 8, 2)->nullable()->comment('温度 (单位: ℃)');
|
||||
$table->integer('n')->nullable()->comment('氮 (单位: mg/kg)');
|
||||
$table->integer('p')->nullable()->comment('磷 (单位: mg/kg)');
|
||||
$table->integer('k')->nullable()->comment('钾 (单位: mg/kg)');
|
||||
$table->timestamp('monitored_at')->comment('监控时间(小时)');
|
||||
$table->timestamps();
|
||||
|
||||
// 索引
|
||||
$table->index('device_id');
|
||||
$table->index('agricultural_base_id');
|
||||
$table->unique('monitored_at');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('soil_monitoring_logs');
|
||||
}
|
||||
};
|
||||
Loading…
Reference in New Issue