ejaculations.sourceはNULL非許容にする

This commit is contained in:
shibafu 2020-05-24 19:39:24 +09:00
parent 00f75f33cc
commit e2f01561a8
3 changed files with 36 additions and 1 deletions

View File

@ -17,7 +17,7 @@ class Ejaculation extends Model
protected $fillable = [
'user_id', 'ejaculated_date',
'note', 'geo_latitude', 'geo_longitude', 'link',
'note', 'geo_latitude', 'geo_longitude', 'link', 'source',
'is_private', 'is_too_sensitive'
];

View File

@ -57,6 +57,7 @@ class EjaculationController extends Controller
'ejaculated_date' => Carbon::createFromFormat('Y/m/d H:i', $inputs['date'] . ' ' . $inputs['time']),
'note' => $inputs['note'] ?? '',
'link' => $inputs['link'] ?? '',
'source' => Ejaculation::SOURCE_WEB,
'is_private' => $request->has('is_private') ?? false,
'is_too_sensitive' => $request->has('is_too_sensitive') ?? false
]);

View File

@ -0,0 +1,34 @@
<?php
use App\Ejaculation;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class MakeNonNullableSourceOnEjaculations extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
DB::statement('UPDATE ejaculations SET source = ? WHERE source IS NULL', [Ejaculation::SOURCE_WEB]);
Schema::table('ejaculations', function (Blueprint $table) {
$table->string('source')->nullable(false)->change();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('ejaculations', function (Blueprint $table) {
$table->string('source')->nullable()->change();
});
}
}