<?php
declare(strict_types=1);require __DIR__.'/connect.php';require __DIR__.'/schema.php';$check($dm&&$lane==='C','Only approved C readonly metadata');$fresh=$schema('YOSHOP_EQUIPMENT');$persist('equipment-schema-fresh.json',$fresh);$original=json_decode(file_get_contents($runtime.'/equipment-schema-original.json'),true);$diff=[];$walk=static function($a,$b,$path)use(&$walk,&$diff){if(gettype($a)!==gettype($b)){$diff[]=['path'=>$path,'kind'=>'type','fresh_type'=>gettype($a),'persisted_type'=>gettype($b),'fresh_json'=>json_encode($a),'persisted_json'=>json_encode($b)];return;}if(is_array($a)){if(array_keys($a)!==array_keys($b)){$diff[]=['path'=>$path,'kind'=>'keys'];return;}foreach($a as $k=>$v)$walk($v,$b[$k],$path.'.'.$k);}elseif($a!==$b)$diff[]=['path'=>$path,'kind'=>'value','fresh'=>$a,'persisted'=>$b];};$walk($fresh,$original,'schema');$out=['business_DDL_started'=>is_file($runtime.'/ddl-apply.json'),'rows'=>(int)$q('SELECT COUNT(*) n FROM yoshop_equipment')[0]['n'],'columns'=>array_column($fresh['columns'],'column_name'),'diff'=>$diff];file_put_contents(__DIR__.'/ddl-state-C.json',json_encode($out,JSON_PRETTY_PRINT));echo json_encode($out),"\n";
