Error starting to use "long" item_ids with old database

Created on 11 December 2024, 4 months ago

I'm currently working on a site that was built in 2014/2015. Recently, I added a module that required item_ids with a length of ≈80 characters. This created the following error:

SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'item_id' at row 1: INSERT INTO "search_api_item" ("index_id", "datasource", "item_id", "changed", "status") VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4); Array
(
    [:db_insert_placeholder_0] => temp
    [:db_insert_placeholder_1] => date_recur:node__field_date
    [:db_insert_placeholder_2] => date_recur:node__field_date/3138:en:0:2015-01-08-15-30-00--2015-01-08-18-00-00
    [:db_insert_placeholder_3] => 1733920571
    [:db_insert_placeholder_4] => 1
)

I know that the size was increased with https://www.drupal.org/project/search_api/issues/2704761 #2704761 around alpha15. But there wasn't an update hook to match old databases with the new code.

I created a hook in one of the custom modules for the site to bring the database in line with the code:

function hook_update_N{
  $field_spec = [
    'type' => 'varchar',
    'length' => '150',
    'not null' => false,
  ];
  \Drupal::database()->schema()->changeField('search_api_item', 'item_id', 'item_id', $field_spec);
}

As alpha15 was around 9 years ago, I don't expect this to proceed further. I'm documenting my findings in case someone else needs it.

🐛 Bug report
Status

Active

Version

1.0

Component

General code

Created by

🇬🇧United Kingdom John Cook

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

Comments & Activities

  • Issue created by @John Cook
  • 🇦🇹Austria drunken monkey Vienna, Austria

    Thanks for posting this! You’re right, this might still help others who come across this problem.
    However, I’m still marking it as “works as designed”. Alpha versions come with the explicit warning that data compatibility is not guaranteed, so problems like this are expected.

Production build 0.71.5 2024