<?php

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

class CreateUserCreditMarginsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('user_credit_margins', function (Blueprint $table) {
            $table->id();

            $table->unsignedInteger('user_id');
            
            $table->decimal('credit', 13, 2)->nullable();
            $table->text('message')->nullable();
            $table->unsignedTinyInteger('status')->index()->default(0);
            $table->boolean('paid')->default(false);
            $table->unsignedBigInteger('user_credit_id')->nullable();

            $table->timestamps();

            $table->foreign('user_id')
                ->references('id')
                ->on('users');

        });
    }

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