Merge pull request #359 from shikorism/fix/ej-source-nonnull

ejaculations.sourceはNULL非許容にする
This commit is contained in:
shibafu 2020-05-24 21:22:13 +09:00 committed by GitHub
commit 0218035aeb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 46 additions and 3 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'
];
@ -49,8 +49,7 @@ class Ejaculation extends Model
public function scopeOnlyWebCheckin(Builder $query)
{
return $query->where('ejaculations.source', null)
->orWhere('ejaculations.source', '<>', Ejaculation::SOURCE_CSV);
return $query->where('ejaculations.source', Ejaculation::SOURCE_WEB);
}
public function scopeWithLikes(Builder $query)

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

@ -8,5 +8,6 @@ $factory->define(Ejaculation::class, function (Faker $faker) {
return [
'ejaculated_date' => $faker->date('Y-m-d H:i:s'),
'note' => $faker->text,
'source' => Ejaculation::SOURCE_WEB,
];
});

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();
});
}
}

View File

@ -13,6 +13,14 @@ use Tests\TestCase;
class SettingTest extends TestCase
{
use RefreshDatabase;
protected function setUp(): void
{
parent::setUp();
$this->seed();
}
public function testDestroyUser()
{
$user = factory(User::class)->create();