@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
ini_set('zend.exception_ignore_args','1');
|
||||
set_exception_handler(function(Throwable $e){fwrite(STDERR,'Read-only preservation stopped: '.$e::class.' line '.$e->getLine().PHP_EOL);exit(1);});
|
||||
$before=json_decode(file_get_contents(__DIR__.'/ESTADO-QA-READONLY.json'),true,512,JSON_THROW_ON_ERROR);
|
||||
$proof=['read_only'=>true,'active_database_connections'=>0,'targets'=>[]];
|
||||
foreach($before['targets'] as $label=>$state){
|
||||
$name=$state['identity']['database'];if(!str_ends_with($name,'_test'))throw new RuntimeException('QA required');
|
||||
$db=new PDO('pgsql:host=127.0.0.1;port=55441;dbname='.$name,'postgres','',[PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION]);$db->exec('BEGIN ISOLATION LEVEL REPEATABLE READ READ ONLY');
|
||||
try {
|
||||
$identity=$db->query('SELECT current_database() AS database,inet_server_port() AS port')->fetch(PDO::FETCH_ASSOC);
|
||||
if($identity['database']!==$name||(int)$identity['port']!==55441)throw new RuntimeException('Wrong QA');
|
||||
$checks=[];
|
||||
foreach($state['tables'] as $table=>$prior){
|
||||
$rows=$db->query('SELECT row_to_json(t)::text FROM public."'.$table.'" t ORDER BY row_to_json(t)::text')->fetchAll(PDO::FETCH_COLUMN);
|
||||
$actual=hash('sha256',implode("\n",$rows));if($actual!==$prior['sha256'])throw new RuntimeException('Reference master changed');
|
||||
$checks[$table]=['count'=>count($rows),'sha256'=>$actual,'unchanged'=>true];
|
||||
}
|
||||
$proof['targets'][$label]=['identity'=>$identity,'reference_tables'=>$checks];
|
||||
}finally{$db->exec('ROLLBACK');}
|
||||
}
|
||||
file_put_contents(__DIR__.'/PRESERVACAO-REFERENCIAS-QA.json',json_encode($proof,JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE|JSON_THROW_ON_ERROR).PHP_EOL);
|
||||
echo json_encode(['QA_reference_tables_unchanged'=>true,'targets'=>count($proof['targets']),'active_connections'=>0]).PHP_EOL;
|
||||
Reference in New Issue
Block a user