<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class AddOpeningPurchaseIdToProducts extends Migration
{
    public function up()
    {
        if (!Schema::hasColumn('products', 'opening_purchase_id')) {
            Schema::table('products', function (Blueprint $table) {
                $table->unsignedInteger('opening_purchase_id')->nullable()->after('measurement_type');
            });
        }
    }

    public function down()
    {
        if (Schema::hasColumn('products', 'opening_purchase_id')) {
            Schema::table('products', function (Blueprint $table) {
                $table->dropColumn('opening_purchase_id');
            });
        }
    }
}
