2 Commits

Author SHA1 Message Date
dhanabalan
77129cb70b Added mfm meter model file 2025-07-31 16:30:59 +05:30
dhanabalan
bb462a6c45 Added foreign and unique key for mfm_meters table 2025-07-31 16:30:04 +05:30
2 changed files with 46 additions and 0 deletions

View File

@@ -13,6 +13,7 @@ class MfmMeter extends Model
protected $fillable = [
'plant_id',
'device_master_id',
'sequence',
'name',
'created_at',
@@ -24,4 +25,9 @@ class MfmMeter extends Model
{
return $this->belongsTo(Plant::class);
}
public function devicemaster(): BelongsTo
{
return $this->belongsTo(DeviceMaster::class, 'device_master_id');
}
}

View File

@@ -0,0 +1,40 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
$sql = <<<'SQL'
ALTER TABLE mfm_meters
ADD COLUMN device_master_id BIGINT NOT NULL,
ADD CONSTRAINT mfm_meters_device_master_id_fkey
FOREIGN KEY (device_master_id) REFERENCES device_masters(id);
SQL;
DB::statement($sql);
$sql1 = <<<'SQL'
ALTER TABLE mfm_meters
ADD UNIQUE (plant_id, device_master_id, name);
SQL;
DB::statement($sql1);
}
/**
* Reverse the migrations.
*/
public function down(): void
{
// Schema::table('mfm_meters', function (Blueprint $table) {
// //
// });
}
};