diff --git a/web/app/Services/Boot.php b/web/app/Services/Boot.php index 1ac320ea..56296e1b 100644 --- a/web/app/Services/Boot.php +++ b/web/app/Services/Boot.php @@ -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(); } diff --git a/web/tests/BootDatabaseGlobalContractTest.php b/web/tests/BootDatabaseGlobalContractTest.php new file mode 100644 index 00000000..5aa99c23 --- /dev/null +++ b/web/tests/BootDatabaseGlobalContractTest.php @@ -0,0 +1,25 @@ +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";