Problem/Motivation
In #838992: Change the uid field from integer to serial by leveraging NO_AUTO_VALUE_ON_ZERO on MySQL we hit an issue because \Drupal\Core\Database\Database static caches database connections across container rebuilds. The postgres schema class static caches schema information which means that an update which affects the table schema will not be reflected in the test runner. The work-around introduced in that issue was to close the db connections after running updates.
This issue will discuss whether we want to fix this in a better way. Normally after rebuilding the container all the services (apart from the one tagged with persist) are new instances. This is not true the database service because it uses \Drupal\Core\Database\Database::getConnection() as a factory.
Steps to reproduce
>>> $database = \Drupal::database();
>>> $cf = \Drupal::configFactory();
>>> drupal_flush_all_caches();
>>> $database === \Drupal::database();
=> true
>>> $cf === \Drupal::configFactory();
=> false
Proposed resolution
Options:
- Close database connections in
\Drupal\Core\DrupalKernel::initializeContainer() - Somehow make the database factory a service - this might be very very tricky because the container is load from the database.
Comments