From 8615ce5b54bbe1fa4ee792dc4e6ce106ca63998b Mon Sep 17 00:00:00 2001 From: Nabeel Shahzad Date: Mon, 12 Jun 2017 22:47:53 -0500 Subject: [PATCH] seed db from yaml file --- composer.json | 3 +- composer.lock | 112 +++++++++++++++--------------- database/seeds/DatabaseSeeder.php | 33 +++------ database/seeds/seed.yml | 58 ++++++++++++++++ 4 files changed, 125 insertions(+), 81 deletions(-) create mode 100644 database/seeds/seed.yml diff --git a/composer.json b/composer.json index 962161ae..7ad97cc9 100755 --- a/composer.json +++ b/composer.json @@ -17,7 +17,8 @@ "doctrine/dbal": "~2.3", "zizaco/entrust": "5.2.x-dev", "prettus/l5-repository": "^2.6", - "spatie/laravel-pjax": "^1.3" + "spatie/laravel-pjax": "^1.3", + "symfony/yaml": "^3.3" }, "require-dev": { "fzaninotto/faker": "~1.4", diff --git a/composer.lock b/composer.lock index 40a89203..f0e30ec7 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "528d419a11eb2963be54a289afa2fbbc", + "content-hash": "74036cb1d4ba5a8114ee893fc869e92d", "packages": [ { "name": "barryvdh/laravel-ide-helper", @@ -3077,6 +3077,61 @@ ], "time": "2017-06-02T09:10:29+00:00" }, + { + "name": "symfony/yaml", + "version": "v3.3.2", + "source": { + "type": "git", + "url": "https://github.com/symfony/yaml.git", + "reference": "9752a30000a8ca9f4b34b5227d15d0101b96b063" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/yaml/zipball/9752a30000a8ca9f4b34b5227d15d0101b96b063", + "reference": "9752a30000a8ca9f4b34b5227d15d0101b96b063", + "shasum": "" + }, + "require": { + "php": ">=5.5.9" + }, + "require-dev": { + "symfony/console": "~2.8|~3.0" + }, + "suggest": { + "symfony/console": "For validating YAML files using the lint command" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.3-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Yaml\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Yaml Component", + "homepage": "https://symfony.com", + "time": "2017-06-02T22:05:06+00:00" + }, { "name": "tijsverkoyen/css-to-inline-styles", "version": "2.2.0", @@ -4732,61 +4787,6 @@ "homepage": "https://github.com/sebastianbergmann/version", "time": "2016-10-03T07:35:21+00:00" }, - { - "name": "symfony/yaml", - "version": "v3.3.2", - "source": { - "type": "git", - "url": "https://github.com/symfony/yaml.git", - "reference": "9752a30000a8ca9f4b34b5227d15d0101b96b063" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/yaml/zipball/9752a30000a8ca9f4b34b5227d15d0101b96b063", - "reference": "9752a30000a8ca9f4b34b5227d15d0101b96b063", - "shasum": "" - }, - "require": { - "php": ">=5.5.9" - }, - "require-dev": { - "symfony/console": "~2.8|~3.0" - }, - "suggest": { - "symfony/console": "For validating YAML files using the lint command" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "3.3-dev" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Component\\Yaml\\": "" - }, - "exclude-from-classmap": [ - "/Tests/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony Yaml Component", - "homepage": "https://symfony.com", - "time": "2017-06-02T22:05:06+00:00" - }, { "name": "webmozart/assert", "version": "1.2.0", diff --git a/database/seeds/DatabaseSeeder.php b/database/seeds/DatabaseSeeder.php index ee742a3d..b90eeaee 100755 --- a/database/seeds/DatabaseSeeder.php +++ b/database/seeds/DatabaseSeeder.php @@ -13,7 +13,8 @@ class DatabaseSeeder extends Seeder public function run() { $this->user_seeder(); - $this->airport_seeder(); + $this->seed_from_yaml(); + //$this->airport_seeder(); } protected function time() { @@ -43,30 +44,14 @@ class DatabaseSeeder extends Seeder DB::table('role_user')->insert(['user_id' => 1, 'role_id' => 2]); } - /** - * Add a few initial airports - */ - protected function airport_seeder() + protected function seed_from_yaml() { - $airports = [ - [ - 'icao' => 'KAUS', - 'name' => 'Austin-Bergstrom International Airport', - 'location' => 'Austin, Texas, USA', - 'lat' => 30.1945278, - 'lon' => -97.6698889, - ], - [ - 'icao' => 'KJFK', - 'name' => 'John F Kennedy International Airport', - 'location' => 'New York, New York, USA', - 'lat' => 40.6399257, - 'lon' => -73.7786950, - ], - ]; - - foreach($airports as $airport) { - DB::table('airports')->insert($airport); + $yml = Yaml::parse(file_get_contents(database_path('seeds/seed.yml'))); + foreach ($yml as $table => $rows) { + foreach($rows as $row) { + DB::table($table)->insert($row); + } } } + } diff --git a/database/seeds/seed.yml b/database/seeds/seed.yml new file mode 100644 index 00000000..3bea979c --- /dev/null +++ b/database/seeds/seed.yml @@ -0,0 +1,58 @@ +# +airlines: + - id: 1 + code: VMS + name: phpvms airlines + active: 1 + +# +airports: + - icao: KAUS + name: Austin-Bergstrom International Airport + location: Austin, Texas, USA + lat: 30.1945278 + lon: -97.6698889 + - icao: KJFK + name: John F Kennedy International Airport + location: New York, New York, USA + lat: 40.6399257 + lon: -73.7786950 + +# +aircraft_classes: + - id: 1 + code: H + name: Heavy + +# +aircraft: + - id: 1 + aircraft_class_id: 1 + icao: B744 + name: Boeing 747-400 + registration: NC17 + tail_number: 17 + - id: 2 + aircraft_class_id: 1 + icao: B772 + name: Boeing 777-200 + registration: NC20 + tail_number: 20 + +# +fares: + - id: 1 + code: Y + name: Economy + price: 100 + capacity: 200 + - id: 2 + code: F + name: First-Class + price: 500 + capacity: 10 + +# +aircraft_fare: + - aircraft_id: 1 + fare_id: 1