<?php

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

class CreateLoopGroupUserPaidsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('loop_group_user_paids', function (Blueprint $table) {
            $table->id();
            $table->bigInteger('loop_group_user_id')->unsigned()->index();
            $table->tinyInteger('month')->index();
            $table->boolean('done')->comment(' false for paid month when user withdrawed before got cashed ')->index();
            $table->timestamp('created_at');

            $table->foreign('loop_group_user_id')->references('id')->on('loop_group_users')->onDelete('cascade')->onUpdate('cascade');

            // Set engine to InnoDB it's useful in join and constraint
            $table->engine = 'InnoDB';
        });
    }

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