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' => filter_var($settings['SGC_GEOGRAPHY_ENABLED'] ?? false, FILTER_VALIDATE_BOOLEAN), 'classified_suppliers' => $db->table('suppliers')->whereNotNull('geography_reference')->count(), 'classified_companies' => $db->table('tenants')->whereNotNull('geography_reference')->count()]; }); if (! $result['migration_applied'] || ! $result['supplier_column_installed'] || ! $result['company_column_installed'] || $result['mfa_accounts_enrolled'] || ! $result['geography_flag'] || $result['classified_suppliers'] || $result['classified_companies']) { throw new LogicException('Pilot differs from the authorized installed and unclassified geography scope.'); } file_put_contents($root.'/docs/proofs/administrative-geography-installation-pilot.json', json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES).PHP_EOL); echo 'Geography pilot inspected read-only: columns empty and selection enabled; no business commands.'.PHP_EOL;