diff --git a/src/Commands/MigrateRollbackCommand.php b/src/Commands/MigrateRollbackCommand.php index 920c93b21..3afc81147 100644 --- a/src/Commands/MigrateRollbackCommand.php +++ b/src/Commands/MigrateRollbackCommand.php @@ -66,7 +66,7 @@ public function rollback($module) $module = $this->module->findOrFail($module); } - $migrator = new Migrator($module, $this->getLaravel()); + $migrator = new Migrator($module, $this->getLaravel(), $this->option('subpath')); $database = $this->option('database'); @@ -111,6 +111,7 @@ protected function getOptions() ['database', null, InputOption::VALUE_OPTIONAL, 'The database connection to use.'], ['force', null, InputOption::VALUE_NONE, 'Force the operation to run when in production.'], ['pretend', null, InputOption::VALUE_NONE, 'Dump the SQL queries that would be run.'], + ['subpath', null, InputOption::VALUE_OPTIONAL, 'Indicate a subpath for modules specific migration file'] ]; } } diff --git a/src/Migrations/Migrator.php b/src/Migrations/Migrator.php index 75901a19d..c3a1afd61 100644 --- a/src/Migrations/Migrator.php +++ b/src/Migrations/Migrator.php @@ -23,6 +23,14 @@ class Migrator */ protected $laravel; + /** + * Optional subpath for specific migration file. + * + * @var string|null + * @example subpath 2000_01_01_000000_create_example_table.php + */ + protected $subpath = ''; + /** * The database connection to be used * @@ -34,11 +42,13 @@ class Migrator * Create new instance. * @param Module $module * @param Application $application + * @param string|null $subpath */ - public function __construct(Module $module, Application $application) + public function __construct(Module $module, Application $application, $subpath = null) { $this->module = $module; $this->laravel = $application; + $this->subpath = $subpath; } /** @@ -88,7 +98,11 @@ public function getPath() */ public function getMigrations($reverse = false) { - $files = $this->laravel['files']->glob($this->getPath() . '/*_*.php'); + if (!empty($this->subpath)) { + $files = $this->laravel['files']->glob($this->getPath() . '/' . $this->subpath); + } else { + $files = $this->laravel['files']->glob($this->getPath() . '/*_*.php'); + } // Once we have the array of files in the directory we will just remove the // extension and take the basename of the file which is all we need when