Move the on-demand-table creation into the database API

Created on 8 November 2014, almost 10 years ago
Updated 5 August 2023, about 1 year ago

Problem/Motivation

Menu tree storage, config and cache uses the same pattern: execute a query, catch an exception, try to create the table, if succeeded rerun the query. This is already wasteful and there's already demand #2338747: Move {router} out of system.install and create the table lazy for it elsewhere.

Proposed resolution

  1. We add a schemaProvider interface with a single getSchema method that takes an optional table name argument.
  2. We add a per driver isTableMissingException method that checks an exception whether it means table is missing. Sucks PDO doesn't do that.
  3. Queries can specify $options = ['schema_provider' => $this] which is then used in order to create the table on the fly.
  4. query will catch the exceptions and call the isTableMissingException method (this can be disabled by an option). For selects it returns new FakeStatement([]);. insert and merge passes in a table name. For insert/update/merge ... it will create the passed in tables.

Note: This concept has limits, so for example tables which are used in entity queries/views, so ones which contain joins, are not supported yet.

Remaining tasks

User interface changes

API changes

  • Add Schema::ensureTableExists()
  • Queries, like db_select() etc. get $options = ['schema_provider' => $this]/li>

This is an API addition: schema gets ensureTableExists and query gets executeEnsuringTable -- so it should be good to go.

📌 Task
Status

Needs work

Version

11.0 🔥

Component
Database 

Last updated less than a minute ago

  • Maintained by
  • 🇳🇱Netherlands @daffie
Created by

🇨🇦Canada chx

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024