14 lines
3.4 KiB
PHP
14 lines
3.4 KiB
PHP
<?php
|
|
require __DIR__.'/boot-QA.php';
|
|
use Illuminate\Support\Facades\DB;
|
|
$baseline=json_decode(file_get_contents(__DIR__.'/BASELINE-QA.json'),true);$tables=DB::select("SELECT tablename FROM pg_tables WHERE schemaname='public' ORDER BY tablename");$hashes=[];foreach($tables as$t){$n=$t->tablename;$hashes[$n]=DB::selectOne('SELECT md5(COALESCE(string_agg(md5(row_to_json(t)::text),\'\' ORDER BY row_to_json(t)::text),\'\')) AS hash FROM "'.$n.'" t')->hash;}
|
|
$changed=[];foreach($baseline['tables']as$n=>$h)if($hashes[$n]!==$h)$changed[]=$n;
|
|
$permitted=['audit_events','desk_cases','desk_events','desk_requests','desk_revisions','desk_notifications','migrations','simulation_form_drafts'];
|
|
if(array_diff($changed,$permitted))throw new RuntimeException('Unplanned QA table changes: '.implode(',',array_diff($changed,$permitted)));
|
|
foreach(['existing_businesses','opportunities','investment_zones','sectors','geo_locations','documents','memberships','portal_profile_grants','portal_profile_roles']as$n)if(isset($baseline['tables'][$n])&&$baseline['tables'][$n]!==$hashes[$n])throw new RuntimeException('Protected master changed: '.$n);
|
|
$original=config('database.connections.pgsql');$original['database']='navigation_20261016_test';config(['database.connections.navigation_baseline'=>$original]);$old=DB::connection('navigation_baseline');if($old->selectOne('SELECT current_database() AS name,inet_server_port() AS port')->name!=='navigation_20261016_test'||(int)$old->selectOne('SELECT inet_server_port() AS port')->port!==55441)throw new RuntimeException('QA baseline guard');
|
|
$id=json_decode(file_get_contents(__DIR__.'/FUNCTIONAL-STATE.json'),true)['case_id'];$preserved=[];foreach($old->table('desk_cases')->get()as$row){if($row->id===$id)continue;$now=DB::table('desk_cases')->where('id',$row->id)->first();if(json_encode($row)!==json_encode($now))throw new RuntimeException('Other existing dossier changed');$preserved[]=$row->id;}
|
|
$published=DB::table('existing_businesses')->where('id','172aa874-98fc-4bf6-b78f-d2e9a386d345')->first();$priorPublished=$old->table('existing_businesses')->where('id',$published->id)->first();if(json_encode($published)!==json_encode($priorPublished)||$published->status!=='published')throw new RuntimeException('Published reference changed');
|
|
$restored=json_decode(file_get_contents(__DIR__.'/RESTORE-QA.json'),true);$originalRestored=$restored['table_hashes'];$matching=[];foreach($hashes as$n=>$h)if(($originalRestored[$n]??null)===$h)$matching[]=$n;
|
|
$r=['target'=>$target,'table_count'=>count($hashes),'changed_existing_tables'=>$changed,'unchanged_original_tables'=>count($baseline['tables'])-count($changed),'new_tables'=>array_values(array_diff(array_keys($hashes),array_keys($baseline['tables']))),'table_hashes'=>$hashes,'other_existing_dossiers_preserved'=>count($preserved),'published_reference'=>['id'=>$published->id,'version'=>(int)$published->version_no,'status'=>'published','baseline_version_preserved'=>true],'master_documents_permissions_history_preserved'=>true,'nominal_migration_count'=>DB::table('migrations')->where('migration',App\Services\InvestorContext::MIGRATION)->count(),'sequences'=>DB::selectOne("SELECT count(*) AS count FROM information_schema.sequences WHERE sequence_schema='public'")->count,'restored_snapshot_tables_matching_before_compatibility_test'=>count($matching)];file_put_contents(__DIR__.'/FINAL-QA.json',json_encode($r,JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE));echo json_encode(array_diff_key($r,['table_hashes'=>true]));
|