diff --git a/src/Command/Migrate.php b/src/Command/Migrate.php index 96880d5..5e5dc7a 100644 --- a/src/Command/Migrate.php +++ b/src/Command/Migrate.php @@ -6,6 +6,7 @@ namespace Krzysiej\RyobiCrawler\Command; use Illuminate\Database\Capsule\Manager as Capsule; use Illuminate\Database\Schema\Blueprint; +use Krzysiej\RyobiCrawler\Models\Country; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; @@ -93,26 +94,30 @@ class Migrate extends Command $table->timestamps(); }); } - $id = Capsule::table('countries')->insertGetId( - [ - 'countryName' => 'Poland', - 'productsUrl' => 'https://pl.ryobitools.eu/api/product-listing/get-products', - 'cultureCode' => 'pl-PL', - 'currency' => 'PLN', - 'locale' => 'pl', - 'created_at' => now(), - 'updated_at' => now(), - ]); - Capsule::table('countries')->insert([ - 'countryName' => 'UK', - 'productsUrl' => 'https://uk.ryobitools.eu/api/product-listing/get-products', - 'cultureCode' => 'en-GB', - 'currency' => 'GBP', - 'locale' => 'en', - 'created_at' => now(), - 'updated_at' => now(), - ] - ); + if (Capsule::schema()->hasTable('countries') && !Country::where('countryName', 'Poland')->exists()) { + $id = Capsule::table('countries')->insertGetId( + [ + 'countryName' => 'Poland', + 'productsUrl' => 'https://pl.ryobitools.eu/api/product-listing/get-products', + 'cultureCode' => 'pl-PL', + 'currency' => 'PLN', + 'locale' => 'pl', + 'created_at' => now(), + 'updated_at' => now(), + ]); + } + if (Capsule::schema()->hasTable('countries') && !Country::where('countryName', 'UK')->exists()) { + Capsule::table('countries')->insert([ + 'countryName' => 'UK', + 'productsUrl' => 'https://uk.ryobitools.eu/api/product-listing/get-products', + 'cultureCode' => 'en-GB', + 'currency' => 'GBP', + 'locale' => 'en', + 'created_at' => now(), + 'updated_at' => now(), + ] + ); + } if (!Capsule::schema()->hasColumn('products', 'country_id')) { Capsule::schema()->table('products', function (Blueprint $table) use ($id) {