feature/handle-multiple-countries #45

Merged
krzysiej merged 5 commits from feature/handle-multiple-countries into master 2026-01-17 17:07:40 +01:00
Showing only changes of commit 4983f868df - Show all commits

View File

@@ -11,6 +11,7 @@ use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
use function Symfony\Component\Clock\now;
#[AsCommand(name: 'app:migrate', description: 'Create database and rum migrations')] #[AsCommand(name: 'app:migrate', description: 'Create database and rum migrations')]
class Migrate extends Command class Migrate extends Command
@@ -39,6 +40,7 @@ class Migrate extends Command
$this->createPricesTable(); $this->createPricesTable();
$this->createStocksTable(); $this->createStocksTable();
$this->addColumns(); $this->addColumns();
$this->createCountriesTable();
return Command::SUCCESS; return Command::SUCCESS;
} }
@@ -76,6 +78,7 @@ class Migrate extends Command
}); });
} }
} }
public function createCountriesTable(): void public function createCountriesTable(): void
{ {
if (!Capsule::schema()->hasTable('countries')) { if (!Capsule::schema()->hasTable('countries')) {
@@ -86,6 +89,26 @@ class Migrate extends Command
$table->timestamps(); $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 public function createStocksTable(): void