<?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) {
        //     //
        // });
    }
};
