Files
Investidor-V2/outputs/investmoz-editorial-ativacao-20261018/verify-data.php
T
nala cf003c8623
tests / ci (push) Canceled after 0s
versao nrgocios 4
2026-10-18 15:57:06 +02:00

14 lines
3.2 KiB
PHP

<?php
ini_set('zend.exception_ignore_args','1');set_exception_handler(function(Throwable $e){fwrite(STDERR,'Data verification stopped: '.$e::class.' line '.$e->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['database']!=='investemoz'||(int)$c['port']!==5432||!in_array($c['host'],['127.0.0.1','localhost'])||!empty($c['url']))throw new RuntimeException('Destination identity');
$b=json_decode(file_get_contents(__DIR__.'/FRESH-BACKUP.json'),true,512,JSON_THROW_ON_ERROR);$cloneName=$b['restore_target']['database'];if(!preg_match('/^editorial_before_\d{8}_\d{6}_test$/D',$cloneName)||(int)$b['restore_target']['port']!==55441)throw new RuntimeException('Clone guard');
$db=new PDO('pgsql:host='.$c['host'].';port=5432;dbname=investemoz',$c['username'],$c['password'],[PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION]);$clone=new PDO('pgsql:host=127.0.0.1;port=55441;dbname='.$cloneName,'postgres','',[PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION]);
foreach([$db,$clone]as$conn){$conn->exec('BEGIN ISOLATION LEVEL REPEATABLE READ READ ONLY');$conn->exec("SET LOCAL TIME ZONE 'UTC'");}
try{
$tables=[];foreach(['documents','portal_resources','portal_resource_links','portal_resource_revisions','audit_events','opportunities','desk_cases','investor_journeys','investment_submissions','interest_requests','investor_navigation_preferences','economic_activities','investment_zones','migrations']as$table){$sql='SELECT row_to_json(t)::text FROM "'.$table.'" t ORDER BY row_to_json(t)::text';$a=$db->query($sql)->fetchAll(PDO::FETCH_COLUMN);$z=$clone->query($sql)->fetchAll(PDO::FETCH_COLUMN);if($a!==$z)throw new RuntimeException('Unexpected table change: '.$table);$tables[$table]=['rows'=>count($a),'sha256'=>hash('sha256',implode("\n",$a))];}
$ledger=[];foreach(['2026_10_16_140000_add_investment_zone_operational_details','2026_10_16_150000_create_investor_navigation_preferences']as$name){$q=$db->prepare('SELECT count(*) FROM migrations WHERE migration=?');$q->execute([$name]);$ledger[$name]=(int)$q->fetchColumn();if($ledger[$name]!==1)throw new RuntimeException('Existing ledger');}
$sector=$db->query('SELECT id,sector_id,management_version FROM opportunities WHERE id IN (2,6) ORDER BY id')->fetchAll(PDO::FETCH_ASSOC);if((int)$sector[0]['sector_id']!==8||(int)$sector[1]['sector_id']!==6)throw new RuntimeException('Existing sector decisions');
$proof=['at'=>gmdate('c'),'candidate'=>'editorial-QA-f95dbc5e373f','read_only'=>true,'target'=>['database'=>'investemoz','port'=>5432],'compared_with_fresh_restored_snapshot'=>true,'preserved_tables'=>$tables,'ledger'=>$ledger,'preserved_sector_decisions'=>$sector,'business_writes'=>0,'migrations_executed'=>[],'accepted_QA_repeated'=>false];file_put_contents(__DIR__.'/PRESERVACAO-POS-CODIGO.json',json_encode($proof,JSON_PRETTY_PRINT|JSON_THROW_ON_ERROR));echo json_encode(['tables_preserved'=>count($tables),'business_writes'=>0,'ledger'=>$ledger]).PHP_EOL;
}finally{$db->exec('ROLLBACK');$clone->exec('ROLLBACK');}