<?php
require __DIR__.'/common.php';
if(is_file(__DIR__.'/private/batch-before10.json'))throw new RuntimeException('No lease replay');
$before=$source(true);$prior=json_decode(file_get_contents(__DIR__.'/expected/'.$lane.'/batch-after10.json'),true);$a=$before;unset($a['sentinel'],$prior['sentinel']);if($a!==$prior)throw new RuntimeException('Original8/actor/config/identity drift');
$logBefore=$logs();$priorLog=json_decode(file_get_contents(__DIR__.'/expected/'.$lane.'/final10.json'),true)['logs'];if(count($logBefore)!==148||$logBefore!==$priorLog)throw new RuntimeException('Original148 log drift');
$metadata=[];$objects=[];foreach(['staff','dishes','dish','foods_composition','date_menu','menu_recommend','menu_recommend_set','member_weight_status','rpe','rpe_info','sport','identity_type','config','user','initial_menu_log']as $t){$table='ydy_'.$t;
$metadata[$t]=$lane==='B'?$q('SELECT COLUMN_NAME,COLUMN_TYPE,IS_NULLABLE,COLUMN_DEFAULT,EXTRA FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME=? ORDER BY ORDINAL_POSITION',[$table]):$q('SELECT COLUMN_NAME,DATA_TYPE,DATA_LENGTH,DATA_PRECISION,DATA_SCALE,NULLABLE,DATA_DEFAULT FROM USER_TAB_COLUMNS WHERE TABLE_NAME=? ORDER BY COLUMN_ID',[strtoupper($table)]);
if(!$metadata[$t])throw new RuntimeException('Missing table '.$t);
}
$table='ydy_initial_menu_log';$objects['constraints']=$lane==='B'?$q('SELECT CONSTRAINT_NAME,CONSTRAINT_TYPE FROM information_schema.TABLE_CONSTRAINTS WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME=? ORDER BY CONSTRAINT_NAME',[$table]):$q('SELECT CONSTRAINT_NAME,CONSTRAINT_TYPE,STATUS,SEARCH_CONDITION FROM USER_CONSTRAINTS WHERE TABLE_NAME=? ORDER BY CONSTRAINT_NAME',[strtoupper($table)]);
$objects['triggers']=$lane==='B'?$q('SELECT TRIGGER_NAME,ACTION_TIMING,EVENT_MANIPULATION,ACTION_STATEMENT FROM information_schema.TRIGGERS WHERE EVENT_OBJECT_SCHEMA=DATABASE() AND EVENT_OBJECT_TABLE=? ORDER BY TRIGGER_NAME',[$table]):$q('SELECT * FROM USER_TRIGGERS WHERE TABLE_NAME=? ORDER BY TRIGGER_NAME',[strtoupper($table)]);
$oldMeta=json_decode(file_get_contents(__DIR__.'/expected/'.$lane.'/old-lease10.json'),true);if($metadata['initial_menu_log']!==$oldMeta['metadata']['initial_menu_log']||$objects['constraints']!==$oldMeta['objects']['constraints']||$objects['triggers']!==[])throw new RuntimeException('Log metadata/default/FK/trigger drift');
require __DIR__.'/app-init.php';$dictionary=[];foreach(['recommend_val','other_recommend','sport_flag','dietary','dietary_fiber']as $k)$dictionary[$k]=\think\Config::get($k);
$save('dictionary.json',$dictionary);$save('original100.json',$before);$save('logs-before10.json',$logBefore);$save('lease-oracle.json',$GLOBALS['NR_ORACLE']);$save('lease10.json',['lane'=>$lane,'own_rows'=>8,'logs'=>148,'metadata'=>$metadata,'objects'=>$objects,'HTTP'=>0,'DML'=>0,'DDL'=>0]);echo json_encode(['lane'=>$lane,'own_rows'=>8,'logs'=>148,'tables'=>count($metadata),'HTTP'=>0,'DML'=>0,'DDL'=>0]),"\n";
