Move seed data into separate file with importer; fix admin panel js being broken

This commit is contained in:
Nabeel Shahzad
2017-12-29 17:34:09 -06:00
parent 7cd4bf5ffb
commit 520751b151
17 changed files with 10292 additions and 922 deletions

View File

@@ -11,17 +11,9 @@ use App\Models\Pirep;
class DevCommands extends BaseCommand
{
protected $signature = 'phpvms {cmd} {--file=?}';
protected $signature = 'phpvms {cmd}';
protected $description = 'Developer commands';
protected $dbSvc;
public function __construct(DatabaseService $dbSvc)
{
parent::__construct();
$this->dbSvc = $dbSvc;
}
/**
* Run dev related commands
*/
@@ -37,7 +29,6 @@ class DevCommands extends BaseCommand
$commands = [
'clear-acars' => 'clearAcars',
'compile-assets' => 'compileAssets',
'import' => 'importYaml',
];
if(!array_key_exists($command, $commands)) {
@@ -76,12 +67,4 @@ class DevCommands extends BaseCommand
$this->runCommand('npm update');
$this->runCommand('npm run dev');
}
/**
* Import data from a YAML file
*/
protected function importYaml()
{
$this->info('importing '. $this->argument('file'));
}
}

View File

@@ -0,0 +1,53 @@
<?php
namespace App\Console\Commands;
use DB;
use App\Console\BaseCommand;
use App\Services\DatabaseService;
class ImportCommand extends BaseCommand
{
protected $signature = 'phpvms:import {files*}';
protected $description = 'Developer commands';
protected $dbSvc;
public function __construct(DatabaseService $dbSvc)
{
parent::__construct();
$this->dbSvc = $dbSvc;
}
/**
* Run dev related commands
*/
public function handle()
{
$files = $this->argument('files');
if(empty($files)) {
$this->error('No files to import specified!');
exit();
}
$ignore_errors = true;
/*$ignore_errors = $this->option('ignore_errors');
if(!$ignore_errors) {
$ignore_errors = false;
}*/
foreach($files as $file) {
if(!file_exists($file)) {
$this->error('File ' . $file .' doesn\'t exist');
exit;
}
$this->info('Importing ' . $file);
$imported = $this->dbSvc->seed_from_yaml_file($file, $ignore_errors);
foreach($imported as $table => $count) {
$this->info('Imported '.$count.' records from "'.$table.'"');
}
}
}
}

View File

@@ -16,6 +16,7 @@ class Kernel extends ConsoleKernel
Commands\AcarsReplay::class,
Commands\CreateDatabase::class,
Commands\DevCommands::class,
Commands\ImportCommand::class,
Commands\Install::class,
Commands\NavdataCommand::class,
];

View File

@@ -1,6 +1,6 @@
<?php
use Illuminate\Database\Migrations\Migration;
use App\Models\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class CreateRanksTable extends Migration
@@ -24,6 +24,19 @@ class CreateRanksTable extends Migration
$table->unique('name');
});
/**
* Initial required data...
*/
$ranks = [
[
'id' => 1,
'name' => 'New Pilot',
'hours' => 0,
]
];
$this->addData('ranks', $ranks);
}
/**

View File

@@ -1,92 +1,7 @@
airlines:
- id: 1
icao: VMS
iata: VM
name: phpvms airlines
active: 1
created_at: now
updated_at: now
users:
- id: 1
name: Admin User
email: admin@phpvms.net
password: admin
api_key: testadminapikey
airline_id: 1
rank_id: 1
home_airport_id: KAUS
curr_airport_id: KJFK
last_pirep_id: pirepid_3
flights: 3
flight_time: 43200
timezone: America/Chicago
state: 1
created_at: now
updated_at: now
- id: 2
name: Carla Walters
email: carla.walters68@example.com
password: admin
api_key: testuserapikey1
airline_id: 1
rank_id: 1
home_airport_id: KJFK
curr_airport_id: KJFK
flights: 1
flight_time: 43200
created_at: now
updated_at: now
state: 0
- id: 3
name: Raymond Pearson
email: raymond.pearson56@example.com
password: admin
api_key: testuserapikey2
airline_id: 1
rank_id: 1
home_airport_id: KJFK
curr_airport_id: KAUS
flights: 1
flight_time: 43200
created_at: now
updated_at: now
state: 1
role_user:
- user_id: 1
role_id: 1
user_type: App\Models\User
- user_id: 1
role_id: 2
user_type: App\Models\User
- user_id: 2
role_id: 2
user_type: App\Models\User
- user_id: 3
role_id: 2
user_type: App\Models\User
# ranks
ranks:
- id: 1
name: New Pilot
hours: 0
- id: 2
name: Junior First Officer
hours: 10
- id: 3
name: First Officer
hours: 15
auto_approve_acars: 1
auto_approve_manual: 1
- id: 4
name: Senior Captain
hours: 20
auto_approve_acars: 1
auto_approve_manual: 1
auto_promote: 0
#
# Initial minimal data required. You probably don't
# want to modify or erase any of this here
#
airports:
- id: KAUS
@@ -98,233 +13,3 @@ airports:
lat: 30.1945278
lon: -97.6698889
tz: America/Chicago
- id: KJFK
iata: JFK
icao: KJFK
name: John F Kennedy
location: New York, New York, USA
country: United States
lat: 40.6399257
lon: -73.7786950
tz: America/New_York
- id: KBWI
iata: BWI
icao: KBWI
name: Baltimore/Washington International Thurgood Marshall Airport
location: Baltimore, MD
country: United States
lat: 39.1754
lon: -76.6683
tz: America/New_York
- id: KIAH
iata: IAH
icao: KIAH
name: George Bush Intercontinental Houston Airport
location: Houston, TX
country: United States
lat: 29.9844
lon: -95.3414
tz: America/Chicago
- id: KORD
iata: ORD
icao: KORD
name: Chicago O'Hare International Airport
location: Chicago, IL
country: United States
lat: 41.9786
lon: -87.9048
tz: America/Chicago
- id: KDFW
iata: DFW
icao: KDFW
name: Dallas Fort Worth International Airport
location: Dallas, TX
country: United States
lat: 32.8968
lon: -97.038
tz: America/Chicago
- id: EFHK
iata: HEL
icao: EFHK
name: Helsinki Vantaa Airport
location: Helsinki
country: Finland
lat: 60.3172
lon: 24.9633
tz: Europe/Helsinki
- id: EGLL
iata: LHR
icao: EGLL
name: London Heathrow
location: London, England
lat: 51.4775
lon: -0.4614
tz: Europe/London
#
aircraft:
- id: 1
subfleet_id: 1
name: Boeing 747-400
registration: NC17
tail_number: 17
- id: 2
subfleet_id: 2
name: Boeing 777-200
registration: NC20
tail_number: 20
#aircraft_rank:
# - aircraft_id: 1
# rank_id: 1
# - aircraft_id: 1
# rank_id: 2
# acars_pay: 100
# manual_pay: 50
fares:
- id: 1
code: Y
name: Economy
price: 100
capacity: 200
- id: 2
code: B
name: Business
price: 500
capacity: 10
- id: 3
code: F
name: First-Class
price: 800
capacity: 5
subfleets:
- id: 1
airline_id: 1
name: 747-400 Winglets
type: 744W
- id: 2
airline_id: 1
name: 777-200 LR
type: 772-LR
# add a few mods to aircraft and fares
subfleet_fare:
# Fare classes on the 747
- subfleet_id: 1
fare_id: 1
price: 200
capacity: 400
- subfleet_id: 1
fare_id: 2
capacity: 20
- subfleet_id: 1
fare_id: 3
price: 1000
capacity: 10
# Fare classes on the 777
- subfleet_id: 2
fare_id: 1
- subfleet_id: 2
fare_id: 3
capacity: 10
subfleet_flight:
- subfleet_id: 1
flight_id: flightid_1
flights:
- id: flightid_1
airline_id: 1
flight_number: 100
dpt_airport_id: KAUS
arr_airport_id: KJFK
route: KAUS SID TNV J87 IAH J2 LCH J22 MEI J239 ATL J52 AJFEB J14 BYJAC Q60 JAXSN J14 COLIN J61 HUBBS J55 SIE STAR KJFK
dpt_time: 6PM CST
arr_time: 11PM EST
created_at: NOW
updated_at: NOW
- id: flightid_2
airline_id: 1
flight_number: 6028
dpt_airport_id: KIAH
arr_airport_id: KAUS
dpt_time: 9AM CST
arr_time: 1030AM CST
route: PITZZ4 MNURE WLEEE4
created_at: NOW
updated_at: NOW
flight_fields:
- id: 1
flight_id: flightid_1
name: cost index
value: 80
- id: 2
flight_id: flightid_2
name: cost index
value: 100
user_bids:
- id: 100
user_id: 1
flight_id: flightid_1
- id: 101
user_id: 1
flight_id: flightid_3
pireps:
- id: pirepid_1
user_id: 1
airline_id: 1
flight_id: flightid_1
aircraft_id: 1
dpt_airport_id: KAUS
arr_airport_id: KJFK
flight_time: 180 # 6 hours
state: 1
route: PLMMR2 SPA Q22 BEARI FAK PHLBO3
notes: just a pilot report
created_at: NOW
updated_at: NOW
- id: pirepid_2
user_id: 1
airline_id: 1
flight_id: flightid_2
aircraft_id: 1
dpt_airport_id: KJFK
arr_airport_id: KAUS
flight_time: 180 # 6 hours
state: 1
route: PLMMR2 SPA Q22 BEARI FAK PHLBO3
notes: just a pilot report
created_at: NOW
updated_at: NOW
- id: pirepid_3
user_id: 1
airline_id: 1
flight_id: flightid_2
aircraft_id: 1
dpt_airport_id: KJFK
arr_airport_id: KAUS
flight_time: 180 # 6 hours
state: 1
route: PLMMR2 SPA Q22 BEARI FAK PHLBO3
notes: just a pilot report
created_at: NOW
updated_at: NOW
pirep_fields:
- id: 1
name: arrival gate
required: 0
pirep_field_values:
- id: 1
pirep_id: pirepid_1
name: arrival gate
value: B14
source: manual

View File

@@ -0,0 +1,327 @@
airlines:
- id: 1
icao: VMS
iata: VM
name: phpvms airlines
active: 1
created_at: now
updated_at: now
users:
- id: 1
name: Admin User
email: admin@phpvms.net
password: admin
api_key: testadminapikey
airline_id: 1
rank_id: 1
home_airport_id: KAUS
curr_airport_id: KJFK
last_pirep_id: pirepid_3
flights: 3
flight_time: 43200
timezone: America/Chicago
state: 1
created_at: now
updated_at: now
- id: 2
name: Carla Walters
email: carla.walters68@example.com
password: admin
api_key: testuserapikey1
airline_id: 1
rank_id: 1
home_airport_id: KJFK
curr_airport_id: KJFK
flights: 1
flight_time: 43200
created_at: now
updated_at: now
state: 0
- id: 3
name: Raymond Pearson
email: raymond.pearson56@example.com
password: admin
api_key: testuserapikey2
airline_id: 1
rank_id: 1
home_airport_id: KJFK
curr_airport_id: KAUS
flights: 1
flight_time: 43200
created_at: now
updated_at: now
state: 1
role_user:
- user_id: 1
role_id: 1
user_type: App\Models\User
- user_id: 1
role_id: 2
user_type: App\Models\User
- user_id: 2
role_id: 2
user_type: App\Models\User
- user_id: 3
role_id: 2
user_type: App\Models\User
# ranks
ranks:
- id: 2
name: Junior First Officer
hours: 10
- id: 3
name: First Officer
hours: 15
auto_approve_acars: 1
auto_approve_manual: 1
- id: 4
name: Senior Captain
hours: 20
auto_approve_acars: 1
auto_approve_manual: 1
auto_promote: 0
airports:
- id: KAUS
iata: AUS
icao: KAUS
name: Austin-Bergstrom
location: Austin, Texas, USA
country: United States
lat: 30.1945278
lon: -97.6698889
tz: America/Chicago
- id: KJFK
iata: JFK
icao: KJFK
name: John F Kennedy
location: New York, New York, USA
country: United States
lat: 40.6399257
lon: -73.7786950
tz: America/New_York
- id: KBWI
iata: BWI
icao: KBWI
name: Baltimore/Washington International Thurgood Marshall Airport
location: Baltimore, MD
country: United States
lat: 39.1754
lon: -76.6683
tz: America/New_York
- id: KIAH
iata: IAH
icao: KIAH
name: George Bush Intercontinental Houston Airport
location: Houston, TX
country: United States
lat: 29.9844
lon: -95.3414
tz: America/Chicago
- id: KORD
iata: ORD
icao: KORD
name: Chicago O'Hare International Airport
location: Chicago, IL
country: United States
lat: 41.9786
lon: -87.9048
tz: America/Chicago
- id: KDFW
iata: DFW
icao: KDFW
name: Dallas Fort Worth International Airport
location: Dallas, TX
country: United States
lat: 32.8968
lon: -97.038
tz: America/Chicago
- id: EFHK
iata: HEL
icao: EFHK
name: Helsinki Vantaa Airport
location: Helsinki
country: Finland
lat: 60.3172
lon: 24.9633
tz: Europe/Helsinki
- id: EGLL
iata: LHR
icao: EGLL
name: London Heathrow
location: London, England
lat: 51.4775
lon: -0.4614
tz: Europe/London
#
aircraft:
- id: 1
subfleet_id: 1
name: Boeing 747-400
registration: NC17
tail_number: 17
- id: 2
subfleet_id: 2
name: Boeing 777-200
registration: NC20
tail_number: 20
#aircraft_rank:
# - aircraft_id: 1
# rank_id: 1
# - aircraft_id: 1
# rank_id: 2
# acars_pay: 100
# manual_pay: 50
fares:
- id: 1
code: Y
name: Economy
price: 100
capacity: 200
- id: 2
code: B
name: Business
price: 500
capacity: 10
- id: 3
code: F
name: First-Class
price: 800
capacity: 5
subfleets:
- id: 1
airline_id: 1
name: 747-400 Winglets
type: 744W
- id: 2
airline_id: 1
name: 777-200 LR
type: 772-LR
# add a few mods to aircraft and fares
subfleet_fare:
# Fare classes on the 747
- subfleet_id: 1
fare_id: 1
price: 200
capacity: 400
- subfleet_id: 1
fare_id: 2
capacity: 20
- subfleet_id: 1
fare_id: 3
price: 1000
capacity: 10
# Fare classes on the 777
- subfleet_id: 2
fare_id: 1
- subfleet_id: 2
fare_id: 3
capacity: 10
subfleet_flight:
- subfleet_id: 1
flight_id: flightid_1
flights:
- id: flightid_1
airline_id: 1
flight_number: 100
dpt_airport_id: KAUS
arr_airport_id: KJFK
route: KAUS SID TNV J87 IAH J2 LCH J22 MEI J239 ATL J52 AJFEB J14 BYJAC Q60 JAXSN J14 COLIN J61 HUBBS J55 SIE STAR KJFK
dpt_time: 6PM CST
arr_time: 11PM EST
created_at: NOW
updated_at: NOW
- id: flightid_2
airline_id: 1
flight_number: 6028
dpt_airport_id: KIAH
arr_airport_id: KAUS
dpt_time: 9AM CST
arr_time: 1030AM CST
route: PITZZ4 MNURE WLEEE4
created_at: NOW
updated_at: NOW
flight_fields:
- id: 1
flight_id: flightid_1
name: cost index
value: 80
- id: 2
flight_id: flightid_2
name: cost index
value: 100
user_bids:
- id: 100
user_id: 1
flight_id: flightid_1
- id: 101
user_id: 1
flight_id: flightid_3
pireps:
- id: pirepid_1
user_id: 1
airline_id: 1
flight_id: flightid_1
aircraft_id: 1
dpt_airport_id: KAUS
arr_airport_id: KJFK
flight_time: 180 # 6 hours
state: 1
route: PLMMR2 SPA Q22 BEARI FAK PHLBO3
notes: just a pilot report
created_at: NOW
updated_at: NOW
- id: pirepid_2
user_id: 1
airline_id: 1
flight_id: flightid_2
aircraft_id: 1
dpt_airport_id: KJFK
arr_airport_id: KAUS
flight_time: 180 # 6 hours
state: 1
route: PLMMR2 SPA Q22 BEARI FAK PHLBO3
notes: just a pilot report
created_at: NOW
updated_at: NOW
- id: pirepid_3
user_id: 1
airline_id: 1
flight_id: flightid_2
aircraft_id: 1
dpt_airport_id: KJFK
arr_airport_id: KAUS
flight_time: 180 # 6 hours
state: 1
route: PLMMR2 SPA Q22 BEARI FAK PHLBO3
notes: just a pilot report
created_at: NOW
updated_at: NOW
pirep_fields:
- id: 1
name: arrival gate
required: 0
pirep_field_values:
- id: 1
pirep_id: pirepid_1
name: arrival gate
value: B14
source: manual

View File

@@ -30,7 +30,7 @@ class AircraftController extends BaseController
$aircraft = $this->aircraftRepository->all();
return view('admin.aircraft.index', [
'aircraft', $aircraft
'aircraft' => $aircraft
]);
}

View File

@@ -28,16 +28,32 @@ class DatabaseService extends BaseService
return Carbon::now('UTC')->format('Y-m-d H:i:s');
}
public function seed_from_yaml_file($yaml_file)
/**
* @param $yaml_file
* @param bool $ignore_errors
* @return array
* @throws \Exception
*/
public function seed_from_yaml_file($yaml_file, $ignore_errors=false): array
{
$yml = file_get_contents($yaml_file);
$this->seed_from_yaml($yml);
return $this->seed_from_yaml($yml, $ignore_errors);
}
public function seed_from_yaml($yml)
/**
* @param $yml
* @param bool $ignore_errors
* @return array
* @throws \Exception
*/
public function seed_from_yaml($yml, $ignore_errors=false): array
{
$imported = [];
$yml = Yaml::parse($yml);
foreach ($yml as $table => $rows) {
$imported[$table] = 0;
foreach ($rows as $row) {
# see if this table uses a UUID as the PK
@@ -60,12 +76,19 @@ class DatabaseService extends BaseService
}
}
#try {
try {
DB::table($table)->insert($row);
#} catch(QueryException $e) {
# Log::info($e->getMessage());
#}
++$imported[$table];
} catch(QueryException $e) {
if($ignore_errors) {
continue;
}
throw $e;
}
}
}
return $imported;
}
}