@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Contracts\Console\Kernel;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
require dirname(__DIR__).'/vendor/autoload.php';
|
||||
if (! in_array('--inspect-commercial-schema', $argv, true)) {
|
||||
throw new LogicException('Exige a opção explícita de inspecção, sem instalação.');
|
||||
}
|
||||
$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'] ?? '', $match)
|
||||
|| $settings['DB_USERNAME'] !== 'payable_qa_'.$match[1]) {
|
||||
throw new LogicException('Destino do piloto não coincide com a configuração aprovada.');
|
||||
}
|
||||
$app = require $root.'/bootstrap/app.php';
|
||||
$app->make(Kernel::class)->bootstrap();
|
||||
$base = DB::connection('pgsql')->getConfig();
|
||||
unset($base['name']);
|
||||
config(['database.connections.commercial_preflight' => [...$base, 'url' => null, 'host' => $settings['DB_HOST'],
|
||||
'database' => $settings['DB_DATABASE'], 'username' => $settings['DB_USERNAME'], 'password' => $settings['DB_PASSWORD']]]);
|
||||
$db = DB::connection('commercial_preflight');
|
||||
$db->beginTransaction();
|
||||
try {
|
||||
$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('Identidade do destino não confirmada.');
|
||||
}
|
||||
$schema = $db->getSchemaBuilder();
|
||||
$targets = ['2026_11_21_000001_create_quotation_exchange_rates.php', '2026_11_21_000002_add_supplier_bank_account_keys.php'];
|
||||
$hashes = [];
|
||||
foreach ($targets as $name) {
|
||||
$hashes[$name] = hash_file('sha256', $root.'/database/migrations/'.$name);
|
||||
}
|
||||
$report = ['inspection_only' => true, 'target' => 'SGC local 8005', 'consistent_read_only' => true,
|
||||
'public_tables' => (int) $db->selectOne("select count(*) as n from pg_tables where schemaname='public'")->n,
|
||||
'fx_table_present' => $schema->hasTable('quotation_exchange_rates'), 'quotation_fx_column_present' => $schema->hasColumn('quotations', 'exchange_basis'),
|
||||
'bank_account_key_present' => $schema->hasColumn('supplier_bank_details', 'account_key'),
|
||||
'migration_hashes' => $hashes, 'pilot_manifest_sha256' => hash_file('sha256', $root.'/public/build/manifest.json')];
|
||||
$db->commit();
|
||||
echo json_encode($report, JSON_THROW_ON_ERROR).PHP_EOL;
|
||||
} finally {
|
||||
if ($db->transactionLevel() !== 0) {
|
||||
$db->rollBack();
|
||||
}
|
||||
DB::purge('commercial_preflight');
|
||||
}
|
||||
Reference in New Issue
Block a user