Files
compras/scripts/geography-pilot-check.php
T
nala 63d20b10fc
tests / ci (push) Canceled after 0s
commit de armazens
2026-11-04 09:40:26 +02:00

42 lines
3.0 KiB
PHP

<?php
use Illuminate\Contracts\Console\Kernel;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
require dirname(__DIR__).'/vendor/autoload.php';
$root = dirname(__DIR__);
$settings = json_decode(file_get_contents('C:/laragon/data/sgf-tempo/secrets/payables-demo-compras.json'), true, 32, JSON_THROW_ON_ERROR);
if (($settings['APP_ENV'] ?? '') !== 'payable-testing' || ($settings['DB_HOST'] ?? '') !== '127.0.0.1' || realpath($settings['HOST_ROOT'] ?? '') !== realpath($root)
|| ! preg_match('/^compras_receipts_test_([a-f0-9]{12})$/D', $settings['DB_DATABASE'] ?? '', $matches) || $settings['DB_USERNAME'] !== 'payable_qa_'.$matches[1]) {
throw new LogicException('Wrong pilot destination.');
}
$app = require $root.'/bootstrap/app.php';
$app->make(Kernel::class)->bootstrap();
$base = DB::connection('pgsql')->getConfig();
unset($base['name']);
config(['database.connections.geography_pilot_read' => [...$base, 'url' => null, 'host' => $settings['DB_HOST'], 'port' => $settings['DB_PORT'],
'database' => $settings['DB_DATABASE'], 'username' => $settings['DB_USERNAME'], 'password' => $settings['DB_PASSWORD']]]);
$db = DB::connection('geography_pilot_read');
$result = $db->transaction(function () use ($db, $settings) {
$db->statement('SET TRANSACTION ISOLATION LEVEL REPEATABLE READ READ ONLY');
$identity = $db->selectOne('select current_database() as db, current_user as role');
if ($identity->db !== $settings['DB_DATABASE'] || $identity->role !== $settings['DB_USERNAME']) {
throw new LogicException('Identity mismatch.');
}
$schema = Schema::connection('geography_pilot_read');
return ['checked_at' => gmdate('c'), 'environment' => 'http://127.0.0.1:8005', 'result' => 'passed',
'supplier_column_installed' => $schema->hasColumn('suppliers', 'geography_reference'),
'company_column_installed' => $schema->hasColumn('tenants', 'geography_reference'),
'migration_applied' => $db->table('migrations')->where('migration', '2026_11_03_000004_add_administrative_geography_references')->exists(),
'mfa_accounts_enrolled' => $db->table('users')->where(fn ($q) => $q->whereNotNull('two_factor_secret')->orWhereNotNull('two_factor_recovery_codes')->orWhereNotNull('two_factor_confirmed_at'))->count(),
'access_version' => (int) $db->table('organization_access')->where('tenant_id', 1)->value('version'),
'business_commands' => false, 'geography_flag' => config('geography.enabled')];
});
if ($result['migration_applied'] || $result['supplier_column_installed'] || $result['company_column_installed'] || $result['mfa_accounts_enrolled'] || $result['geography_flag']) {
throw new LogicException('Pilot differs from the expected uninstalled geography scope.');
}
file_put_contents($root.'/docs/proofs/administrative-geography-pilot.json', json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES).PHP_EOL);
echo 'Geography pilot inspected read-only: columns absent; no business commands.'.PHP_EOL;