info('Checking Spatial Planning Constraints...'); $this->newLine(); try { // Get total spatial plannings $totalSpatialPlannings = SpatialPlanning::count(); // Get spatial plannings with retribution proposals $withProposals = SpatialPlanning::whereHas('retributionProposals')->count(); // Get spatial plannings without retribution proposals $withoutProposals = SpatialPlanning::whereDoesntHave('retributionProposals')->count(); // Get total retribution proposals $totalProposals = RetributionProposal::count(); // Get retribution proposals linked to spatial plannings $linkedProposals = RetributionProposal::whereNotNull('spatial_planning_id')->count(); // Get standalone retribution proposals $standaloneProposals = RetributionProposal::whereNull('spatial_planning_id')->count(); // Display statistics $this->table( ['Metric', 'Count'], [ ['Total Spatial Plannings', $totalSpatialPlannings], ['├─ With Retribution Proposals', $withProposals], ['└─ Without Retribution Proposals', $withoutProposals], ['', ''], ['Total Retribution Proposals', $totalProposals], ['├─ Linked to Spatial Planning', $linkedProposals], ['└─ Standalone Proposals', $standaloneProposals], ] ); $this->newLine(); // Show constraint implications if ($withProposals > 0) { $this->warn("⚠️ CONSTRAINT WARNING:"); $this->warn(" {$withProposals} spatial plannings have retribution proposals linked to them."); $this->warn(" These cannot be deleted directly due to foreign key constraints."); $this->newLine(); $this->info("💡 TRUNCATE OPTIONS:"); $this->info(" • Use --truncate to delete ALL data (spatial plannings + linked proposals)"); $this->info(" • Use --safe-truncate to delete only spatial plannings without proposals"); $this->info(" • Manual cleanup: Delete proposals first, then spatial plannings"); } else { $this->info("✅ No foreign key constraints found."); $this->info(" All spatial plannings can be safely truncated."); } $this->newLine(); // Show example commands $this->info("📋 EXAMPLE COMMANDS:"); $this->info(" php artisan spatial:init --truncate # Delete all data (smart method)"); $this->info(" php artisan spatial:init --safe-truncate # Delete safe data only"); $this->info(" php artisan spatial:init --force-truncate # Force truncate (disable FK checks)"); $this->info(" php artisan spatial:init file.csv --truncate # Import with truncate"); return 0; } catch (\Exception $e) { $this->error('Error checking constraints: ' . $e->getMessage()); return 1; } } }