Add the rest of available countries. #48

Merged
krzysiej merged 3 commits from feature/new-countries into master 2026-02-17 09:34:55 +01:00
Showing only changes of commit a388b53cff - Show all commits

View File

@@ -6,6 +6,7 @@ namespace Krzysiej\RyobiCrawler\Command;
use Illuminate\Database\Capsule\Manager as Capsule; use Illuminate\Database\Capsule\Manager as Capsule;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Krzysiej\RyobiCrawler\Models\Country;
use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
@@ -93,26 +94,66 @@ class Migrate extends Command
$table->timestamps(); $table->timestamps();
}); });
} }
$id = Capsule::table('countries')->insertGetId( 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', 'countryName' => 'Poland',
'cultureCode' => 'pl-PL', 'productsUrl' => 'https://pl.ryobitools.eu/api/product-listing/get-products',
'currency' => 'PLN', 'cultureCode' => 'pl-PL',
'locale' => 'pl', 'currency' => 'PLN',
'created_at' => now(), 'locale' => 'pl',
'updated_at' => now(), 'created_at' => now(),
]); 'updated_at' => now(),
Capsule::table('countries')->insert([ ]);
'countryName' => 'UK', }
'productsUrl' => 'https://uk.ryobitools.eu/api/product-listing/get-products', if (Capsule::schema()->hasTable('countries') && !Country::where('countryName', 'UK')->exists()) {
'cultureCode' => 'en-GB', Capsule::table('countries')->insert([
'currency' => 'GBP', 'countryName' => 'UK',
'locale' => 'en', 'productsUrl' => 'https://uk.ryobitools.eu/api/product-listing/get-products',
'created_at' => now(), 'cultureCode' => 'en-GB',
'updated_at' => now(), 'currency' => 'GBP',
] 'locale' => 'en',
); 'created_at' => now(),
'updated_at' => now(),
]
);
}
if (Capsule::schema()->hasTable('countries') && !Country::where('countryName', 'Netherlands')->exists()) {
Capsule::table('countries')->insert([
'countryName' => 'Netherlands',
'productsUrl' => 'https://nl.ryobitools.eu/api/product-listing/get-products',
'cultureCode' => 'nl-NL',
'currency' => 'EUR',
'locale' => 'nl',
'created_at' => now(),
'updated_at' => now(),
]
);
}
if (Capsule::schema()->hasTable('countries') && !Country::where('countryName', 'France')->exists()) {
Capsule::table('countries')->insert([
'countryName' => 'France',
'productsUrl' => 'https://fr.ryobitools.eu/api/product-listing/get-products',
'cultureCode' => 'fr-FR',
'currency' => 'EUR',
'locale' => 'fr',
'created_at' => now(),
'updated_at' => now(),
]
);
}
if (Capsule::schema()->hasTable('countries') && !Country::where('countryName', 'Spain')->exists()) {
Capsule::table('countries')->insert([
'countryName' => 'Spain',
'productsUrl' => 'https://es.ryobitools.eu/api/product-listing/get-products',
'cultureCode' => 'es-ES',
'currency' => 'EUR',
'locale' => 'es',
'created_at' => now(),
'updated_at' => now(),
]
);
}
if (!Capsule::schema()->hasColumn('products', 'country_id')) { if (!Capsule::schema()->hasColumn('products', 'country_id')) {
Capsule::schema()->table('products', function (Blueprint $table) use ($id) { Capsule::schema()->table('products', function (Blueprint $table) use ($id) {
@@ -174,9 +215,11 @@ class Migrate extends Command
public function index(): void public function index(): void
{ {
Capsule::schema()->table('products', function (Blueprint $table) { if (!count(Capsule::select('SELECT name FROM sqlite_master WHERE type = "index" and name = "products_skuid_country_id_unique"'))) {
$table->integer('skuID')->unique(false)->change(); Capsule::schema()->table('products', function (Blueprint $table) {
$table->unique(['skuID', 'country_id']); $table->integer('skuID')->unique(false)->change();
}); $table->unique(['skuID', 'country_id']);
});
}
} }
} }