Problem/Motivation

Database schema field type changes for existing fields with existing data fail for method call updateFieldStorageDefinition() from iframe_update_8101() and iframe_update_8201() update hooks.

Update started: iframe_update_8201
[error] The SQL storage cannot change the schema for an existing field (field_xx in entity) with data.

Proposed resolution

  • Temporarily store the field data to a variable, wipe the data from the database table, change the storage type and restore the field data.
  • There is already a helper method FieldTypeUpdateUtil::_field_type_schema_column_spec_change_helper() that comes in hand with this module and it can be used in the update hooks.

Comments

fathima.asmat created an issue. See original summary.

fathima.asmat’s picture

StatusFileSize
new1.04 KB

A patch is attached.

fathima.asmat’s picture

Assigned: fathima.asmat » Unassigned
Issue summary: View changes
Status: Active » Needs review
nguyenphan’s picture

I apply update-n-hook-fail-3312090-2.patch it is fine when update.

"patches": {
          "drupal/iframe": {
              "Update_N hook fail": "https://www.drupal.org/files/issues/2022-09-27/update-n-hook-fail-3312090-2.patch"
          }
        }

  • neffets committed b9ea596 on 8.x-2.x
    Issue #3312090 by fathima.asmat: Update_N hook fail for field type...
neffets’s picture

Assigned: Unassigned » neffets
Status: Needs review » Fixed

8.x-2.19 fixes the update hooks, thx for the info

fathima.asmat’s picture

Title: Update_N hook fail for field type change for fields with existing data » Update_N hook fail for field type change for fields with existing data/new columns
Status: Fixed » Needs review
StatusFileSize
new1.21 KB

The recent commit merged to the code has also removed the code of adding new columns such as header level to the database table, hence is causing another updb issue unfortunately.

[notice] Update started: iframe_update_8204
  [error]  Exception thrown while performing a schema update. SQLSTATE[42S22]: Column not found: 1054 Unknown
  column 'field_xx_iframe_headerlevel' in 'where clause': SELECT 1 AS "expression"
  FROM ....

See commit removal- https://git.drupalcode.org/project/iframe/-/commit/b9ea596a7c920b6bdb978....
https://git.drupalcode.org/project/iframe/-/commit/b9ea596a7c920b6bdb978...

I have attached a patch below that adds the fields to the schema as part of the helper method that updates the storage definitions for the altered columns.

fathima.asmat’s picture

Version: 8.x-2.x-dev » 8.x-2.19
fathima.asmat’s picture

StatusFileSize
new1.22 KB
new397 bytes

Patch 7 was missing a closing brace, this patch should resolve that.

  • neffets committed 35887cc on 8.x-2.x
    Issue #3312090 by fathima.asmat, neffets: Update_N hook fail for field...
neffets’s picture

Status: Needs review » Fixed

OK.

I added Patch-9 but changed the position in Code.

If get old code with fewer columns and then add the new-ones, it could be that the old-data cannot be imported because of not-null-missing-data-for-column errors.
So I changed the position to
* table => first add the new columns (so any defaults will be filled in)
* then get-old-data
* then wipe
* at end fill in the exported data (with all known columns) to the empty tables.

neffets’s picture

Schema update improved to allow adding new columns for empty tables too in file src/FieldTypeUpdateUtil.php, (see issue #2843108 and issue #937442 too)

Status: Fixed » Closed (fixed)

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