23 lines
2.2 KiB
PHP
23 lines
2.2 KiB
PHP
<?php
|
|
ini_set('zend.exception_ignore_args','1');
|
|
set_exception_handler(function(Throwable $e){fwrite(STDERR,'Read-only QA inspection stopped: '.$e::class.' line '.$e->getLine().PHP_EOL);exit(1);});
|
|
$name='negocios_nome_before_20261016_071036_test';
|
|
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 {
|
|
$id=$db->query('SELECT current_database() AS database,inet_server_port() AS port')->fetch(PDO::FETCH_ASSOC);
|
|
if($id['database']!==$name||(int)$id['port']!==55441)throw new RuntimeException('Wrong identity');
|
|
$result=['identity'=>$id,'read_only'=>true,'active_connections'=>0];
|
|
$result['related_tables']=$db->query("SELECT table_schema,table_name FROM information_schema.tables WHERE table_type='BASE TABLE' AND table_schema NOT IN ('pg_catalog','information_schema') AND (table_name ~* '(economic|activid|cae|sector|value_chain)') ORDER BY table_schema,table_name")->fetchAll(PDO::FETCH_ASSOC);
|
|
foreach($result['related_tables'] as &$t){
|
|
$qualified='"'.str_replace('"','""',$t['table_schema']).'"."'.str_replace('"','""',$t['table_name']).'"';
|
|
$t['count']=(int)$db->query('SELECT count(*) FROM '.$qualified)->fetchColumn();
|
|
}unset($t);
|
|
$result['cluster_portfolio_visibility']=$db->query("SELECT c.id,c.code,c.data_classification,c.status,(SELECT count(*) FROM investment_dossiers d WHERE d.cluster_id=c.id AND d.publication_status='published' AND d.deleted_at IS NULL) AS published_dossiers FROM economic_clusters c WHERE c.deleted_at IS NULL ORDER BY c.code")->fetchAll(PDO::FETCH_ASSOC);
|
|
$result['document_schema']=$db->query("SELECT column_name,data_type FROM information_schema.columns WHERE table_schema='public' AND table_name='documents' ORDER BY ordinal_position")->fetchAll(PDO::FETCH_ASSOC);
|
|
$file=__DIR__.'/DEPENDENCIAS-QA-READONLY.json';if(is_file($file))throw new RuntimeException('Preserve proof');
|
|
file_put_contents($file,json_encode($result,JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE|JSON_THROW_ON_ERROR).PHP_EOL);
|
|
echo json_encode($result,JSON_UNESCAPED_UNICODE).PHP_EOL;
|
|
}finally{$db->exec('ROLLBACK');}
|