Problem/Motivation

Schema

Entity/field definitions
Mismatched entity and/or field definitions
The following changes were detected in the entity type and field definitions.
Order

The Order number field needs to be updated.

Payment

The Remote ID field needs to be updated.

Payment method

The Remote ID field needs to be updated.

Product variation

The SKU field needs to be updated.

Steps to reproduce

Proposed resolution

https://www.drupal.org/docs/drupal-apis/update-api/updating-database-sch...

Remaining tasks

User interface changes

API changes

Data model changes

Issue fork commerce-3183315

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

joelpittet created an issue. See original summary.

joelpittet’s picture

joelpittet’s picture

Issue summary: View changes

Berdir’s picture

I commented on #2907367: Add indexes to important fields because that was easier.

Also, if that change is already in HEAD then this is imho at least a major bug.

Berdir’s picture

Not *quite* the same, but you should just need to do something like this for each affected field:

/**
 * Update the status field.
 */
function paragraphs_update_8014() {
  // The status field was promoted to an entity key in paragraphs_update_8013(),
  // which makes it NOT NULL in the default SQL storage, which means its storage
  // definition needs to be updated as well.
  $entity_definition_update_manager = \Drupal::service('entity.definition_update_manager');
  $entity_definition_update_manager->updateFieldStorageDefinition($entity_definition_update_manager->getFieldStorageDefinition('status', 'paragraph'));
}
joelpittet’s picture

Status: Active » Needs review
FileSize
4.36 KB

Thank you very much @Berdir, it worked very well, the indexes are there and the schema is now updated. I removed public function onEntityTypeUpdate

joelpittet’s picture

Berdir’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me. The onEntityTypeUpdate() might have created the necessary indexes but didn't update the installed field storage definitions.

I'd love to have a better system for this in core that doesn't require custom storage schemas and this seems like a pretty nice start, but things get a bit more complicated once you need indexes that cover multiple fields or unique indexes, fields with multiple properties (e.g. not sure what would happen with the commerce implementation if you try to put an index on a price field).

Dave Kopecek’s picture

I can confirm the RTBC. Thanks to all who worked on this!

  • jsacksick committed 006e800 on 8.x-2.x authored by joelpittet
    Issue #3183315 by joelpittet, Berdir: Update schema for new indexes.
    
jsacksick’s picture

Status: Reviewed & tested by the community » Fixed

Committed! Thanks!

Status: Fixed » Closed (fixed)

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

darrenwh’s picture

I've found another field that needs indexing, adding it to field_indexes and the rerunning the update script does not add an index to the additional field, should it do? https://www.drupal.org/project/commerce/issues/3224681