fix: initialize Capsule static database access

go
codex 2 weeks ago
parent cf6ab25c47
commit 2cd7b7a16e

@ -40,6 +40,11 @@ class Boot
if (Config::get('enable_log')=='true') {
$capsule->addConnection(Config::getLogDbConfig(), 'log');
}
// Several database-only coordinators intentionally use Capsule's
// static query builder so every write in one workflow shares the
// connection selected by the surrounding transaction. Eloquent's
// resolver alone does not initialize that static Capsule instance.
$capsule->setAsGlobal();
$capsule->bootEloquent();
self::bootPaginator();
}

@ -0,0 +1,25 @@
<?php
$source = file_get_contents(
dirname(__DIR__) . '/app/Services/Boot.php'
);
if ($source === false) {
throw new RuntimeException('Unable to read the database bootstrap.');
}
$start = strpos($source, 'public static function bootDb()');
$end = strpos($source, 'private static function bootPaginator()', $start ?: 0);
if ($start === false || $end === false || $end <= $start) {
throw new RuntimeException('Unable to isolate Boot::bootDb().');
}
$method = substr($source, $start, $end - $start);
$global = strpos($method, '$capsule->setAsGlobal();');
$eloquent = strpos($method, '$capsule->bootEloquent();');
if ($global === false || $eloquent === false || $global > $eloquent) {
throw new RuntimeException(
'Boot::bootDb() must initialize Capsule static queries before Eloquent.'
);
}
echo "Boot database global contract tests passed\n";
Loading…
Cancel
Save