FEATURE #2520: add template for creating new table
This commit is contained in:
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Modules\$ModuleName$\Database\Migrations;
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class $MigrationName$ extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run migration
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::create('$TableName$', function (Blueprint $table) {
|
||||||
|
$table->increments('id');
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rollback migration
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('$TableName$');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,14 +1,28 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class $MigrationName$
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class $MigrationName$ extends Migration
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Run migration
|
||||||
|
*/
|
||||||
public function up()
|
public function up()
|
||||||
{
|
{
|
||||||
$TableName$;
|
Schema::table('$TableName$', function (Blueprint $table) {
|
||||||
|
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rollback migration
|
||||||
|
*/
|
||||||
public function down()
|
public function down()
|
||||||
{
|
{
|
||||||
|
Schema::table('$TableName$', function (Blueprint $table) {
|
||||||
|
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -11,7 +11,7 @@ class CreateMigration extends Command
|
|||||||
* The name and signature of the console command.
|
* The name and signature of the console command.
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $signature = 'module:make-migration {module?} {name?} {--t|table= : Table name}';
|
protected $signature = 'module:make-migration {module?} {name?} {--t|table= : Table name} {--c|create : Use template for creating new table}';
|
||||||
/**
|
/**
|
||||||
* The console command description.
|
* The console command description.
|
||||||
* @var string
|
* @var string
|
||||||
@@ -19,15 +19,16 @@ class CreateMigration extends Command
|
|||||||
protected $description = 'Make new migration for given module';
|
protected $description = 'Make new migration for given module';
|
||||||
protected $migrationName;
|
protected $migrationName;
|
||||||
protected $tableName;
|
protected $tableName;
|
||||||
|
protected $moduleName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute the console command.
|
* Execute the console command.
|
||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
$module = $this->argument('module');
|
$this->moduleName = $module = $this->argument('module');
|
||||||
$this->migrationName = $name = $this->argument('name');
|
$this->migrationName = $name = $this->argument('name');
|
||||||
$this->tableName = $this->option('table');
|
$this->tableName = trim($this->option('table'), ' =');
|
||||||
|
|
||||||
$modules = Module::where('enabled', true)
|
$modules = Module::where('enabled', true)
|
||||||
->get()
|
->get()
|
||||||
@@ -51,7 +52,8 @@ class CreateMigration extends Command
|
|||||||
$name = $this->ask('Input migration name');
|
$name = $this->ask('Input migration name');
|
||||||
}
|
}
|
||||||
|
|
||||||
$content = file_get_contents(config('modules.paths.stubs') . '/Migrations/new.stub');
|
$stubName = $this->option('create') ? 'create' : 'new';
|
||||||
|
$content = file_get_contents(config('modules.paths.stubs') . '/Migrations/'.$stubName.'.stub');
|
||||||
$content = $this->replacePlaceholders($content);
|
$content = $this->replacePlaceholders($content);
|
||||||
|
|
||||||
$migrationName = $path . $this->getMigrationName($name);
|
$migrationName = $path . $this->getMigrationName($name);
|
||||||
@@ -72,6 +74,7 @@ class CreateMigration extends Command
|
|||||||
{
|
{
|
||||||
$replace = [
|
$replace = [
|
||||||
'$MigrationName$' => studly_case($this->migrationName),
|
'$MigrationName$' => studly_case($this->migrationName),
|
||||||
|
'$ModuleName$' => $this->moduleName,
|
||||||
'$TableName$' => $this->tableName
|
'$TableName$' => $this->tableName
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
@@ -39,8 +39,9 @@ class RunMigrations extends Command
|
|||||||
foreach ($modules as $module) {
|
foreach ($modules as $module) {
|
||||||
$this->info('Migrating '.$module->static_name);
|
$this->info('Migrating '.$module->static_name);
|
||||||
|
|
||||||
$basePath = $module->is_template ? config('modules.path.template') : config('modules.paths.modules');
|
$basePath = $module->is_template ? config('modules.path.templates') : config('modules.paths.modules');
|
||||||
$path = $basePath . '/' . $module->static_name . '/Database/Migrations/';
|
$path = $basePath . '/' . $module->static_name . '/Database/Migrations/';
|
||||||
|
$path = str_replace(base_path(), '', $path);
|
||||||
|
|
||||||
$this->call($command, ['--path' => $path]);
|
$this->call($command, ['--path' => $path]);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user