From f3615232aafcd8c3224c3cfc2d60e120f705da0f Mon Sep 17 00:00:00 2001 From: Dimitri Sitchet Tomkeu Date: Sun, 11 Oct 2026 18:32:33 +0100 Subject: [PATCH] feat: rollback des migrations d'un namespace particulier --- src/Commands/Migration/Refresh.php | 19 +++++++++---------- src/Commands/Migration/Rollback.php | 8 +++++--- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/Commands/Migration/Refresh.php b/src/Commands/Migration/Refresh.php index 130428f..49c1ab7 100644 --- a/src/Commands/Migration/Refresh.php +++ b/src/Commands/Migration/Refresh.php @@ -52,16 +52,17 @@ public function handle() $this->eol()->info('Réinitialisation et réexécution des migrations...'); - $group = $this->option('group', config('database.connection', 'default')); - $seed = $this->option('seed') === true; + $seed = $this->option('seed') === true; + $options = [ + '--group' => $group = $this->option('group', config('database.connection', 'default')), + '--all' => $this->option('all') === true, + '--force' => $this->option('force') === true, + '--namespace' => $this->option('namespace'), + ]; $this->newLine()->comment('Étape 1/2: Annulation de toutes les migrations'); - $rollbackResult = $this->call('migrate:rollback', options: [ - '--group' => $group, - '--all' => true, - '--force' => true, - ]); + $rollbackResult = $this->call('migrate:rollback', options: $options); if ($rollbackResult !== EXIT_SUCCESS) { $this->error('Échec de l\'annulation des migrations.'); @@ -71,9 +72,7 @@ public function handle() $this->newLine()->comment('Étape 2/2: Réexécution des migrations'); - $migrateResult = $this->call('migrate', options: [ - '--group' => $group, - ]); + $migrateResult = $this->call('migrate', options: $options); if ($migrateResult !== EXIT_SUCCESS) { $this->error('Échec de l\'exécution des migrations.'); diff --git a/src/Commands/Migration/Rollback.php b/src/Commands/Migration/Rollback.php index bf3d447..bed922d 100644 --- a/src/Commands/Migration/Rollback.php +++ b/src/Commands/Migration/Rollback.php @@ -35,6 +35,7 @@ class Rollback extends DatabaseCommand */ protected array $options = [ '-g, --group' => 'Groupe de base de données à utiliser', + '-n, --namespace' => 'Namespace spécifique à annuler', '-b, --batch' => 'Numéro de lot cible (ex: 3 pour revenir au lot #3, -2 pour revenir de 2 lots)', '--all' => 'Annuler toutes les migrations', '--show-stats' => 'Afficher les statistiques de l\'opération', @@ -55,8 +56,9 @@ public function handle() $this->eol()->info('Recherche des migrations à annuler...'); - $group = $this->option('group', config('database.connection', 'default')); - $batch = $this->option('all') ? 0 : $this->option('batch', 1); + $group = $this->option('group', config('database.connection', 'default')); + $namespace = $this->option('namespace'); + $batch = $this->option('all') ? 0 : $this->option('batch', 1); if (is_string($batch) && ! preg_match('/^-?\d+$/', $batch)) { $this->error('Le numéro de lot doit être un entier.'); @@ -65,7 +67,7 @@ public function handle() } $batch = (int) $batch; - $runner = $this->runner('ALL', $group); + $runner = $this->runner($namespace ?? 'ALL', $group); $rolledBack = 0; $errorCount = 0;