mirror of
https://github.com/koel/koel
synced 2024-11-12 23:47:09 +00:00
chore: clean up seeders
This commit is contained in:
parent
4dabfd1c6f
commit
872764da5a
7 changed files with 7 additions and 84 deletions
|
@ -20,7 +20,7 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
* @property Collection $songs
|
* @property Collection $songs
|
||||||
* @property bool $is_unknown
|
* @property bool $is_unknown
|
||||||
*
|
*
|
||||||
* @method static self firstOrCreate(array $params)
|
* @method static self firstOrCreate(array $where, array $params)
|
||||||
*/
|
*/
|
||||||
class Album extends Model
|
class Album extends Model
|
||||||
{
|
{
|
||||||
|
|
|
@ -6,12 +6,11 @@ use Illuminate\Database\Seeder;
|
||||||
|
|
||||||
class AlbumTableSeeder extends Seeder
|
class AlbumTableSeeder extends Seeder
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* Run the database seeds.
|
|
||||||
*/
|
|
||||||
public function run()
|
public function run()
|
||||||
{
|
{
|
||||||
Album::create([
|
Album::firstOrCreate([
|
||||||
|
'id' => Album::UNKNOWN_ID
|
||||||
|
], [
|
||||||
'id' => Album::UNKNOWN_ID,
|
'id' => Album::UNKNOWN_ID,
|
||||||
'artist_id' => Artist::UNKNOWN_ID,
|
'artist_id' => Artist::UNKNOWN_ID,
|
||||||
'name' => Album::UNKNOWN_NAME,
|
'name' => Album::UNKNOWN_NAME,
|
||||||
|
|
|
@ -5,12 +5,11 @@ use Illuminate\Database\Seeder;
|
||||||
|
|
||||||
class ArtistTableSeeder extends Seeder
|
class ArtistTableSeeder extends Seeder
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* Run the database seeds.
|
|
||||||
*/
|
|
||||||
public function run()
|
public function run()
|
||||||
{
|
{
|
||||||
Artist::create([
|
Artist::firstOrCreate([
|
||||||
|
'id' => Artist::UNKNOWN_ID
|
||||||
|
], [
|
||||||
'id' => Artist::UNKNOWN_ID,
|
'id' => Artist::UNKNOWN_ID,
|
||||||
'name' => Artist::UNKNOWN_NAME,
|
'name' => Artist::UNKNOWN_NAME,
|
||||||
]);
|
]);
|
||||||
|
|
|
@ -5,16 +5,10 @@ use Illuminate\Database\Seeder;
|
||||||
|
|
||||||
class DatabaseSeeder extends Seeder
|
class DatabaseSeeder extends Seeder
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* Run the database seeds.
|
|
||||||
*/
|
|
||||||
public function run()
|
public function run()
|
||||||
{
|
{
|
||||||
Model::unguard();
|
Model::unguard();
|
||||||
|
|
||||||
// This must be run first, to check for dependencies
|
|
||||||
// $this->call(UserTableSeeder::class);
|
|
||||||
|
|
||||||
$this->call(ArtistTableSeeder::class);
|
$this->call(ArtistTableSeeder::class);
|
||||||
$this->call(AlbumTableSeeder::class);
|
$this->call(AlbumTableSeeder::class);
|
||||||
$this->call(SettingTableSeeder::class);
|
$this->call(SettingTableSeeder::class);
|
||||||
|
|
|
@ -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,
|
|
||||||
]);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -5,11 +5,6 @@ use Illuminate\Database\Seeder;
|
||||||
|
|
||||||
class SettingTableSeeder extends Seeder
|
class SettingTableSeeder extends Seeder
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* Run the database seeds.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function run()
|
public function run()
|
||||||
{
|
{
|
||||||
Setting::set('media_path', '');
|
Setting::set('media_path', '');
|
||||||
|
|
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue