chore: clean up seeders

This commit is contained in:
Phan An 2019-11-29 21:50:59 +01:00
parent 4dabfd1c6f
commit 872764da5a
7 changed files with 7 additions and 84 deletions

View file

@ -20,7 +20,7 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
* @property Collection $songs
* @property bool $is_unknown
*
* @method static self firstOrCreate(array $params)
* @method static self firstOrCreate(array $where, array $params)
*/
class Album extends Model
{

View file

@ -6,12 +6,11 @@ use Illuminate\Database\Seeder;
class AlbumTableSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run()
{
Album::create([
Album::firstOrCreate([
'id' => Album::UNKNOWN_ID
], [
'id' => Album::UNKNOWN_ID,
'artist_id' => Artist::UNKNOWN_ID,
'name' => Album::UNKNOWN_NAME,

View file

@ -5,12 +5,11 @@ use Illuminate\Database\Seeder;
class ArtistTableSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run()
{
Artist::create([
Artist::firstOrCreate([
'id' => Artist::UNKNOWN_ID
], [
'id' => Artist::UNKNOWN_ID,
'name' => Artist::UNKNOWN_NAME,
]);

View file

@ -5,16 +5,10 @@ use Illuminate\Database\Seeder;
class DatabaseSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run()
{
Model::unguard();
// This must be run first, to check for dependencies
// $this->call(UserTableSeeder::class);
$this->call(ArtistTableSeeder::class);
$this->call(AlbumTableSeeder::class);
$this->call(SettingTableSeeder::class);

View file

@ -1,26 +0,0 @@
<?php
use App\Models\Album;
use App\Models\Artist;
use App\Models\Song;
use Illuminate\Database\Seeder;
class E2EDataSeeder extends Seeder
{
private $sampleSongFullPath;
public function run()
{
$this->sampleSongFullPath = realpath(__DIR__.'/../../tests/songs/full.mp3');
factory(Artist::class, 20)->create()->each(function (Artist $artist) {
factory(Album::class, 5)->create([
'artist_id' => $artist->id,
])->each(function (Album $album) {
factory(Song::class, 10)->create([
'album_id' => $album->id,
]);
});
});
}
}

View file

@ -5,11 +5,6 @@ use Illuminate\Database\Seeder;
class SettingTableSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
Setting::set('media_path', '');

View file

@ -1,38 +0,0 @@
<?php
use App\Models\User;
use Illuminate\Database\Seeder;
class UserTableSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run()
{
User::create($this->getUserDetails() + [
'is_admin' => true,
]);
if (!app()->runningUnitTests()) {
$this->command->info('Admin user created. You can (and should) remove the auth details from .env now.');
}
}
protected function getUserDetails()
{
$details = array_filter(array_only(config('koel.admin', []), [
'name', 'email', 'password',
]));
if (count($details) !== 3) {
$this->command->error('Please fill in initial admin details in .env file first.');
abort(422);
}
$details['password'] = Hash::make($details['password']);
return $details;
}
}