ahk-ch/chamb.net

View on GitHub
database/migrations/2016_02_25_190518_add_avatar_to_users_table.php

Summary

Maintainability
A
3 hrs
Test Coverage
<?php

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

class AddAvatarToUsersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('users', function (Blueprint $table) {
            $table->integer('avatar_id')->unsigned()->index()->nullable();
            $table->foreign('avatar_id')->references('id')->on('files')->onDelete('restrict')->onUpdate('cascade');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('users', function (Blueprint $table) {
            $table->dropForeign('users_avatar_id_foreign');
            $table->dropIndex('users_avatar_id_index');
            $table->removeColumn('avatar_id');
        });
    }
}