Skip to content

Commit

Permalink
Возможность указывать путь до директории с миграциями (#7)
Browse files Browse the repository at this point in the history
* allow specify path to migrations for git

* fix

* lint

Co-authored-by: vetal <vitaly.laz@okwork.io>
  • Loading branch information
lazeevv and vetal committed Feb 1, 2022
1 parent a30441a commit 528ee06
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/Console/RollbackMissingMigrations.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ protected function getMigrationsNamesForRollback(): array

protected function rollback(string $artisanPath): void
{
$command = sprintf('php %s migrate:rollback %s %s',
$command = sprintf(
'php %s migrate:rollback %s %s',
$artisanPath,
$this->getOldPaths(),
$this->getRealpath()
Expand Down
9 changes: 6 additions & 3 deletions src/Console/RollbackNewMigrations.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@

class RollbackNewMigrations extends Command
{
private const COMMAND = 'git ls-tree --name-only origin/master database/migrations/';
private const COMMAND_PATTERN = 'git ls-tree --name-only origin/master {git_migrations_path}';

protected $signature = 'rollback_new_migrations:rollback';
protected $signature = 'rollback_new_migrations:rollback {--git_migrations_path=}';
protected $description = 'Rollback new migrations (default way for k8s staging)';

public function handle(): void
Expand All @@ -26,7 +26,10 @@ public function handle(): void
return;
}

$migrationsFromMaster = collect(explode(PHP_EOL, shell_exec(self::COMMAND)))
$gitMigrationsPath = $this->option('git_migrations_path') ?? 'database/migrations/';
$gitCommand = str_replace('{git_migrations_path}', $gitMigrationsPath, self::COMMAND_PATTERN);

$migrationsFromMaster = collect(explode(PHP_EOL, shell_exec($gitCommand)))
->filter()
->map(fn (string $path) => new SplFileInfo(base_path($path)));
$migrationsFromCurrent = collect(File::files(base_path('database/migrations')));
Expand Down

0 comments on commit 528ee06

Please sign in to comment.