From 7d8dc2a4d45a92a7b6dddad06ba7b1bf81dbcaf5 Mon Sep 17 00:00:00 2001 From: Nabeel Shahzad Date: Tue, 6 Feb 2018 13:11:42 -0600 Subject: [PATCH] Cleanup factories and seed data for airport timezone column change --- app/Database/factories/AircraftFactory.php | 2 +- app/Database/factories/AirlineFactory.php | 2 +- app/Database/factories/AirportFactory.php | 9 ++------- app/Database/factories/FareFactory.php | 2 +- app/Database/factories/FlightFactory.php | 6 ++++-- app/Database/factories/PirepFactory.php | 18 ++++++++---------- app/Database/factories/RankFactory.php | 2 +- app/Database/factories/SubfleetFactory.php | 6 ++++-- app/Database/factories/UserFactory.php | 2 +- app/Database/seeds/dev.yml | 2 +- app/Database/seeds/prod.yml | 2 +- app/Database/seeds/sample.yml | 16 ++++++++-------- 12 files changed, 33 insertions(+), 36 deletions(-) diff --git a/app/Database/factories/AircraftFactory.php b/app/Database/factories/AircraftFactory.php index 3e6caa37..bcf501aa 100644 --- a/app/Database/factories/AircraftFactory.php +++ b/app/Database/factories/AircraftFactory.php @@ -4,7 +4,7 @@ use Faker\Generator as Faker; $factory->define(App\Models\Aircraft::class, function (Faker $faker) { return [ - #'id' => $faker->unique()->numberBetween(10, 100000), + 'id' => null, 'subfleet_id' => function() { return factory(App\Models\Subfleet::class)->create()->id; }, diff --git a/app/Database/factories/AirlineFactory.php b/app/Database/factories/AirlineFactory.php index 19f5ee32..20067eb4 100644 --- a/app/Database/factories/AirlineFactory.php +++ b/app/Database/factories/AirlineFactory.php @@ -8,7 +8,7 @@ use Hashids\Hashids; */ $factory->define(App\Models\Airline::class, function (Faker $faker) { return [ - #'id' => $faker->unique()->numberBetween(10, 10000), + 'id' => null, 'icao' => function (array $apt) use ($faker) { $hashids = new Hashids(microtime(), 5); $mt = str_replace('.', '', microtime(true)); diff --git a/app/Database/factories/AirportFactory.php b/app/Database/factories/AirportFactory.php index 2c6f214f..def85245 100644 --- a/app/Database/factories/AirportFactory.php +++ b/app/Database/factories/AirportFactory.php @@ -1,6 +1,5 @@ define(App\Models\Airport::class, function (Faker $faker) { return [ - 'id' => function(array $apt) use ($faker) { + 'id' => function() { $characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; $string = ''; $max = strlen($characters) - 1; @@ -18,16 +17,12 @@ $factory->define(App\Models\Airport::class, function (Faker $faker) { } 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']; }, 'iata' => function (array $apt) { return $apt['id']; }, 'name' => $faker->sentence(3), 'country' => $faker->country, - 'tz' => $faker->timezone, + 'timezone' => $faker->timezone, 'lat' => $faker->latitude, 'lon' => $faker->longitude, 'fuel_100ll_cost' => $faker->randomFloat(2), diff --git a/app/Database/factories/FareFactory.php b/app/Database/factories/FareFactory.php index d3fb3a38..d097e48b 100644 --- a/app/Database/factories/FareFactory.php +++ b/app/Database/factories/FareFactory.php @@ -4,7 +4,7 @@ use Faker\Generator as Faker; $factory->define(App\Models\Fare::class, function (Faker $faker) { return [ - #'id' => $faker->unique()->numberBetween(10, 10000), + 'id' => null, 'code' => $faker->text(5), 'name' => $faker->text(20), 'price' => $faker->randomFloat(2, 100, 1000), diff --git a/app/Database/factories/FlightFactory.php b/app/Database/factories/FlightFactory.php index 36d8e74a..0f65f164 100644 --- a/app/Database/factories/FlightFactory.php +++ b/app/Database/factories/FlightFactory.php @@ -8,8 +8,10 @@ $airlinesAvailable = [1]; $factory->define(App\Models\Flight::class, function (Faker $faker) use ($airlinesAvailable) { return [ - 'id' => substr($faker->unique()->sha1, 28, 12), - 'airline_id' => $faker->randomElement($airlinesAvailable), + 'id' => null, + 'airline_id' => function () { + return factory(App\Models\Airline::class)->create()->id; + }, 'flight_number' => $faker->unique()->numberBetween(10, 1000000), 'route_code' => $faker->randomElement(['', $faker->text(5)]), 'route_leg' => $faker->randomElement(['', $faker->text(5)]), diff --git a/app/Database/factories/PirepFactory.php b/app/Database/factories/PirepFactory.php index 17a79330..3b89c1e5 100644 --- a/app/Database/factories/PirepFactory.php +++ b/app/Database/factories/PirepFactory.php @@ -12,24 +12,22 @@ $factory->define(App\Models\Pirep::class, function (Faker $faker) { return [ 'id' => null, - 'airline_id' => function () { # OVERRIDE THIS IF NEEDED + 'airline_id' => function () { 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; }, 'aircraft_id' => function () { return factory(App\Models\Aircraft::class)->create()->id; }, - 'flight_number' => function () { - return factory(App\Models\Flight::class)->create()->flight_number; - }, - 'route_code' => function(array $pirep) { - //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; + 'flight_number' => function (array $pirep) { + return factory(App\Models\Flight::class)->create([ + 'airline_id' => $pirep['airline_id'] + ])->flight_number; }, + 'route_code' => null, + 'route_leg' => null, 'dpt_airport_id' => function () { return factory(App\Models\Airport::class)->create()->id; }, diff --git a/app/Database/factories/RankFactory.php b/app/Database/factories/RankFactory.php index 7237a7b0..bbc8676c 100644 --- a/app/Database/factories/RankFactory.php +++ b/app/Database/factories/RankFactory.php @@ -11,7 +11,7 @@ use Faker\Generator as Faker; */ $factory->define(App\Models\Rank::class, function (Faker $faker) { return [ - #'id' => $faker->unique()->numberBetween(10, 10000), + 'id' => null, 'name' => $faker->unique()->text(50), 'hours' => $faker->numberBetween(10, 50), 'auto_approve_acars' => 0, diff --git a/app/Database/factories/SubfleetFactory.php b/app/Database/factories/SubfleetFactory.php index 2bfd9fae..f11daed8 100644 --- a/app/Database/factories/SubfleetFactory.php +++ b/app/Database/factories/SubfleetFactory.php @@ -4,8 +4,10 @@ use Faker\Generator as Faker; $factory->define(App\Models\Subfleet::class, function (Faker $faker) { return [ - #'id' => $faker->unique()->numberBetween(10, 10000), - 'airline_id' => 1, + 'id' => null, + 'airline_id' => function () { + return factory(App\Models\Airline::class)->create()->id; + }, 'name' => $faker->unique()->text(50), 'type' => $faker->unique()->text(7), ]; diff --git a/app/Database/factories/UserFactory.php b/app/Database/factories/UserFactory.php index 4763b971..690aa9c1 100644 --- a/app/Database/factories/UserFactory.php +++ b/app/Database/factories/UserFactory.php @@ -8,7 +8,7 @@ $factory->define(App\Models\User::class, function (Faker $faker) static $password; return [ - #'id' => $faker->unique()->numberBetween(10, 10000), + 'id' => null, 'name' => $faker->name, 'email' => $faker->safeEmail, 'password' => $password ?: $password = Hash::make('secret'), diff --git a/app/Database/seeds/dev.yml b/app/Database/seeds/dev.yml index fab538a3..0c3cca14 100644 --- a/app/Database/seeds/dev.yml +++ b/app/Database/seeds/dev.yml @@ -10,7 +10,7 @@ airports: name: Austin-Bergstrom location: Austin, Texas, USA country: United States + timezone: America/Chicago lat: 30.1945278 lon: -97.6698889 hub: 1 - tz: America/Chicago diff --git a/app/Database/seeds/prod.yml b/app/Database/seeds/prod.yml index fab538a3..0c3cca14 100644 --- a/app/Database/seeds/prod.yml +++ b/app/Database/seeds/prod.yml @@ -10,7 +10,7 @@ airports: name: Austin-Bergstrom location: Austin, Texas, USA country: United States + timezone: America/Chicago lat: 30.1945278 lon: -97.6698889 hub: 1 - tz: America/Chicago diff --git a/app/Database/seeds/sample.yml b/app/Database/seeds/sample.yml index d4984898..5601aff0 100644 --- a/app/Database/seeds/sample.yml +++ b/app/Database/seeds/sample.yml @@ -110,73 +110,73 @@ airports: name: Austin-Bergstrom location: Austin, Texas, USA country: United States + timezone: America/Chicago lat: 30.1945278 lon: -97.6698889 hub: 1 - tz: America/Chicago - id: KJFK iata: JFK icao: KJFK name: John F Kennedy location: New York, New York, USA country: United States + timezone: America/New_York lat: 40.6399257 lon: -73.7786950 hub: 1 - tz: America/New_York - id: KBWI iata: BWI icao: KBWI name: Baltimore/Washington International Thurgood Marshall Airport location: Baltimore, MD country: United States + timezone: America/New_York 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 + timezone: America/Chicago 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 + timezone: America/Chicago 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 + timezone: America/Chicago lat: 32.8968 lon: -97.038 - tz: America/Chicago - id: EFHK iata: HEL icao: EFHK name: Helsinki Vantaa Airport location: Helsinki country: Finland + timezone: Europe/Helsinki lat: 60.3172 lon: 24.9633 - tz: Europe/Helsinki - id: EGLL iata: LHR icao: EGLL name: London Heathrow location: London, England + timezone: Europe/London lat: 51.4775 lon: -0.4614 - tz: Europe/London # aircraft: