Updating from alpha1 to alpha2 seems to fail because of the changes in eck.schema.yml (https://www.drupal.org/node/2797775).

All entity types created through ECK get a field mismatch error (https://www.drupal.org/node/2554101) on the ID column. The change from mapping to config_entity type alters the 'Unsigned' value of each ID field (from false to true) and Drupal will not update fields with data.

I tried to manually enable the unsigned value for the id fields but since the last used configuration is in key_value storage Drupal does not notice that the unsigned bit is actually ok now. How to update the values in the key_value store with the actual field/table config is beyond me. Running drush entity-updates does not do the trick here either.

Steps to reproduce:

  1. Start from alpha1 version
  2. Create a entity type, bundle and add an entity for that bundle
  3. Update the module to alpha2
  4. Check the drupal status report for mismatch errors on the ID base field for the entity type

I fixed the issue for now by reverting to alpha1 (which makes the errors go away)

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

spoit created an issue. See original summary.

legolasbo’s picture

I've managed to reproduce the issue. Let's see if we can fix it.

legolasbo’s picture

Status: Active » Needs review
FileSize
1.97 KB

This issue is actually introduced in #2825144: Refactor EckEntity.php instead of #2797775: Simplify eck.schema.yml.

Attached patch adds an update path. Please test this thoroughly on a backed-up database as I've only tested it on a single entity type.

OnkelTem’s picture

The patch hasn't worked for my case.
It fails on applying updates in eck_update_8005()

$manager = \Drupal::entityDefinitionUpdateManager();
$manager->applyUpdates();

with the error:

SQLSTATE[22004]: Null value not allowed: 1138 Invalid use of NULL value: ALTER TABLE {author} CHANGE `id` `id` INT unsigned NOT NULL;

It first deletes ID field (!) from both tables (which is indeed a wrong thing to do), and then adds it back with obviously NULL values, but since it can not be NULL according to its definition the operation fails.

OnkelTem’s picture

Sharing my solution instead.

WARNING: this hook is mysql-specific!

/**
 * Upgrades ECK tables (ID columns should be of unsinged int type) and installs new definitions from code.
 */
function HOOK_update_NNN() {
  $connection = Drupal::database();
  $entity_definition_update_manager = Drupal::service('entity.definition_update_manager');
  $entity_types = Drupal::entityTypeManager()->getDefinitions();
  $eck_entity_types = Drupal::entityTypeManager()->getStorage('eck_entity_type')->loadMultiple();

  /** @var \Drupal\Core\Entity\ContentEntityType $entity_type */
  foreach (array_intersect_key($entity_types, $eck_entity_types) as $entity_type) {
    // Update database tables
    $connection->query('ALTER TABLE {' . $entity_type->getBaseTable() . '} MODIFY id int(10) unsigned NOT NULL AUTO_INCREMENT');
    $connection->query('ALTER TABLE {' . $entity_type->getDataTable() . '} MODIFY id int(10) unsigned NOT NULL');
    // Install new definitions from code
    $entity_definition_update_manager->installEntityType($entity_type);
  }
}
legolasbo’s picture

So I've taken the suggestion from #5 and adjusted it to use Drupal's database abstraction layer. This is a far cleaner solution! please test so we can quickly commit and roll an alpha3

OnkelTem’s picture

Thank you, it looks much better now! I've never been good with Drupal Schema :^)

Can't test it though - have no old database by hand, but I hope other uses might check it out soon.

KarlShea’s picture

Status: Needs review » Reviewed & tested by the community

Worked for me!

tim.abbott’s picture

Worked for me too, many thanks!

legolasbo’s picture

Thanks for the feedback guys. I'll commit this and roll a new alpha asap.

proweb.ua’s picture

#6 works

  • legolasbo committed 83b4ea4 on 8.x-1.x
    Issue #2825407 by legolasbo, OnkelTem: Changes to eck.schema.yml trigger...
legolasbo’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed to 8.x-1.x, thanks!

Status: Fixed » Closed (fixed)

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

SalAG’s picture

Are there any solutions for a postgres database, which don't have unsigned int types?

This issue has left me in eck 1.0-alpha 1 for far too long and I think this might hold me back from updating into 8.8 from 8.7.12

Any help appreciated.