make(\Illuminate\Contracts\Console\Kernel::class)->bootstrap(); use Illuminate\Support\Facades\DB; if(!\App\Modules\Identity\Services\LocalDatabaseGuard::allows())throw new RuntimeException('Own application connection required.'); if(!DB::table('companies')->where(['id'=>1,'tenant_id'=>1,'name'=>'Tempo Lda'])->exists()||!DB::table('units')->where(['id'=>1,'tenant_id'=>1,'company_id'=>1,'name'=>'SEGI'])->exists())throw new RuntimeException('Scope differs.'); $grants=[];foreach([1=>['view','request','apply'],2=>['view','review']] as $actor=>$rights){if(!DB::table('company_memberships')->where(['user_id'=>$actor,'tenant_id'=>1,'company_id'=>1])->exists())throw new RuntimeException('Membership missing.');foreach($rights as $right){$g=['user_id'=>$actor,'tenant_id'=>1,'company_id'=>1,'unit_id'=>1,'permission'=>'workshop_corrections.'.$right];$grants[]=$g+['already_granted'=>DB::table('permission_grants')->where($g)->exists()];}} $prerequisites=[];foreach([1,2] as $actor){foreach(['workshop.view','workshop_billing.view','unit.view'] as $p)$prerequisites[]=['user_id'=>$actor,'permission'=>$p,'present'=>DB::table('permission_grants')->where(['user_id'=>$actor,'tenant_id'=>1,'company_id'=>1,'unit_id'=>1,'permission'=>$p])->exists()];foreach(['company.view','clients.view','services.view'] as $p)$prerequisites[]=['user_id'=>$actor,'permission'=>$p,'present'=>DB::table('permission_grants')->where(['user_id'=>$actor,'tenant_id'=>1,'company_id'=>1,'permission'=>$p])->whereNull('unit_id')->exists()];}foreach(['service_drafts.view','service_drafts.create','billing_drafts.view','billing_drafts.create'] as $p)$prerequisites[]=['user_id'=>1,'permission'=>$p,'present'=>DB::table('permission_grants')->where(['user_id'=>1,'tenant_id'=>1,'company_id'=>1,'unit_id'=>1,'permission'=>$p])->exists()]; try{\App\Modules\Workshop\WorkshopCorrections::guard();throw new RuntimeException('Real corrections allowed.');}catch(\Symfony\Component\HttpKernel\Exception\HttpExceptionInterface $e){if($e->getStatusCode()!==403)throw $e;} echo json_encode(['mode'=>'preview_only','destination'=>'sgf_tempo_dev','migration_130000_applied'=>DB::table('migrations')->where('migration','2026_10_28_130000_create_workshop_billing_corrections')->exists(),'proposed_grants'=>$grants,'existing_prerequisites'=>$prerequisites,'real_corrections_blocked'=>true,'applied'=>false],JSON_PRETTY_PRINT|JSON_THROW_ON_ERROR).PHP_EOL;