<?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('records_rows', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('record_id')->nullable();
            $table->foreign('record_id')->nullable()->references('id')->on('records')->onUpdate('cascade')->onDelete('cascade');
            $table->unsignedBigInteger('causal_id');
            $table->foreign('causal_id')->nullable()->references('id')->on('causals')->onUpdate('cascade')->onDelete('cascade');
            $table->json('when')->nullable();
            $table->integer('commercial')->default(1);
            $table->decimal('amount', $precision = 8, $scale = 2);
            $table->string('note')->nullable();
            $table->softDeletes();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('records_rows');
    }
};
