Skip to content

Commit

Permalink
Merge pull request #1626 from JaberWiki/master
Browse files Browse the repository at this point in the history
[feat] Include a optional flag `subpath` for rollbacking module's specific migration file
  • Loading branch information
dcblogdev authored Oct 18, 2023
2 parents c9e9a03 + 24509b0 commit e0e1191
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 = '';

/**
* 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 (!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
Expand Down

0 comments on commit e0e1191

Please sign in to comment.