getLine().PHP_EOL);exit(1);}); $root=dirname(__DIR__,2);require $root.'/vendor/autoload.php';$app=require $root.'/bootstrap/app.php'; (new Illuminate\Foundation\Bootstrap\LoadEnvironmentVariables)->bootstrap($app);(new Illuminate\Foundation\Bootstrap\LoadConfiguration)->bootstrap($app); $c=config('database.connections.'.config('database.default')); if($c['driver']!=='pgsql'||$c['database']!=='investemoz'||(int)$c['port']!==5432||!in_array($c['host'],['127.0.0.1','localhost'])||!empty($c['url']))throw new RuntimeException('Active identity guard'); $db=new PDO('pgsql:host='.$c['host'].';port=5432;dbname=investemoz',$c['username'],$c['password'],[PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION]);$db->exec('BEGIN READ ONLY'); try{ $events=$db->query("SELECT id,action,actor_user_id,occurred_at,correlation_id,after_data->'result' AS result FROM audit_events WHERE source_system='economic-reference-lot-01' ORDER BY occurred_at,id")->fetchAll(PDO::FETCH_ASSOC); foreach($events as&$event)$event['result']=json_decode($event['result'],true,512,JSON_THROW_ON_ERROR);unset($event); $ledger=$db->query("SELECT migration,batch FROM migrations WHERE migration='2026_10_16_120000_extend_economic_reference_hierarchy'")->fetchAll(PDO::FETCH_ASSOC); $result=['at'=>gmdate('c'),'read_only'=>true,'target'=>['database'=>'investemoz','port'=>5432],'ledger'=>$ledger,'events'=>$events]; $path=__DIR__.'/OPERACOES-ATIVO.json';file_put_contents($path,json_encode($result,JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE|JSON_THROW_ON_ERROR).PHP_EOL); echo json_encode(['ledger'=>$ledger,'events'=>array_map(fn($e)=>['id'=>$e['id'],'action'=>$e['action'],'actor_user_id'=>$e['actor_user_id'],'changed'=>count($e['result']['changed']??[]),'reused'=>count($e['result']['reused']??[])],$events)]).PHP_EOL; }finally{$db->exec('ROLLBACK');}