Update packages. Add docker support, move migration to command, add stocks as a new table.
This commit is contained in:
91
src/Command/Migrate.php
Normal file
91
src/Command/Migrate.php
Normal file
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Krzysiej\RyobiCrawler\Command;
|
||||
|
||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
#[AsCommand(name: 'app:migrate', description: 'Create database and rum migrations')]
|
||||
class Migrate extends Command
|
||||
{
|
||||
protected function configure(): void
|
||||
{
|
||||
touch(__DIR__ . '/../../database.sqlite');
|
||||
$capsule = new Capsule;
|
||||
$capsule->addConnection([
|
||||
'driver' => 'sqlite',
|
||||
'database' => __DIR__ . '/../../database.sqlite',
|
||||
]);
|
||||
$capsule->setAsGlobal();
|
||||
$capsule->bootEloquent();
|
||||
}
|
||||
|
||||
public function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$this->createProductsTable();
|
||||
$this->createPricesTable();
|
||||
$this->createStocksTable();
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
public function createProductsTable(): void
|
||||
{
|
||||
if (!Capsule::schema()->hasTable('products')) {
|
||||
Capsule::schema()->create('products', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->string('name');
|
||||
$table->integer('skuID')->unique();
|
||||
$table->integer('agilityID');
|
||||
$table->integer('availableQuantity');
|
||||
$table->integer('stock');
|
||||
$table->json('categories');
|
||||
$table->string('image');
|
||||
$table->string('subTitle');
|
||||
$table->string('variantCode');
|
||||
$table->string('modelCode');
|
||||
$table->string('url');
|
||||
$table->boolean('starred')->default(false);
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public function createPricesTable(): void
|
||||
{
|
||||
if (!Capsule::schema()->hasTable('prices')) {
|
||||
Capsule::schema()->create('prices', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->foreignId('product_id');
|
||||
$table->float('price');
|
||||
$table->float('productStandardPrice');
|
||||
$table->float('lowestProductPrice30Days');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public function createStocksTable(): void
|
||||
{
|
||||
if (!Capsule::schema()->hasTable('stocks')) {
|
||||
Capsule::schema()->create('stocks', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->foreignId('product_id');
|
||||
$table->integer('availableQuantity');
|
||||
$table->integer('stock');
|
||||
$table->boolean('isInStock');
|
||||
$table->boolean('previouslyHadStock');
|
||||
$table->boolean('isNew');
|
||||
$table->boolean('isComingSoon');
|
||||
$table->boolean('isOnSale');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user