Commit 288c0586 authored by catch's avatar catch
Browse files

Issue #3388170 by DiDebru, tetranz, alexpott, smustgrave: system update 10100 cache tables fail

(cherry picked from commit e8778fb2)
parent 29617467
Loading
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -1823,6 +1823,12 @@ function system_update_10100(&$sandbox = NULL) {
  });
  if ($connection->databaseType() != 'sqlite') {
    foreach (array_keys($cache_tables) as $table) {
      // If the table has no expire column there is nothing to do. This can
      // happen if a site has tables starting with cache_ that are not cache
      // bins.
      if (!$schema->fieldExists($table, 'expire')) {
        continue;
      }
      // Truncate cache tables. They will be flushed anyway at the end of
      // database updates, but emptying the tables now will boost the schema
      // changes.
+12 −1
Original line number Diff line number Diff line
@@ -95,6 +95,17 @@ public function testUpdate() {
      $this->markTestSkipped("This test does not support the SQLite database driver.");
    }

    // Create a table starting with cache that is not a cache bin.
    \Drupal::service('database')->schema()->createTable('cache_bogus', [
      'fields' => [
        'id'  => [
          'type' => 'int',
          'not null' => TRUE,
        ],
      ],
      'primary key' => ['id'],
    ]);

    $this->collectTimestampFieldsFromDatabase();
    // PostgreSQL returns the value 'integer' instead of 'int' when queried
    // about the column type. Some PostgreSQL tables are already of the type
@@ -120,7 +131,7 @@ public function collectTimestampFieldsFromDatabase() {
    }
    $tables = $connection->schema()->findTables('cache_%');
    $tables = array_filter($tables, function ($table) {
      return str_starts_with($table, 'cache_');
      return str_starts_with($table, 'cache_') && $table !== 'cache_bogus';
    });
    $this->assertNotEmpty($tables);
    foreach ($tables as $table) {