|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Cortex\Foundation\Console\Commands; |
|
6
|
|
|
|
|
7
|
|
|
use Illuminate\Database\Console\Migrations\MigrateMakeCommand as BaseMigrateMakeCommand; |
|
8
|
|
|
|
|
9
|
|
|
class MigrateMakeCommand extends BaseMigrateMakeCommand |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* The console command signature. |
|
13
|
|
|
* |
|
14
|
|
|
* @var string |
|
15
|
|
|
*/ |
|
16
|
|
|
protected $signature = 'make:migration {name : The name of the migration.} |
|
17
|
|
|
{--module= : The name of the module.} |
|
18
|
|
|
{--create= : The table to be created.} |
|
19
|
|
|
{--table= : The table to migrate.} |
|
20
|
|
|
{--path= : The location where the migration file should be created.}'; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Write the migration file to disk. |
|
24
|
|
|
* |
|
25
|
|
|
* @param string $name |
|
26
|
|
|
* @param string $table |
|
27
|
|
|
* @param bool $create |
|
28
|
|
|
* @return string |
|
|
|
|
|
|
29
|
|
|
*/ |
|
30
|
|
|
protected function writeMigration($name, $table, $create) |
|
31
|
|
|
{ |
|
32
|
|
|
$this->makeDirectory($this->getMigrationPath()); |
|
33
|
|
|
|
|
34
|
|
|
parent::writeMigration($name, $table, $create); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Build the directory for the class if necessary. |
|
39
|
|
|
* |
|
40
|
|
|
* @param string $path |
|
41
|
|
|
* @return string |
|
42
|
|
|
*/ |
|
43
|
|
|
protected function makeDirectory($path) |
|
44
|
|
|
{ |
|
45
|
|
|
if (! $this->laravel['files']->isDirectory($path)) { |
|
46
|
|
|
$this->laravel['files']->makeDirectory($path, 0777, true, true); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
return $path; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Get migration path (either specified by '--path' or '--module' options). |
|
54
|
|
|
* |
|
55
|
|
|
* @return string |
|
56
|
|
|
*/ |
|
57
|
|
|
protected function getMigrationPath() |
|
58
|
|
|
{ |
|
59
|
|
|
if (! is_null($targetPath = $this->input->getOption('path'))) { |
|
60
|
|
|
return $this->laravel->basePath().'/'.$targetPath; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
if (! is_null($module = $this->input->getOption('module')) && $this->laravel->files->exists($modulePath = $this->laravel->path().DIRECTORY_SEPARATOR.$module)) { |
|
|
|
|
|
|
64
|
|
|
return $modulePath.DIRECTORY_SEPARATOR.'database'.DIRECTORY_SEPARATOR.'migrations'; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
return $this->laravel->databasePath().DIRECTORY_SEPARATOR.'migrations'; |
|
|
|
|
|
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.