@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use Illuminate\Database\Schema\Builder;
|
||||
use LogicException;
|
||||
|
||||
/** Read-only startup preflight; never installs, repairs or enables a module. */
|
||||
final class StandaloneSchema
|
||||
{
|
||||
/** @param array<string,mixed> $features */
|
||||
public static function verify(Builder $schema, array $features): void
|
||||
{
|
||||
foreach (['import-legal' => ['import-tariffs'], 'import-bank-support' => ['import-dossier'],
|
||||
'import-readiness' => ['import-dossier'], 'general-ledger' => ['supplier-payables'],
|
||||
'supplier-settlements' => ['supplier-payables'], 'general-ledger-cycle' => ['general-ledger', 'supplier-settlements']] as $feature => $dependencies) {
|
||||
foreach ($dependencies as $dependency) {
|
||||
if (($features[$feature] ?? false) === true && ($features[$dependency] ?? false) !== true) {
|
||||
throw new LogicException('COMPRAS_RUNTIME_FEATURE_DEPENDENCY:'.$feature.':'.$dependency);
|
||||
}
|
||||
}
|
||||
}
|
||||
$tables = ['supply_records' => ['id', 'tenant_id', 'kind', 'record_key', 'version', 'data', 'snapshot', 'operation_key'],
|
||||
'requisitions' => ['id', 'tenant_id', 'status'], 'users' => ['id', 'tenant_id']];
|
||||
foreach ($features as $feature => $enabled) {
|
||||
if ($enabled !== true) {
|
||||
continue;
|
||||
}
|
||||
$required = match ($feature) {
|
||||
'capital-register' => ['equipment' => ['id', 'tenant_id', 'department_id']],
|
||||
'private-audit' => ['private_audit_exports' => ['id', 'tenant_id']],
|
||||
'conflict-releases' => ['conflict_releases' => ['id', 'tenant_id']],
|
||||
'requisition-accounts' => ['gl_accounts' => ['id', 'tenant_id', 'company_id', 'unit_id', 'code', 'label', 'currency', 'is_movement']],
|
||||
'requisition-expiry' => ['budget_requisition_cycles' => ['id', 'requisition_id', 'cycle', 'state'],
|
||||
'requisitions' => ['approval_cycle', 'process_version'], 'approval_steps' => ['approval_cycle'],
|
||||
'budget_entries' => ['requisition_cycle'], 'workflow_notices' => ['event_kind'], 'requisition_commands' => ['id']],
|
||||
'budget-distributions' => ['budget_distributions' => ['id', 'tenant_id'], 'budget_distribution_events' => ['id'],
|
||||
'budget_distribution_entries' => ['id'], 'budget_distribution_consumptions' => ['id'],
|
||||
'requisitions' => ['budget_distribution_preparation']],
|
||||
'order-parts' => ['budget_order_commands' => ['id', 'tenant_id'], 'budget_order_bindings' => ['id'],
|
||||
'budget_order_allocations' => ['id'], 'budget_order_consumptions' => ['id'], 'purchase_order_sources' => ['id']],
|
||||
'import-landed-costs' => ['budget_landed_commands' => ['id', 'tenant_id'], 'budget_landed_entries' => ['id']],
|
||||
'supplier-payables' => ['pa_sources' => ['id', 'tenant_id'], 'pa_proposals' => ['id'], 'pa_obligations' => ['id'],
|
||||
'pa_events' => ['id'], 'pa_outbox' => ['event_id', 'state'], 'pa_commands' => ['id'], 'pa_access' => ['user_id', 'person', 'action']],
|
||||
'general-ledger' => ['gl_accounts' => ['id', 'tenant_id'], 'gl_periods' => ['id'], 'gl_rules' => ['id'],
|
||||
'gl_proposals' => ['id'], 'gl_reviews' => ['id'], 'gl_journals' => ['id'], 'gl_lines' => ['id'],
|
||||
'gl_commands' => ['id'], 'gl_events' => ['id']],
|
||||
'supplier-settlements' => ['ps_payments' => ['id', 'tenant_id'], 'ps_payment_decisions' => ['id'],
|
||||
'ps_proposals' => ['id', 'allocation_cycle'], 'ps_allocation_aliases' => ['id'], 'ps_allocation_decisions' => ['id'],
|
||||
'ps_allocations' => ['id'], 'ps_commands' => ['id'], 'ps_events' => ['id'], 'ps_outbox' => ['event_id', 'state'],
|
||||
'ps_reversal_proposals' => ['id'], 'ps_reversals' => ['id']],
|
||||
'general-ledger-cycle' => ['gl_corrections' => ['id'], 'gl_correction_results' => ['id'],
|
||||
'gl_period_checks' => ['id'], 'gl_period_reviews' => ['id'], 'gl_period_closures' => ['id']],
|
||||
default => [],
|
||||
};
|
||||
foreach ($required as $table => $columns) {
|
||||
$tables[$table] = array_values(array_unique([...($tables[$table] ?? []), ...$columns]));
|
||||
}
|
||||
}
|
||||
foreach ($tables as $table => $columns) {
|
||||
if (! $schema->hasColumns($table, $columns)) {
|
||||
throw new LogicException('COMPRAS_RUNTIME_SCHEMA_INCOMPLETE:'.$table);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user