@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
use App\Services\StandaloneComponentSchema;
|
||||
use Illuminate\Database\PostgresConnection;
|
||||
|
||||
// Metadata only. No application bootstrap, migrations, business rows or configuration writes.
|
||||
if (! in_array('--inspect-pilot-schema', $argv, true)) {
|
||||
throw new LogicException('Explicit read-only pilot schema inspection required.');
|
||||
}
|
||||
$root = dirname(__DIR__);
|
||||
require $root.'/vendor/autoload.php';
|
||||
$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'] ?? '', $match)
|
||||
|| ($settings['DB_USERNAME'] ?? '') !== 'payable_qa_'.$match[1]
|
||||
|| ! is_scalar($settings['DB_PORT'] ?? null) || ! ctype_digit((string) $settings['DB_PORT'])
|
||||
|| (int) $settings['DB_PORT'] < 1 || (int) $settings['DB_PORT'] > 65535) {
|
||||
throw new LogicException('Pilot metadata target identity mismatch.');
|
||||
}
|
||||
$db = new PDO('pgsql:host=127.0.0.1;port='.(int) $settings['DB_PORT'].';dbname='.$settings['DB_DATABASE'],
|
||||
$settings['DB_USERNAME'], $settings['DB_PASSWORD'], [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);
|
||||
$db->beginTransaction();
|
||||
try {
|
||||
$db->exec('SET TRANSACTION ISOLATION LEVEL REPEATABLE READ READ ONLY');
|
||||
$identity = $db->query('SELECT current_database() AS database_name, current_user AS role_name')->fetch(PDO::FETCH_ASSOC);
|
||||
if ($identity['database_name'] !== $settings['DB_DATABASE'] || $identity['role_name'] !== $settings['DB_USERNAME']) {
|
||||
throw new LogicException('Pilot metadata connection identity mismatch.');
|
||||
}
|
||||
$tables = [];
|
||||
foreach ($db->query("SELECT table_name,column_name,data_type,is_nullable FROM information_schema.columns WHERE table_schema='public' ORDER BY table_name,ordinal_position")->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
||||
$tables[$row['table_name']][] = ['name' => $row['column_name'], 'type' => $row['data_type'], 'nullable' => $row['is_nullable'] === 'YES'];
|
||||
}
|
||||
$migrations = $db->query('SELECT migration FROM migrations ORDER BY migration')->fetchAll(PDO::FETCH_COLUMN);
|
||||
$connection = new PostgresConnection($db, $settings['DB_DATABASE'], '', ['driver' => 'pgsql', 'search_path' => 'public']);
|
||||
$profiles = [];
|
||||
foreach (array_keys(StandaloneComponentSchema::GROUPS) as $group) {
|
||||
$profiles[$group] = StandaloneComponentSchema::inspect($connection, $group);
|
||||
}
|
||||
$report = ['checked_at' => gmdate('c'), 'environment' => 'http://127.0.0.1:8005', 'inspection_only' => true,
|
||||
'consistent_read_only' => true, 'business_values_read' => false, 'configuration_or_permission_changes' => false,
|
||||
'tables' => $tables, 'applied_migrations' => $migrations, 'component_profiles' => $profiles];
|
||||
$db->commit();
|
||||
$output = $root.'/docs/proofs/standalone-pilot-schema-inventory.json';
|
||||
file_put_contents($output, json_encode($report, JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR).PHP_EOL);
|
||||
echo json_encode(['inspection_only' => true, 'table_count' => count($tables), 'migrations' => count($migrations),
|
||||
'business_values_read' => false, 'component_profiles' => $profiles,
|
||||
'proof' => 'docs/proofs/standalone-pilot-schema-inventory.json'], JSON_THROW_ON_ERROR).PHP_EOL;
|
||||
} finally {
|
||||
if ($db->inTransaction()) {
|
||||
$db->rollBack();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user