[meta] Replace hook_schema() implementations with ::ensureTableExists()

Created on 28 June 2021, over 3 years ago
Updated 15 June 2023, over 1 year ago

Problem/Motivation

hook_schema() creates a strong dependency between module installation and services provided by modules. This means for example that we have to use KernetTestBase::installSchema() in kernel tests.

We have an existing pattern in core which avoids this, the ::ensureTableExists() pattern. With this, services are responsible for creating their database schema on demand. Some examples: https://api.drupal.org/api/drupal/9.3.x/search/ensureTableExists

Steps to reproduce

Proposed resolution

Apply this pattern to more core services. Eventually deprecate hook_schema() once it's no longer used in core.

At the same time, look at adding a more formal API:
πŸ“Œ Move the on-demand-table creation into the database API Needs work

Note that πŸ“Œ Deprecate Drupal\Core\Database\Connection::nextId() and the {sequences} table and schema Fixed removes a hook_schema() implementation by replacing it with key value.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

🌱 Plan
Status

Active

Version

11.0 πŸ”₯

Component
BaseΒ  β†’

Last updated 1 day ago

Created by

πŸ‡¬πŸ‡§United Kingdom catch

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