<?php

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

class CreateMyTable extends Migration
{
    /**
     * Run the migrations.
     */
    public function up()
    {
        Schema::create('my_table', function (Blueprint $table) {
          
            // Obvi, increments for `id`
            $table->increments('id');
          
            // All foreign keys should be indexed
            $table->integer('account_id')->index();
          
            // All columns that *cannot* be empty should *not* be nullable or have an empty default
            $table->string('name');
          
            // All columns that *can* be empty should have nullable(), not default('')
            $table->json('codes')->nullable();
          
            // All boolean columns should have a default value
            // Booleans should always start with `is_` or `has_`
            $table->boolean('is_approval_required')->default(false);
          
            // Unit columns should include the unit
            $table->integer('job_length_minutes')->nullable();
          
            // Foreign keys to a user should end in `_by`
            $table->integer('approved_by')->index()->nullable();
          
            // Timestamps should end in `_at`
            $table->timestamp('approved_at')->nullable();
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down()
    {
        // Down migrations should exist.
      
        Schema::dropIfExists('my_table');
    }
}