FEATURE: make user id not mandatory in widgets table

This commit is contained in:
Michal Kváček
2016-09-25 00:19:20 +02:00
parent d5950d9cd7
commit 00d7bd562c
@@ -0,0 +1,55 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class MakeUserIdNullableAtWidgets extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('widgets', function (Blueprint $table) {
$table->dropForeign(['user_id']);
$table->integer('user_id')
->nullable(true)
->default(null)
->comment('User ID who created this widget. NULL for widget created by template.')->change();
$table->foreign('user_id')
->references('id')
->on('users')
->onDelete('cascade')
->onUpdate('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('widgets', function (Blueprint $table) {
$table->dropForeign(['user_id']);
});
Schema::table('widgets', function (Blueprint $table) {
$table->integer('user_id')
->nullable(false)
->comment('User ID who created this widget. ')->change();
$table->foreign('user_id')
->references('id')
->on('users')
->onDelete('no action')
->onUpdate('no action');
});
}
}