phpvms/app/Database/seeds/DatabaseSeeder.php

50 lines
1.1 KiB
PHP
Raw Normal View History

2017-06-09 02:28:26 +08:00
<?php
use App\Services\DatabaseService;
2017-06-09 02:28:26 +08:00
use Illuminate\Database\Seeder;
class DatabaseSeeder extends Seeder
{
private static $seed_mapper = [
'local' => 'dev',
'qa' => 'dev',
'staging' => 'dev',
];
private static $always_seed = [
'permissions',
];
2017-06-09 02:28:26 +08:00
/**
* Run the database seeds.
2018-08-27 00:40:04 +08:00
*
* @throws Exception
2017-06-09 02:28:26 +08:00
*/
public function run()
{
$env = App::environment();
if (array_key_exists($env, self::$seed_mapper)) {
$env = self::$seed_mapper[$env];
}
Log::info('Seeding from environment '.$env);
2017-06-20 00:50:25 +08:00
$path = database_path('seeds/'.$env.'.yml');
if (!file_exists($path)) {
$path = database_path('seeds/prod.yml');
2017-06-20 00:50:25 +08:00
}
$svc = app(DatabaseService::class);
2017-06-25 02:20:24 +08:00
$svc->seed_from_yaml_file($path);
// Always seed/sync these
foreach (self::$always_seed as $file) {
Log::info('Importing '.$file);
$path = database_path('seeds/'.$file.'.yml');
if (file_exists($path)) {
$svc->seed_from_yaml_file($path);
}
}
}
2017-06-09 02:28:26 +08:00
}