-
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathGenerateMigrationCommand.php
More file actions
66 lines (51 loc) · 1.74 KB
/
GenerateMigrationCommand.php
File metadata and controls
66 lines (51 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
declare(strict_types=1);
namespace Bow\Console\Command\Generator;
use Bow\Console\AbstractCommand;
use Bow\Console\Color;
use Bow\Console\Generator;
use Bow\Support\Str;
class GenerateMigrationCommand extends AbstractCommand
{
/**
* Create a migration command
*
* @param string $model
*
* @return void
* @throws ErrorException
*/
public function run(string $model): void
{
$create_at = date("YmdHis");
$filename = sprintf("Version%s%s", $create_at, ucfirst(Str::camel($model)));
$generator = new Generator(
$this->setting->getMigrationDirectory(),
$filename
);
$parameters = $this->arg->getParameters();
if ($parameters->has('--create') && $parameters->has('--table')) {
$this->throwFailsCommand('bad command', 'add help');
}
$type = "model/standard";
if ($parameters->has('--table')) {
if ($parameters->get('--table') === true) {
$this->throwFailsCommand('bad command option [--table=table]', 'add help');
}
$table = $parameters->get('--table');
$type = 'model/table';
} elseif ($parameters->has('--create')) {
if ($parameters->get('--create') === true) {
$this->throwFailsCommand('bad command option [--create=table]', 'add help');
}
$table = $parameters->get('--create');
$type = 'model/create';
}
$generator->write($type, [
'table' => $table ?? 'table_name',
'className' => $filename
]);
// Print console information
echo Color::green('The migration file has been successfully created') . "\n";
}
}