option('force')) { if (!$this->confirm('This will delete ALL mutations data. Are you sure?')) { $this->info('Operation cancelled.'); return 0; } } try { DB::beginTransaction(); // Delete mutations data in proper order (foreign key constraints) $this->info('Cleaning mutations data...'); // 1. Delete stock logs related to mutations if (Schema::hasTable('stock_logs')) { $deleted = DB::table('stock_logs') ->where('source_type', 'App\\Models\\Mutation') ->delete(); $this->info("Deleted {$deleted} stock logs related to mutations"); } // 2. Delete mutation details if (Schema::hasTable('mutation_details')) { $deleted = DB::table('mutation_details')->delete(); $this->info("Deleted {$deleted} mutation details"); } // 3. Delete mutations if (Schema::hasTable('mutations')) { $deleted = DB::table('mutations')->delete(); $this->info("Deleted {$deleted} mutations"); } // 4. Reset auto increment if (Schema::hasTable('mutations')) { DB::statement('ALTER TABLE mutations AUTO_INCREMENT = 1'); $this->info('Reset mutations auto increment'); } if (Schema::hasTable('mutation_details')) { DB::statement('ALTER TABLE mutation_details AUTO_INCREMENT = 1'); $this->info('Reset mutation_details auto increment'); } DB::commit(); $this->info('✅ Mutations data cleaned successfully!'); $this->info('You can now rollback and re-run migrations.'); return 0; } catch (\Exception $e) { DB::rollback(); $this->error('❌ Error cleaning mutations data: ' . $e->getMessage()); return 1; } } }