Replace array-based Schema API with a value object structure

Created on 31 December 2023, almost 2 years ago

Problem/Motivation

Spin off from ✨ Use events in Database Schema operations Active .

Today,

A Drupal schema definition is an array structure representing one or more tables and their related keys and indexes. A schema is defined by hook_schema(), which usually lives in a modulename.install file.

https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Database%...

Proposed resolution

Change it into a structure of value objects.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

✨ Feature request
Status

Active

Version

11.0 🔥

Component
Database  →

Last updated about 2 months ago

  • Maintained by
  • 🇳🇱Netherlands @daffie
Created by

🇮🇹Italy mondrake 🇮🇹

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

Merge Requests

Comments & Activities

  • Issue created by @mondrake
  • Assigned to mondrake
  • 🇮🇹Italy mondrake 🇮🇹
  • Pipeline finished with Failed
    almost 2 years ago
    Total: 162s
    #70495
  • Pipeline finished with Failed
    almost 2 years ago
    Total: 511s
    #70496
  • Pipeline finished with Failed
    almost 2 years ago
    #70511
  • Pipeline finished with Failed
    almost 2 years ago
    Total: 519s
    #70524
  • Pipeline finished with Failed
    almost 2 years ago
    #70543
  • Pipeline finished with Failed
    almost 2 years ago
    Total: 180s
    #70547
  • Pipeline finished with Failed
    almost 2 years ago
    Total: 672s
    #70556
  • Pipeline finished with Success
    almost 2 years ago
    Total: 552s
    #70583
  • Pipeline finished with Failed
    almost 2 years ago
    Total: 314s
    #70624
  • Pipeline finished with Failed
    almost 2 years ago
    #70627
  • Pipeline finished with Success
    almost 2 years ago
    #70630
  • Status changed to Needs review almost 2 years ago
  • 🇮🇹Italy mondrake 🇮🇹

    Here's a MR that tries to do the minimum possible:

    • add all the relevant value objects to the Drupal\Core\Database\SchemaDefinition namespace
    • adds a converter from the new API to the old API + a basic test, and makes adjustments so that we can use the new API in hook_schema() or other functions without impacting the database driver code (that will be huge, but follow ups). In practice the new API is converted to the old one on the fly.
    • added a couple of example conversions to demonstrate the new API, for system_schema() and Drupal\Core\Batch\BatchStorage::schemaDefinition(). I would leave conversions to followups, too, because it's a lot of work, especially for cases where the old array structure is built dynamically.

    Looking forward to reviews!

  • Pipeline finished with Success
    almost 2 years ago
    Total: 1076s
    #70762
  • Status changed to Needs work almost 2 years ago
  • 🇮🇹Italy mondrake 🇮🇹

    Let’s change the trait to an abstract class.

  • Pipeline finished with Success
    almost 2 years ago
    Total: 683s
    #71004
  • Pipeline finished with Success
    almost 2 years ago
    Total: 1234s
    #71064
  • Pipeline finished with Failed
    almost 2 years ago
    Total: 184s
    #71095
  • Issue was unassigned.
  • Status changed to Needs review almost 2 years ago
  • 🇮🇹Italy mondrake 🇮🇹

    For review. Invocation of hook_schema now return by default the array version of the schema definition, for BC. Code needs to explicitly opt-in to get Table objects instead or array shapes. In the future this will change but this allows to manage transition to the new approach.

  • Pipeline finished with Success
    almost 2 years ago
    Total: 1029s
    #71100
  • Status changed to Needs work almost 2 years ago
  • 🇮🇹Italy mondrake 🇮🇹

    Adding an enum for column size.

  • 🇮🇹Italy mondrake 🇮🇹
  • Pipeline finished with Canceled
    almost 2 years ago
    Total: 459s
    #71139
  • Status changed to Needs review almost 2 years ago
  • 🇮🇹Italy mondrake 🇮🇹
  • Pipeline finished with Success
    almost 2 years ago
    Total: 8122s
    #71144
  • Pipeline finished with Success
    almost 2 years ago
    Total: 939s
    #71408
  • 🇮🇹Italy mondrake 🇮🇹
  • Status changed to Needs work over 1 year ago
  • The Needs Review Queue Bot → tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

    This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

    Consult the Drupal Contributor Guide → to find step-by-step guides for working with issues.

  • Pipeline finished with Failed
    over 1 year ago
    #110783
  • 🇺🇸United States bradjones1 Digital Nomad Life

    Worth noting we're doing something similar but not quite the same over at 📌 Adding GIN and GIST indexes to PostgreSQL databases RTBC .

    Per some feedback in Drupal Slack today, it sounds like the ideal state would be to use events a la ✨ Use events in Database Schema operations Active but we're postponed enough as it is on related issues. At the very least, this demonstrates how we can use objects in some circumstances inside of "ArrayPI" without breaking BC and enabling innovation.

  • Pipeline finished with Failed
    22 days ago
    Total: 179s
    #620976
  • Pipeline finished with Failed
    22 days ago
    Total: 164s
    #620984
  • Status changed to Needs review 22 days ago
  • Pipeline finished with Failed
    22 days ago
    Total: 1479s
    #620992
  • Pipeline finished with Failed
    3 days ago
    Total: 1407s
    #640722
Production build 0.71.5 2024