Files
Investidor-V2/outputs/investmoz-parques-L1-QA-20261016/compare-restored.php
T
nala cef6e201c7
tests / ci (push) Canceled after 0s
versao nrgocios 2
2026-10-16 20:11:05 +02:00

9 lines
1.7 KiB
PHP

<?php
require __DIR__.'/boot-QA.php';
$original=new PDO('pgsql:host=127.0.0.1;port=55441;dbname=parks_l1_20261016_test','postgres','');$restored=new PDO('pgsql:host=127.0.0.1;port=55441;dbname=parks_l1_restore_20261016_final_test','postgres','');
foreach([$original,$restored]as$p){if((int)$p->query('SELECT inet_server_port()')->fetchColumn()!==55441){throw new RuntimeException('Isolated QA only');}}
$tables=$original->query("SELECT tablename FROM pg_tables WHERE schemaname='public' ORDER BY tablename")->fetchAll(PDO::FETCH_COLUMN);$other=$restored->query("SELECT tablename FROM pg_tables WHERE schemaname='public' ORDER BY tablename")->fetchAll(PDO::FETCH_COLUMN);if($tables!==$other)throw new RuntimeException('Tables mismatch');$hashes=[];
foreach($tables as$name){$sql='SELECT md5(COALESCE(string_agg(md5(row_to_json(t)::text),\'\' ORDER BY row_to_json(t)::text),\'\')) FROM "'.str_replace('"','""',$name).'" t';$a=$original->query($sql)->fetchColumn();$b=$restored->query($sql)->fetchColumn();if($a!==$b)throw new RuntimeException('Restore mismatch '.$name);$hashes[$name]=$a;}
$sql="SELECT sequencename,start_value,min_value,max_value,increment_by,cycle,last_value FROM pg_sequences WHERE schemaname='public' ORDER BY sequencename";$a=$original->query($sql)->fetchAll(PDO::FETCH_ASSOC);$b=$restored->query($sql)->fetchAll(PDO::FETCH_ASSOC);if($a!==$b)throw new RuntimeException('Sequences mismatch');
$result=['tables_equal'=>count($tables),'sequences_equal'=>count($a),'all_table_hashes'=>$hashes,'source'=>'parks_l1_20261016_test:55441','restore'=>'parks_l1_restore_20261016_final_test:55441'];file_put_contents(__DIR__.'/RESTAURO-COMPARACAO-QA.json',json_encode($result,JSON_PRETTY_PRINT));echo json_encode(['tables_equal'=>count($tables),'sequences_equal'=>count($a)]);