Skip to content

Commit

Permalink
internal sql file added, for fast development.
Browse files Browse the repository at this point in the history
  • Loading branch information
fatihtoprak committed Feb 26, 2022
1 parent c70839b commit b50a7ba
Show file tree
Hide file tree
Showing 2 changed files with 153,580 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/Seeders/LCSCSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,32 @@
use Optimisthub\LCSC\Models\Country;
use Optimisthub\LCSC\Models\State;

use Storage;
use DB;
use Illuminate\Database\Schema\Blueprint;

class LCSCSeeder extends Seeder
{
public function run()
{
ini_set('memory_limit', '-1');

if(Storage::disk('local')->exists('public/lcsc/city-state-country.sql'))
{
DB::unprepared(Storage::get('public/lcsc/city-state-country.sql'));
$this->info("#### Old Sql Truncated and new Sql Imported Successfully.. ####");
return;
}

$remoteJson = 'https://raw.githubusercontent.com/dr5hn/countries-states-cities-database/master/countries+states+cities.json';

$fileSize = $this->remoteFileSize($remoteJson);

$this->info('Fetching countries from remote source...['.$fileSize.']');
Storage::put('public/lcsc/city-state-country.json', $this->remoteGet($remoteJson));

$countries = json_decode($this->remoteGet($remoteJson));
//$countries = json_decode(file_get_contents(__DIR__ . "/../countries+states+cities.json"));

foreach ($countries as $countryData) {
$country = Country::query()->updateOrCreate(
[
Expand Down Expand Up @@ -67,6 +79,8 @@ public function run()
}
}
$this->info("#### Done. ####");

Storage::put('public/lcsc/city-state-country.sql', file_get_contents(__DIR__ . "/../city-state-country.sql"));
}
}

Expand Down Expand Up @@ -130,4 +144,5 @@ private function info($string)
{
echo $string . PHP_EOL;
}

}
Loading

0 comments on commit b50a7ba

Please sign in to comment.