2017-06-09 02:28:26 +08:00
|
|
|
<?php
|
|
|
|
|
2018-09-03 01:18:32 +08:00
|
|
|
use App\Services\DatabaseService;
|
2017-06-09 02:28:26 +08:00
|
|
|
use Illuminate\Database\Seeder;
|
|
|
|
|
|
|
|
class DatabaseSeeder extends Seeder
|
|
|
|
{
|
2017-12-05 05:35:39 +08:00
|
|
|
/**
|
|
|
|
* Map these other environments to a specific seed file
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
2017-12-05 05:35:39 +08:00
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
public static $seed_mapper = [
|
2018-03-20 09:50:40 +08:00
|
|
|
'local' => 'dev',
|
|
|
|
'qa' => 'dev',
|
|
|
|
'staging' => 'dev',
|
2017-12-05 05:35:39 +08:00
|
|
|
];
|
|
|
|
|
2017-06-09 02:28:26 +08:00
|
|
|
/**
|
|
|
|
* Run the database seeds.
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
2018-03-31 11:28:19 +08:00
|
|
|
* @throws Exception
|
2017-06-09 02:28:26 +08:00
|
|
|
*/
|
|
|
|
public function run()
|
|
|
|
{
|
2017-06-25 01:59:07 +08:00
|
|
|
$env = App::environment();
|
2018-03-20 09:50:40 +08:00
|
|
|
if (array_key_exists($env, self::$seed_mapper)) {
|
2017-12-05 05:35:39 +08:00
|
|
|
$env = self::$seed_mapper[$env];
|
|
|
|
}
|
|
|
|
|
2017-06-20 00:50:25 +08:00
|
|
|
$path = database_path('seeds/'.$env.'.yml');
|
2017-12-03 14:48:33 +08:00
|
|
|
|
2018-03-20 09:50:40 +08:00
|
|
|
if (!file_exists($path)) {
|
2017-07-14 07:09:08 +08:00
|
|
|
$path = database_path('seeds/prod.yml');
|
2017-06-20 00:50:25 +08:00
|
|
|
}
|
2017-06-25 01:59:07 +08:00
|
|
|
|
2018-09-03 01:18:32 +08:00
|
|
|
$svc = app(DatabaseService::class);
|
2017-06-25 02:20:24 +08:00
|
|
|
$svc->seed_from_yaml_file($path);
|
2017-06-12 00:36:16 +08:00
|
|
|
}
|
2017-06-09 02:28:26 +08:00
|
|
|
}
|