Skip to content

Commit

Permalink
[feat] Indicate a sub-path for modules specific migration file
Browse files Browse the repository at this point in the history
Co-Authored-By: Abdul Majid Irfan <[email protected]>
  • Loading branch information
JaberWiki and Irfan-Majid committed Apr 27, 2023
1 parent 00b7bec commit bf20927
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/Commands/MigrateRollbackCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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']
];
}
}
18 changes: 16 additions & 2 deletions src/Migrations/Migrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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;
}

/**
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit bf20927

Please sign in to comment.