Drop the generate:migration command ()

Core source code should contain things necessary for core to run. Development tooling like this belongs in external packages, like the upcoming Flarum CLI.
This commit is contained in:
Alexander Skvortsov 2021-03-16 12:41:07 -04:00 committed by GitHub
parent 1b5b143930
commit 233b97329c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 0 additions and 303 deletions

@ -12,7 +12,3 @@ disabled:
- phpdoc_order
- phpdoc_separation
- phpdoc_types
finder:
exclude:
- "stubs"

@ -9,7 +9,6 @@
namespace Flarum\Console;
use Flarum\Database\Console\GenerateMigrationCommand;
use Flarum\Database\Console\MigrateCommand;
use Flarum\Database\Console\ResetCommand;
use Flarum\Foundation\AbstractServiceProvider;
@ -26,7 +25,6 @@ class ConsoleServiceProvider extends AbstractServiceProvider
$this->container->singleton('flarum.console.commands', function () {
return [
CacheClearCommand::class,
GenerateMigrationCommand::class,
InfoCommand::class,
MigrateCommand::class,
ResetCommand::class,

@ -1,104 +0,0 @@
<?php
/*
* This file is part of Flarum.
*
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
*/
namespace Flarum\Database\Console;
use Flarum\Console\AbstractCommand;
use Flarum\Database\MigrationCreator;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
class GenerateMigrationCommand extends AbstractCommand
{
/**
* @var MigrationCreator
*/
protected $creator;
/**
* @param MigrationCreator $creator
*/
public function __construct(MigrationCreator $creator)
{
parent::__construct();
$this->creator = $creator;
}
/**
* {@inheritdoc}
*/
protected function configure()
{
$this
->setName('generate:migration')
->setDescription('Generate a migration')
->addArgument(
'name',
InputArgument::REQUIRED,
'The name of the migration.'
)
->addOption(
'extension',
null,
InputOption::VALUE_REQUIRED,
'The extension to generate the migration for.'
)
->addOption(
'create',
null,
InputOption::VALUE_REQUIRED,
'The table to be created.'
)
->addOption(
'table',
null,
InputOption::VALUE_REQUIRED,
'The table to migrate.'
);
}
/**
* {@inheritdoc}
*/
protected function fire()
{
$name = $this->input->getArgument('name');
$extension = $this->input->getOption('extension');
$table = $this->input->getOption('table');
$create = $this->input->getOption('create');
if (! $table && is_string($create)) {
$table = $create;
}
$this->writeMigration($name, $extension, $table, $create);
}
/**
* Write the migration file to disk.
*
* @param string $name
* @param string $extension
* @param string $table
* @param bool $create
* @return string
*/
protected function writeMigration($name, $extension, $table, $create)
{
$path = $this->creator->create($name, $extension, $table, $create);
$file = pathinfo($path, PATHINFO_FILENAME);
$this->info("Created migration: $file");
}
}

@ -1,146 +0,0 @@
<?php
/*
* This file is part of Flarum.
*
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
*/
namespace Flarum\Database;
use Flarum\Foundation\Paths;
use Illuminate\Filesystem\Filesystem;
class MigrationCreator
{
/**
* The filesystem instance.
*
* @var Filesystem
*/
protected $files;
/**
* @var Paths
*/
protected $paths;
/**
* Create a new migrator instance.
*
* @param Filesystem $files
* @param Paths $paths
*/
public function __construct(Filesystem $files, Paths $paths)
{
$this->files = $files;
$this->paths = $paths;
}
/**
* Create a new migration for the given extension.
*
* @param string $name
* @param string $extension
* @param string $table
* @param bool $create
* @return string
*/
public function create($name, $extension = null, $table = null, $create = false)
{
$migrationPath = $this->getMigrationPath($extension);
$path = $this->getPath($name, $migrationPath);
$stub = $this->getStub($table, $create);
$this->files->put($path, $this->populateStub($stub, $table));
return $path;
}
/**
* Get the migration stub file.
*
* @param string $table
* @param bool $create
* @return string
*/
protected function getStub($table, $create)
{
if (is_null($table)) {
return $this->files->get($this->getStubPath().'/blank.stub');
}
// We also have stubs for creating new tables and modifying existing tables
// to save the developer some typing when they are creating a new tables
// or modifying existing tables. We'll grab the appropriate stub here.
$stub = $create ? 'create.stub' : 'update.stub';
return $this->files->get($this->getStubPath()."/{$stub}");
}
/**
* Populate the place-holders in the migration stub.
*
* @param string $stub
* @param string $table
* @return string
*/
protected function populateStub($stub, $table)
{
$replacements = [
'{{table}}' => $table
];
return str_replace(array_keys($replacements), array_values($replacements), $stub);
}
/**
* Get the full path name to the migration directory.
*
* @param string $extension
* @return string
*/
protected function getMigrationPath($extension)
{
if ($extension) {
return $this->paths->vendor.'/'.$extension.'/migrations';
} else {
return __DIR__.'/../../migrations';
}
}
/**
* Get the full path name to the migration.
*
* @param string $name
* @param string $path
* @return string
*/
protected function getPath($name, $path)
{
return $path.'/'.$this->getDatePrefix().'_'.$name.'.php';
}
/**
* Get the date prefix for the migration.
*
* @return string
*/
protected function getDatePrefix()
{
return date('Y_m_d_His');
}
/**
* Get the path to the stubs.
*
* @return string
*/
protected function getStubPath()
{
return __DIR__.'/../../stubs/migrations';
}
}

@ -1,13 +0,0 @@
<?php
use Illuminate\Database\Schema\Builder;
return [
'up' => function (Builder $schema) {
//
},
'down' => function (Builder $schema) {
//
}
];

@ -1,16 +0,0 @@
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder;
return [
'up' => function (Builder $schema) {
$schema->create('{{table}}', function (Blueprint $table) {
$table->increments('id');
});
},
'down' => function (Builder $schema) {
$schema->drop('{{table}}');
}
];

@ -1,18 +0,0 @@
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder;
return [
'up' => function (Builder $schema) {
$schema->table('{{table}}', function (Blueprint $table) {
//
});
},
'down' => function (Builder $schema) {
$schema->table('{{table}}', function (Blueprint $table) {
//
});
}
];