commit compras3 2911
tests / ci (push) Canceled after 0s

This commit is contained in:
2026-11-29 16:03:11 +02:00
parent 7da8d6c87a
commit 30bfb1a773
72 changed files with 10998 additions and 98 deletions
@@ -0,0 +1,71 @@
<?php
namespace App\Services;
use Illuminate\Database\Connection;
use LogicException;
/** Structural identity only; never reads business rows or repairs an existing component. */
final class StandaloneComponentSchema
{
public const GROUPS = [
'budget-distributions-v1' => ['budget_distributions', 'budget_distribution_events', 'budget_distribution_entries', 'budget_distribution_consumptions'],
'supplier-settlements-v1' => ['ps_payments', 'ps_payment_decisions', 'ps_proposals', 'ps_allocation_aliases', 'ps_allocation_decisions', 'ps_allocations', 'ps_commands', 'ps_events', 'ps_outbox'],
'supplier-payables-v1' => ['pa_access', 'pa_sources', 'pa_proposals', 'pa_obligations', 'pa_commands', 'pa_events', 'pa_outbox'],
];
// Measured from the canonical definitions in an owned synthetic PostgreSQL17 composition.
// Pilot metadata was compared separately; it was not used as the authority for these identities.
public const SUPPORTED = [
'budget-distributions-v1' => '4239f48f64e2beb0cf34d3dc8730aca3a0c54aef9cb0dff2c69d03c0e8b1c2e1',
'supplier-settlements-v1' => '11b1522f8b62c32944cf53a6180046d28d51c5c295e6e390633ac809d72bf05a',
'supplier-payables-v1' => 'cda146acf4e674c72b7676fc02cf9b8c5e89208d1dd099193950d785c4dd8452',
];
/** @return list<string> */
public static function reusable(Connection $db): array
{
$groups = [];
foreach (self::SUPPORTED as $group => $expected) {
$actual = self::inspect($db, $group);
if ($actual['present'] === []) {
continue;
}
if ($actual['sha256'] === null || ! hash_equals($expected, $actual['sha256'])) {
throw new LogicException('COMPRAS_RUNTIME_COMPONENT_SCHEMA_UNSUPPORTED:'.$group);
}
$groups[] = $group;
}
return $groups;
}
/** @return array{present:array<int,string>,sha256:?string} */
public static function inspect(Connection $db, string $group): array
{
if ($db->getDriverName() !== 'pgsql' || ! isset(self::GROUPS[$group])) {
throw new LogicException('COMPRAS_RUNTIME_COMPONENT_PROFILE');
}
$tables = self::GROUPS[$group];
$present = array_values(array_filter($tables, fn ($table) => $db->getSchemaBuilder()->hasTable($table)));
if (count($present) !== count($tables)) {
return ['present' => $present, 'sha256' => null];
}
$frames = [];
sort($tables, SORT_STRING);
foreach ($tables as $table) {
$oid = $db->selectOne('SELECT to_regclass(?)::oid AS id', ['public.'.$table])->id;
$frames[$table] = [
'columns' => $db->select('SELECT a.attname AS name,format_type(a.atttypid,a.atttypmod) AS type,a.attnotnull AS required,pg_get_expr(d.adbin,d.adrelid) AS default_value FROM pg_attribute a LEFT JOIN pg_attrdef d ON d.adrelid=a.attrelid AND d.adnum=a.attnum WHERE a.attrelid=? AND a.attnum>0 AND NOT a.attisdropped ORDER BY a.attnum', [$oid]),
'constraints' => $db->select('SELECT conname AS name,contype AS kind,condeferrable AS deferrable,condeferred AS deferred,convalidated AS validated,pg_get_constraintdef(oid,true) AS definition FROM pg_constraint WHERE conrelid=? ORDER BY conname', [$oid]),
'indexes' => $db->select('SELECT ci.relname AS name,pg_get_indexdef(i.indexrelid) AS definition,i.indisvalid AS valid FROM pg_index i JOIN pg_class ci ON ci.oid=i.indexrelid WHERE i.indrelid=? ORDER BY ci.relname', [$oid]),
'triggers' => $db->select('SELECT t.tgname AS name,t.tgenabled AS enabled,pg_get_triggerdef(t.oid,true) AS definition,pg_get_functiondef(t.tgfoid) AS function_definition FROM pg_trigger t WHERE t.tgrelid=? AND NOT t.tgisinternal ORDER BY t.tgname', [$oid]),
];
}
if ($group === 'budget-distributions-v1') {
$frames['anchors'] = $db->select("SELECT a.attname AS name,format_type(a.atttypid,a.atttypmod) AS type,a.attnotnull AS required FROM pg_attribute a WHERE a.attrelid='public.requisitions'::regclass AND a.attname='budget_distribution_preparation' AND NOT a.attisdropped");
}
return ['present' => $present, 'sha256' => hash('sha256', json_encode($frames, JSON_THROW_ON_ERROR))];
}
}