Skip to content

Commit a005c48

Browse files
authored
Merge pull request #23 from blitz-php/1.x-devs
feat: rollback des migrations d'un namespace particulier
2 parents c302632 + f361523 commit a005c48

2 files changed

Lines changed: 14 additions & 13 deletions

File tree

‎src/Commands/Migration/Refresh.php‎

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,17 @@ public function handle()
5252

5353
$this->eol()->info('Réinitialisation et réexécution des migrations...');
5454

55-
$group = $this->option('group', config('database.connection', 'default'));
56-
$seed = $this->option('seed') === true;
55+
$seed = $this->option('seed') === true;
56+
$options = [
57+
'--group' => $group = $this->option('group', config('database.connection', 'default')),
58+
'--all' => $this->option('all') === true,
59+
'--force' => $this->option('force') === true,
60+
'--namespace' => $this->option('namespace'),
61+
];
5762

5863
$this->newLine()->comment('Étape 1/2: Annulation de toutes les migrations');
5964

60-
$rollbackResult = $this->call('migrate:rollback', options: [
61-
'--group' => $group,
62-
'--all' => true,
63-
'--force' => true,
64-
]);
65+
$rollbackResult = $this->call('migrate:rollback', options: $options);
6566

6667
if ($rollbackResult !== EXIT_SUCCESS) {
6768
$this->error('Échec de l\'annulation des migrations.');
@@ -71,9 +72,7 @@ public function handle()
7172

7273
$this->newLine()->comment('Étape 2/2: Réexécution des migrations');
7374

74-
$migrateResult = $this->call('migrate', options: [
75-
'--group' => $group,
76-
]);
75+
$migrateResult = $this->call('migrate', options: $options);
7776

7877
if ($migrateResult !== EXIT_SUCCESS) {
7978
$this->error('Échec de l\'exécution des migrations.');

‎src/Commands/Migration/Rollback.php‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class Rollback extends DatabaseCommand
3535
*/
3636
protected array $options = [
3737
'-g, --group' => 'Groupe de base de données à utiliser',
38+
'-n, --namespace' => 'Namespace spécifique à annuler',
3839
'-b, --batch' => 'Numéro de lot cible (ex: 3 pour revenir au lot #3, -2 pour revenir de 2 lots)',
3940
'--all' => 'Annuler toutes les migrations',
4041
'--show-stats' => 'Afficher les statistiques de l\'opération',
@@ -55,8 +56,9 @@ public function handle()
5556

5657
$this->eol()->info('Recherche des migrations à annuler...');
5758

58-
$group = $this->option('group', config('database.connection', 'default'));
59-
$batch = $this->option('all') ? 0 : $this->option('batch', 1);
59+
$group = $this->option('group', config('database.connection', 'default'));
60+
$namespace = $this->option('namespace');
61+
$batch = $this->option('all') ? 0 : $this->option('batch', 1);
6062

6163
if (is_string($batch) && ! preg_match('/^-?\d+$/', $batch)) {
6264
$this->error('Le numéro de lot doit être un entier.');
@@ -65,7 +67,7 @@ public function handle()
6567
}
6668
$batch = (int) $batch;
6769

68-
$runner = $this->runner('ALL', $group);
70+
$runner = $this->runner($namespace ?? 'ALL', $group);
6971

7072
$rolledBack = 0;
7173
$errorCount = 0;

0 commit comments

Comments
 (0)