assertInstallation($db); $runtime->assertLoadedPackages(allowMissing: true); $paths = $runtime->artifact()['paths']; foreach (StandaloneArtifact::PACKAGES as $package) { require_once $paths[$package].'/bootstrap.php'; } $runtime->assertLoadedPackages(); $schemas = []; foreach ([LedgerSchema::class => ['COMMON-LEDGER-HOST-SCHEMA-v1', true], 'Tempo\\Finance\\Payables\\SettlementSchema' => ['COMMON-PAYABLE-SETTLEMENT-HOST-SCHEMA-v1', false], 'Tempo\\Finance\\Payables\\ReversalSchema' => ['COMMON-PAYABLE-REVERSAL-HOST-SCHEMA-v1', false], 'Tempo\\Finance\\GeneralLedger\\CycleSchema' => ['COMMON-LEDGER-CYCLE-HOST-SCHEMA-v1', true]] as $class => [$contract, $connectionArgument]) { if (! class_exists($class, false)) { throw new \LogicException('COMPRAS_RUNTIME_FINANCE_SCHEMA_MISSING'); } $schema = new \ReflectionClass($class); if (! $schema->hasConstant('HOST_SCHEMA_CONTRACT') || $schema->getConstant('HOST_SCHEMA_CONTRACT') !== $contract || ! $schema->hasMethod('installForHost')) { throw new \LogicException('COMPRAS_RUNTIME_FINANCE_SCHEMA_CONTRACT'); } $schemas[] = [$schema, $contract, $connectionArgument]; } $db->transaction(function () use ($db, $runtime, $settings, $schemas) { $db->selectOne('SELECT pg_advisory_xact_lock(hashtextextended(?, 0))', [$settings['installation_id']]); $runtime->assertInstallation($db); foreach (['budget_distributions', 'budget_order_commands', 'purchase_order_sources', 'budget_landed_commands', 'budget_requisition_cycles', 'gl_accounts', 'ps_payments', 'ps_reversals', 'gl_corrections'] as $table) { if ($db->getSchemaBuilder()->hasTable($table)) { throw new \LogicException('COMPRAS_RUNTIME_EXTENSION_SCHEMA_EXISTS'); } } // The normal application migrations already install the common payables schema. StandaloneSchema::verify($db->getSchemaBuilder(), ['supplier-payables' => true]); BudgetDistributionSchema::install(); BudgetOrderPartsSchema::install($db); PurchaseOrderSourcesSchema::install($db); BudgetLandedCostSchema::install($db); RequisitionCycleSchema::install($db); foreach ($schemas as [$schema, $contract, $connectionArgument]) { $arguments = [$contract, fn () => $runtime->assertInstallation($db)]; if ($connectionArgument) { array_unshift($arguments, $db); } $schema->getMethod('installForHost')->invokeArgs(null, $arguments); } }); } }