From bf2092721395df0d2a9b4e2770b243b36befc23c Mon Sep 17 00:00:00 2001 From: Hossain Mohammad Shahidullah Jaber Date: Thu, 27 Apr 2023 11:54:26 +0600 Subject: [PATCH] [feat] Indicate a sub-path for modules specific migration file Co-Authored-By: Abdul Majid Irfan <78084618+Irfan-Majid@users.noreply.github.com> --- src/Commands/MigrateRollbackCommand.php | 3 ++- src/Migrations/Migrator.php | 18 ++++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) 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..d2bd00d43 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 = null; + /** * 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 ($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