You are here

function field_sql_storage_update_7002 in Drupal 7

Fix primary keys in field revision data tables.

Related topics

File

modules/field/modules/field_sql_storage/field_sql_storage.install, line 197
Install, update and uninstall functions for the field_sql_storage module.

Code

function field_sql_storage_update_7002() {
  $results = db_select('field_config', 'fc', array(
    'fetch' => PDO::FETCH_ASSOC,
  ))
    ->fields('fc')
    ->condition('storage_module', 'field_sql_storage')
    ->execute();
  foreach ($results as $field) {

    // Revision tables of deleted fields do not need to be fixed, since no new
    // data is written to them.
    if (!$field['deleted']) {
      $table = "field_revision_{$field['field_name']}";
      db_drop_primary_key($table);
      db_add_primary_key($table, array(
        'entity_type',
        'entity_id',
        'revision_id',
        'deleted',
        'delta',
        'language',
      ));
    }
  }
}