Cleanup factories and seed data for airport timezone column change

This commit is contained in:
Nabeel Shahzad 2018-02-06 13:11:42 -06:00
parent 531c7ddba3
commit 7d8dc2a4d4
12 changed files with 33 additions and 36 deletions

View File

@ -4,7 +4,7 @@ use Faker\Generator as Faker;
$factory->define(App\Models\Aircraft::class, function (Faker $faker) { $factory->define(App\Models\Aircraft::class, function (Faker $faker) {
return [ return [
#'id' => $faker->unique()->numberBetween(10, 100000), 'id' => null,
'subfleet_id' => function() { 'subfleet_id' => function() {
return factory(App\Models\Subfleet::class)->create()->id; return factory(App\Models\Subfleet::class)->create()->id;
}, },

View File

@ -8,7 +8,7 @@ use Hashids\Hashids;
*/ */
$factory->define(App\Models\Airline::class, function (Faker $faker) { $factory->define(App\Models\Airline::class, function (Faker $faker) {
return [ return [
#'id' => $faker->unique()->numberBetween(10, 10000), 'id' => null,
'icao' => function (array $apt) use ($faker) { 'icao' => function (array $apt) use ($faker) {
$hashids = new Hashids(microtime(), 5); $hashids = new Hashids(microtime(), 5);
$mt = str_replace('.', '', microtime(true)); $mt = str_replace('.', '', microtime(true));

View File

@ -1,6 +1,5 @@
<?php <?php
use Hashids\Hashids;
use Faker\Generator as Faker; use Faker\Generator as Faker;
/** /**
@ -9,7 +8,7 @@ use Faker\Generator as Faker;
$factory->define(App\Models\Airport::class, function (Faker $faker) { $factory->define(App\Models\Airport::class, function (Faker $faker) {
return [ return [
'id' => function(array $apt) use ($faker) { 'id' => function() {
$characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; $characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
$string = ''; $string = '';
$max = strlen($characters) - 1; $max = strlen($characters) - 1;
@ -18,16 +17,12 @@ $factory->define(App\Models\Airport::class, function (Faker $faker) {
} }
return $string; return $string;
#return $faker->unique()->text(5);
/*$hashids = new Hashids(microtime(), 5);
$mt = str_replace('.', '', microtime(true));
return $hashids->encode($mt);*/
}, },
'icao' => function(array $apt) { return $apt['id']; }, 'icao' => function(array $apt) { return $apt['id']; },
'iata' => function (array $apt) { return $apt['id']; }, 'iata' => function (array $apt) { return $apt['id']; },
'name' => $faker->sentence(3), 'name' => $faker->sentence(3),
'country' => $faker->country, 'country' => $faker->country,
'tz' => $faker->timezone, 'timezone' => $faker->timezone,
'lat' => $faker->latitude, 'lat' => $faker->latitude,
'lon' => $faker->longitude, 'lon' => $faker->longitude,
'fuel_100ll_cost' => $faker->randomFloat(2), 'fuel_100ll_cost' => $faker->randomFloat(2),

View File

@ -4,7 +4,7 @@ use Faker\Generator as Faker;
$factory->define(App\Models\Fare::class, function (Faker $faker) { $factory->define(App\Models\Fare::class, function (Faker $faker) {
return [ return [
#'id' => $faker->unique()->numberBetween(10, 10000), 'id' => null,
'code' => $faker->text(5), 'code' => $faker->text(5),
'name' => $faker->text(20), 'name' => $faker->text(20),
'price' => $faker->randomFloat(2, 100, 1000), 'price' => $faker->randomFloat(2, 100, 1000),

View File

@ -8,8 +8,10 @@ $airlinesAvailable = [1];
$factory->define(App\Models\Flight::class, function (Faker $faker) use ($airlinesAvailable) { $factory->define(App\Models\Flight::class, function (Faker $faker) use ($airlinesAvailable) {
return [ return [
'id' => substr($faker->unique()->sha1, 28, 12), 'id' => null,
'airline_id' => $faker->randomElement($airlinesAvailable), 'airline_id' => function () {
return factory(App\Models\Airline::class)->create()->id;
},
'flight_number' => $faker->unique()->numberBetween(10, 1000000), 'flight_number' => $faker->unique()->numberBetween(10, 1000000),
'route_code' => $faker->randomElement(['', $faker->text(5)]), 'route_code' => $faker->randomElement(['', $faker->text(5)]),
'route_leg' => $faker->randomElement(['', $faker->text(5)]), 'route_leg' => $faker->randomElement(['', $faker->text(5)]),

View File

@ -12,24 +12,22 @@ $factory->define(App\Models\Pirep::class, function (Faker $faker) {
return [ return [
'id' => null, 'id' => null,
'airline_id' => function () { # OVERRIDE THIS IF NEEDED 'airline_id' => function () {
return factory(App\Models\Airline::class)->create()->id; return factory(App\Models\Airline::class)->create()->id;
}, },
'user_id' => function () { # OVERRIDE THIS IF NEEDED 'user_id' => function () {
return factory(App\Models\User::class)->create()->id; return factory(App\Models\User::class)->create()->id;
}, },
'aircraft_id' => function () { 'aircraft_id' => function () {
return factory(App\Models\Aircraft::class)->create()->id; return factory(App\Models\Aircraft::class)->create()->id;
}, },
'flight_number' => function () { 'flight_number' => function (array $pirep) {
return factory(App\Models\Flight::class)->create()->flight_number; return factory(App\Models\Flight::class)->create([
}, 'airline_id' => $pirep['airline_id']
'route_code' => function(array $pirep) { ])->flight_number;
//return App\Models\Flight::where(['flight_number' => $pirep['flight_number']])->first()->route_code;
},
'route_leg' => function (array $pirep) {
//return App\Models\Flight::where('flight_number', $pirep['flight_number'])->first()->route_leg;
}, },
'route_code' => null,
'route_leg' => null,
'dpt_airport_id' => function () { 'dpt_airport_id' => function () {
return factory(App\Models\Airport::class)->create()->id; return factory(App\Models\Airport::class)->create()->id;
}, },

View File

@ -11,7 +11,7 @@ use Faker\Generator as Faker;
*/ */
$factory->define(App\Models\Rank::class, function (Faker $faker) { $factory->define(App\Models\Rank::class, function (Faker $faker) {
return [ return [
#'id' => $faker->unique()->numberBetween(10, 10000), 'id' => null,
'name' => $faker->unique()->text(50), 'name' => $faker->unique()->text(50),
'hours' => $faker->numberBetween(10, 50), 'hours' => $faker->numberBetween(10, 50),
'auto_approve_acars' => 0, 'auto_approve_acars' => 0,

View File

@ -4,8 +4,10 @@ use Faker\Generator as Faker;
$factory->define(App\Models\Subfleet::class, function (Faker $faker) { $factory->define(App\Models\Subfleet::class, function (Faker $faker) {
return [ return [
#'id' => $faker->unique()->numberBetween(10, 10000), 'id' => null,
'airline_id' => 1, 'airline_id' => function () {
return factory(App\Models\Airline::class)->create()->id;
},
'name' => $faker->unique()->text(50), 'name' => $faker->unique()->text(50),
'type' => $faker->unique()->text(7), 'type' => $faker->unique()->text(7),
]; ];

View File

@ -8,7 +8,7 @@ $factory->define(App\Models\User::class, function (Faker $faker)
static $password; static $password;
return [ return [
#'id' => $faker->unique()->numberBetween(10, 10000), 'id' => null,
'name' => $faker->name, 'name' => $faker->name,
'email' => $faker->safeEmail, 'email' => $faker->safeEmail,
'password' => $password ?: $password = Hash::make('secret'), 'password' => $password ?: $password = Hash::make('secret'),

View File

@ -10,7 +10,7 @@ airports:
name: Austin-Bergstrom name: Austin-Bergstrom
location: Austin, Texas, USA location: Austin, Texas, USA
country: United States country: United States
timezone: America/Chicago
lat: 30.1945278 lat: 30.1945278
lon: -97.6698889 lon: -97.6698889
hub: 1 hub: 1
tz: America/Chicago

View File

@ -10,7 +10,7 @@ airports:
name: Austin-Bergstrom name: Austin-Bergstrom
location: Austin, Texas, USA location: Austin, Texas, USA
country: United States country: United States
timezone: America/Chicago
lat: 30.1945278 lat: 30.1945278
lon: -97.6698889 lon: -97.6698889
hub: 1 hub: 1
tz: America/Chicago

View File

@ -110,73 +110,73 @@ airports:
name: Austin-Bergstrom name: Austin-Bergstrom
location: Austin, Texas, USA location: Austin, Texas, USA
country: United States country: United States
timezone: America/Chicago
lat: 30.1945278 lat: 30.1945278
lon: -97.6698889 lon: -97.6698889
hub: 1 hub: 1
tz: America/Chicago
- id: KJFK - id: KJFK
iata: JFK iata: JFK
icao: KJFK icao: KJFK
name: John F Kennedy name: John F Kennedy
location: New York, New York, USA location: New York, New York, USA
country: United States country: United States
timezone: America/New_York
lat: 40.6399257 lat: 40.6399257
lon: -73.7786950 lon: -73.7786950
hub: 1 hub: 1
tz: America/New_York
- id: KBWI - id: KBWI
iata: BWI iata: BWI
icao: KBWI icao: KBWI
name: Baltimore/Washington International Thurgood Marshall Airport name: Baltimore/Washington International Thurgood Marshall Airport
location: Baltimore, MD location: Baltimore, MD
country: United States country: United States
timezone: America/New_York
lat: 39.1754 lat: 39.1754
lon: -76.6683 lon: -76.6683
tz: America/New_York
- id: KIAH - id: KIAH
iata: IAH iata: IAH
icao: KIAH icao: KIAH
name: George Bush Intercontinental Houston Airport name: George Bush Intercontinental Houston Airport
location: Houston, TX location: Houston, TX
country: United States country: United States
timezone: America/Chicago
lat: 29.9844 lat: 29.9844
lon: -95.3414 lon: -95.3414
tz: America/Chicago
- id: KORD - id: KORD
iata: ORD iata: ORD
icao: KORD icao: KORD
name: Chicago O'Hare International Airport name: Chicago O'Hare International Airport
location: Chicago, IL location: Chicago, IL
country: United States country: United States
timezone: America/Chicago
lat: 41.9786 lat: 41.9786
lon: -87.9048 lon: -87.9048
tz: America/Chicago
- id: KDFW - id: KDFW
iata: DFW iata: DFW
icao: KDFW icao: KDFW
name: Dallas Fort Worth International Airport name: Dallas Fort Worth International Airport
location: Dallas, TX location: Dallas, TX
country: United States country: United States
timezone: America/Chicago
lat: 32.8968 lat: 32.8968
lon: -97.038 lon: -97.038
tz: America/Chicago
- id: EFHK - id: EFHK
iata: HEL iata: HEL
icao: EFHK icao: EFHK
name: Helsinki Vantaa Airport name: Helsinki Vantaa Airport
location: Helsinki location: Helsinki
country: Finland country: Finland
timezone: Europe/Helsinki
lat: 60.3172 lat: 60.3172
lon: 24.9633 lon: 24.9633
tz: Europe/Helsinki
- id: EGLL - id: EGLL
iata: LHR iata: LHR
icao: EGLL icao: EGLL
name: London Heathrow name: London Heathrow
location: London, England location: London, England
timezone: Europe/London
lat: 51.4775 lat: 51.4775
lon: -0.4614 lon: -0.4614
tz: Europe/London
# #
aircraft: aircraft: