function field_sql_storage_update_7002

Fix primary keys in field revision data tables.

Related topics

File

modules/field/modules/field_sql_storage/field_sql_storage.install, line 197

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',
            ));
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.