Add parameter recreate to migration command.
This commit is contained in:
@@ -9,13 +9,25 @@ 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\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
#[AsCommand(name: 'app:migrate', description: 'Create database and rum migrations')]
|
||||
class Migrate extends Command
|
||||
{
|
||||
private const RECREATE_OPTION = 'recreate';
|
||||
|
||||
protected function configure(): void
|
||||
{
|
||||
$this->addOption(self::RECREATE_OPTION, null, InputOption::VALUE_OPTIONAL, 'Recreate database file event if exist and has data.');
|
||||
}
|
||||
|
||||
public function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
if (true === $input->hasOption(self::RECREATE_OPTION)) {
|
||||
unlink(__DIR__ . '/../../database.sqlite');
|
||||
//sleep(5);
|
||||
}
|
||||
touch(__DIR__ . '/../../database.sqlite');
|
||||
$capsule = new Capsule;
|
||||
$capsule->addConnection([
|
||||
@@ -24,10 +36,6 @@ class Migrate extends Command
|
||||
]);
|
||||
$capsule->setAsGlobal();
|
||||
$capsule->bootEloquent();
|
||||
}
|
||||
|
||||
public function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$this->createProductsTable();
|
||||
$this->createPricesTable();
|
||||
$this->createStocksTable();
|
||||
|
||||
Reference in New Issue
Block a user