Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue/329 refactor seeding #337

Merged
merged 3 commits into from
Aug 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions app/Console/Commands/DevInstall.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ class DevInstall extends Command
'acars.yml',
];

private $databaseSeeder;

public function __construct(\DatabaseSeeder $databaseSeeder)
{
parent::__construct();
$this->databaseSeeder = $databaseSeeder;
}

/**
* Run dev related commands
*
Expand All @@ -45,16 +53,6 @@ public function handle()
'--seed' => true,
]);

//
//

$this->info('Importing sample data');
foreach ($this->yaml_imports as $yml) {
$this->call('phpvms:yaml-import', [
'files' => ['app/Database/seeds/'.$yml],
]);
}

$this->info('Done!');
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<?php

use App\Contracts\Migration;
use App\Services\Installer\MigrationService;
use App\Services\Installer\SeederService;
use Illuminate\Database\Schema\Blueprint;

class CreateSettingsTable extends Migration
{
private $migrationSvc;
private $seederSvc;

public function __construct()
{
$this->migrationSvc = new MigrationService();
$this->seederSvc = app(SeederService::class);
}

/**
Expand Down Expand Up @@ -38,7 +38,7 @@ public function up()
$table->timestamps();
});

$this->migrationSvc->syncAllSettings();
$this->seederSvc->syncAllSettings();
}

/**
Expand Down
15 changes: 0 additions & 15 deletions app/Database/migrations/2017_06_21_165410_create_ranks_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,6 @@ public function up()

$table->unique('name');
});

/**
* Initial required data...
*/
$ranks = [
[
'id' => 1,
'name' => 'New Pilot',
'hours' => 0,
'acars_base_pay_rate' => 50,
'manual_base_pay_rate' => 25,
],
];

$this->addData('ranks', $ranks);
}

/**
Expand Down
39 changes: 7 additions & 32 deletions app/Database/seeds/DatabaseSeeder.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
<?php

use App\Services\DatabaseService;
use App\Services\Installer\SeederService;
use Illuminate\Database\Seeder;

class DatabaseSeeder extends Seeder
{
private static $seed_mapper = [
'local' => 'dev',
'qa' => 'dev',
'staging' => 'dev',
];
private $seederService;

private static $always_seed = [
'permissions',
];
public function __construct()
{
$this->seederService = app(SeederService::class);
}

/**
* Run the database seeds.
Expand All @@ -22,28 +19,6 @@ class DatabaseSeeder extends Seeder
*/
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);
$path = database_path('seeds/'.$env.'.yml');

if (!file_exists($path)) {
$path = database_path('seeds/prod.yml');
}

$svc = app(DatabaseService::class);
$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);
}
}
$this->seederService->syncAllSeeds();
}
}
55 changes: 0 additions & 55 deletions app/Database/seeds/acars.yml

This file was deleted.

57 changes: 57 additions & 0 deletions app/Database/seeds/dev/acars.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
acars:
id_column: id
data:
- id: acars_1
pirep_id: pirepid_1
type: 1
nav_type: 2
name: TNV
lat: 30.28852
lon: -96.058239
created_at: now
updated_at: now
- id: acars_2
pirep_id: pirepid_1
type: 1
nav_type: 2
name: IAH
lat: 29.95691
lon: -95.345719
created_at: now
updated_at: now
- id: acars_3
pirep_id: pirepid_1
type: 1
nav_type: 2
name: LCH
lat: 30.14151
lon: -93.105569
created_at: now
updated_at: now
- id: acars_4
pirep_id: pirepid_1
type: 1
nav_type: 2
name: MEI
lat: 32.37843
lon: -88.804267
created_at: now
updated_at: now
- id: acars_5
pirep_id: pirepid_1
type: 1
nav_type: 2
name: ATL
lat: 33.62907
lon: -84.435064
created_at: now
updated_at: now
- id: acars_6
pirep_id: pirepid_1
type: 1
nav_type: 2
name: SIE
lat: 39.0955
lon: -74.800344
created_at: now
updated_at: now
File renamed without changes.
26 changes: 26 additions & 0 deletions app/Database/seeds/dev/ranks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
ranks:
- id: 1
name: New Pilot
hours: 0
acars_base_pay_rate: 50
manual_base_pay_rate: 25
- id: 2
name: Junior First Officer
hours: 10
acars_base_pay_rate: 100
manual_base_pay_rate: 90
- id: 3
name: First Officer
hours: 15
acars_base_pay_rate: 250
manual_base_pay_rate: 200
auto_approve_acars: 1
auto_approve_manual: 1
- id: 4
name: Senior Captain
hours: 20
acars_base_pay_rate: 500
manual_base_pay_rate: 400
auto_approve_acars: 1
auto_approve_manual: 1
auto_promote: 0
47 changes: 13 additions & 34 deletions app/Database/seeds/sample.yml → app/Database/seeds/dev/sample.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@

airlines:
- id: 1
icao: VMS
iata: VM
name: phpvms airlines
country: us
active: 1
created_at: now
updated_at: now
#airlines:
# - id: 1
# icao: VMS
# iata: VM
# name: phpvms airlines
# country: us
# active: 1
# created_at: now
# updated_at: now

roles:
- name: fleet-only
display_name: Edit Fleet
id_column: name
data:
- name: fleet-only
display_name: Edit Fleet

users:
- id: 1
Expand Down Expand Up @@ -83,29 +85,6 @@ role_user:
role_id: 2
user_type: App\Models\User

# ranks
ranks:
- id: 2
name: Junior First Officer
hours: 10
acars_base_pay_rate: 100
manual_base_pay_rate: 90
- id: 3
name: First Officer
hours: 15
acars_base_pay_rate: 250
manual_base_pay_rate: 200
auto_approve_acars: 1
auto_approve_manual: 1
- id: 4
name: Senior Captain
hours: 20
acars_base_pay_rate: 500
manual_base_pay_rate: 400
auto_approve_acars: 1
auto_approve_manual: 1
auto_promote: 0

awards:
- id: 1
name: Pilot 50 flights
Expand Down
Loading