28 lines
1.4 KiB
PHP
28 lines
1.4 KiB
PHP
<?php
|
|
|
|
// Explicitly called by disposable/new QA setup only, never registered in host migrations.
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Schema;
|
|
use Tempo\Finance\Payables\PayablesSchema;
|
|
|
|
$db = DB::connection();
|
|
if ($db->getDriverName() !== 'pgsql' || ! preg_match('/^(compras_receipts_test_|payable_sgf_)[a-f0-9]{12}$/D', $db->getDatabaseName()) || $db->selectOne('select current_database() as d')->d !== $db->getDatabaseName()) {
|
|
throw new LogicException('Payables schema refused outside isolated QA.');
|
|
}
|
|
// Compras migrations now install the same shared schema before QA fixtures.
|
|
if (Schema::hasTable('pa_sources')) {
|
|
foreach (['pa_access', 'pa_sources', 'pa_proposals', 'pa_obligations', 'pa_commands', 'pa_events', 'pa_outbox'] as $table) {
|
|
if (! Schema::hasTable($table)) {
|
|
throw new LogicException('Incomplete payables schema; no automatic repair.');
|
|
}
|
|
}
|
|
$triggers = DB::selectOne("select count(*) as n from pg_trigger where tgname='pa_history_immutable' and tgrelid in ('pa_sources'::regclass,'pa_proposals'::regclass,'pa_obligations'::regclass,'pa_commands'::regclass,'pa_events'::regclass,'pa_outbox'::regclass)");
|
|
if ((int) $triggers->n !== 6) {
|
|
throw new LogicException('Payables append-only protection missing.');
|
|
}
|
|
|
|
return;
|
|
}
|
|
require_once __DIR__.'/src/PayablesSchema.php';
|
|
PayablesSchema::install();
|