From b503dbf33de45723b9776c02819e595c9ce1140a Mon Sep 17 00:00:00 2001 From: lukinovec Date: Mon, 16 Oct 2023 01:50:59 +0200 Subject: [PATCH] Fix rollback command (#14) * Add and use setParameterDefaults() * Correct rollback test * Check ignored parameters instead of directly checking the command's options * Delete --path setting from the test * Revert test changes * Delete new lines --- src/Commands/Rollback.php | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/Commands/Rollback.php b/src/Commands/Rollback.php index f9d9dac0..651766f7 100644 --- a/src/Commands/Rollback.php +++ b/src/Commands/Rollback.php @@ -27,11 +27,7 @@ class Rollback extends RollbackCommand public function handle(): int { - foreach (config('tenancy.migration_parameters') as $parameter => $value) { - if (! $this->input->hasParameterOption($parameter)) { - $this->input->setOption(ltrim($parameter, '-'), $value); - } - } + $this->setParameterDefaults(); if (! $this->confirmToProceed()) { return 1; @@ -55,4 +51,22 @@ class Rollback extends RollbackCommand { return 'tenants:rollback'; } + + protected function setParameterDefaults(): void + { + // Parameters that this command doesn't support, but can be in tenancy.migration_parameters + $ignoredParameters = [ + '--seed', + '--seeder', + '--isolated', + '--schema-path', + ]; + + foreach (config('tenancy.migration_parameters') as $parameter => $value) { + // Only set the default if the option isn't set + if (! in_array($parameter, $ignoredParameters) && ! $this->input->hasParameterOption($parameter)) { + $this->input->setOption(ltrim($parameter, '-'), $value); + } + } + } }