Problem/Motivation

Drupal's powerful field system keeps a copy of the schema. Contrib modules are able to update fields in the database, especially to increase column size, even if the field has data. Currently the SqlContentEntityStorageSchema class will refuse to update its stored schema definitions if the field contains data, even if the database columns have already been updated.

This change is also part of the proposed changes in #2885413: Timestamp field items are affected by 2038 bug but is proposed separately here in hopes at least this part could be committed more quickly.

Steps to reproduce

The easiest way to reproduce would be using a contrib module that recently expanded its storage to deal with the Y2038 problem. With a fresh install of Drupal 10, install Smart Date 3.7.x and add a Smart Date field to a content type. Create a node of this type with a value for the Smart Date field. Now, update Smart Date to

Proposed resolution

Add a setting to SqlContentEntityStorageSchema to indicate that the database columns have already been updated, allowing the stored schema to be updated.

Remaining tasks

If this issue gets implemented, the same change should be removed from the MR in #2885413: Timestamp field items are affected by 2038 bug

User interface changes

N/A

API changes

The addition of the column_changes_handled setting could be considered an expansion of the API and should be documented.

Data model changes

N/A

Release notes snippet

Modules needing to update the stored schema for fields that have been increased in size in an update hook can now do so by adding the column_changes_handled setting in the storage definition when calling updateFieldStorageDefinition.

Issue fork drupal-3406172

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mandclu created an issue. See original summary.

mandclu’s picture

Status: Active » Needs review
smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

Will need test coverage.

Also not sure if this would require an update to the schema

mxr576’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests

I see test coverage in the MR now.

mxr576’s picture

Status: Needs review » Reviewed & tested by the community

Tested the patch and I can confirm it is working.

alexpott’s picture

Version: 11.x-dev » 10.3.x-dev
Status: Reviewed & tested by the community » Fixed

Committed and pushed fdfb3c6675 to 11.x and e4aafad82b to 10.3.x. Thanks!

  • alexpott committed e4aafad8 on 10.3.x
    Issue #3406172 by mandclu: Provide a flag to allow updates to stored...

  • alexpott committed fdfb3c66 on 11.x
    Issue #3406172 by mandclu: Provide a flag to allow updates to stored...
Wim Leers’s picture

Intriguing issue! I wonder if we could piggyback on this this infrastructure in https://www.drupal.org/project/distributions_recipes to allow reverting of DB schema modifications upon applying a recipe (i.e. when installing FieldStorageConfig + FieldConfig) … 🕵️‍♂️

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.