badgeteam/Hatchery

View on GitHub
database/migrations/2017_06_13_142609_alter_files_and_versions_add_user_id.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php

declare(strict_types=1);

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

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

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table(
            'versions',
            function (Blueprint $table) {
                $table->dropForeign(['user_id']);
                $table->dropColumn('user_id');
            }
        );
        Schema::table(
            'files',
            function (Blueprint $table) {
                $table->dropForeign(['user_id']);
                $table->dropColumn('user_id');
            }
        );
    }
}