diff --git a/app/CMS/Modules/Stubs/Migrations/create.stub b/app/CMS/Modules/Stubs/Migrations/create.stub new file mode 100644 index 00000000..abdaad93 --- /dev/null +++ b/app/CMS/Modules/Stubs/Migrations/create.stub @@ -0,0 +1,29 @@ +increments('id'); + $table->timestamps(); + }); + } + + /** + * Rollback migration + */ + public function down() + { + Schema::dropIfExists('$TableName$'); + } +} \ No newline at end of file diff --git a/app/CMS/Modules/Stubs/Migrations/new.stub b/app/CMS/Modules/Stubs/Migrations/new.stub index e1873063..9d5b2fb1 100644 --- a/app/CMS/Modules/Stubs/Migrations/new.stub +++ b/app/CMS/Modules/Stubs/Migrations/new.stub @@ -1,14 +1,28 @@ 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 ]; diff --git a/app/Console/Commands/Modules/RunMigrations.php b/app/Console/Commands/Modules/RunMigrations.php index 54fe6d16..0e6bd313 100644 --- a/app/Console/Commands/Modules/RunMigrations.php +++ b/app/Console/Commands/Modules/RunMigrations.php @@ -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]); }