FEATURE #2520: add template for creating new table

This commit is contained in:
Michal Kváček
2017-09-01 23:49:34 +02:00
parent a5b6f6fa0d
commit 2d66cf672a
4 changed files with 54 additions and 7 deletions
@@ -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$');
}
}
+16 -2
View File
@@ -1,14 +1,28 @@
<?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()
{
$TableName$;
Schema::table('$TableName$', function (Blueprint $table) {
});
}
/**
* Rollback migration
*/
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.
* @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.
* @var string
@@ -19,15 +19,16 @@ class CreateMigration extends Command
protected $description = 'Make new migration for given module';
protected $migrationName;
protected $tableName;
protected $moduleName;
/**
* Execute the console command.
*/
public function handle()
{
$module = $this->argument('module');
$this->moduleName = $module = $this->argument('module');
$this->migrationName = $name = $this->argument('name');
$this->tableName = $this->option('table');
$this->tableName = trim($this->option('table'), ' =');
$modules = Module::where('enabled', true)
->get()
@@ -51,7 +52,8 @@ class CreateMigration extends Command
$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);
$migrationName = $path . $this->getMigrationName($name);
@@ -72,6 +74,7 @@ class CreateMigration extends Command
{
$replace = [
'$MigrationName$' => studly_case($this->migrationName),
'$ModuleName$' => $this->moduleName,
'$TableName$' => $this->tableName
];
@@ -39,8 +39,9 @@ class RunMigrations extends Command
foreach ($modules as $module) {
$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 = str_replace(base_path(), '', $path);
$this->call($command, ['--path' => $path]);
}