<?php

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

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

            $table->bigInteger('user_id')->unsigned()->index();
            $table->float('amount')->index()->comment('positive or negative');
            $table->string('description', 400)->nullable();
            $table->json('meta')->nullable()->comment(' Includes some informations like loop_id, loop_group_id, etc ');

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

            $table->comment= 'Transactions and money in the user wallet';
            $table->engine = 'InnoDB';
            $table->timestamps();
            $table->softDeletes();
        });
    }

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