From 4983f868df3ca7d57147faa083538c66256a2aa5 Mon Sep 17 00:00:00 2001 From: Krzysiej Date: Fri, 16 Jan 2026 11:02:57 +0100 Subject: [PATCH] Start working on handling multiple countries at once --- src/Command/Migrate.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/Command/Migrate.php b/src/Command/Migrate.php index 5345155..07be8ca 100644 --- a/src/Command/Migrate.php +++ b/src/Command/Migrate.php @@ -11,6 +11,7 @@ use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; +use function Symfony\Component\Clock\now; #[AsCommand(name: 'app:migrate', description: 'Create database and rum migrations')] class Migrate extends Command @@ -39,6 +40,7 @@ class Migrate extends Command $this->createPricesTable(); $this->createStocksTable(); $this->addColumns(); + $this->createCountriesTable(); return Command::SUCCESS; } @@ -76,6 +78,7 @@ class Migrate extends Command }); } } + public function createCountriesTable(): void { if (!Capsule::schema()->hasTable('countries')) { @@ -86,6 +89,26 @@ class Migrate extends Command $table->timestamps(); }); } + $id = Capsule::table('countries')->insertGetId( + [ + 'countryName' => 'Poland', + 'productsUrl' => 'https://pl.ryobitools.eu/api/product-listing/get-products', + 'created_at' => now(), + 'updated_at' => now(), + ]); + Capsule::table('countries')->insert([ + 'countryName' => 'UK', + 'productsUrl' => 'https://uk.ryobitools.eu/api/product-listing/get-products', + 'created_at' => now(), + 'updated_at' => now(), + ] + ); + + if (!Capsule::schema()->hasColumn('products', 'country_id')) { + Capsule::schema()->table('products', function (Blueprint $table) use ($id) { + $table->foreignId('country_id')->default($id)->references('id')->on('countries'); + }); + } } public function createStocksTable(): void