drupal 7 – Actualizar esquema de campo

Pregunta:

Ahora que content_alter_db() se ha eliminado de D7, ¿cuál es la receta para actualizar el esquema de un campo?

Mi campo necesita cambiar de

function sheetnode_field_schema_7001($field) {
$columns = array(
  'value' => array(
    'description' => 'The worksheet content.',
    'type' => 'text',
    'size' => 'big',
    'not null' => TRUE,
  ),
);
$indexes = array();
return array(
  'columns' => $columns,
  'indexes' => $indexes,
);
}

a

function sheetnode_field_schema_7002($field) {
$columns = array(
  'value' => array(
    'description' => 'The worksheet content.',
    'type' => 'text',
    'size' => 'big',
    'not null' => TRUE,
  ),
  'name' => array(
    'description' => 'The worksheet title.',
    'type' => 'varchar',
    'length' => 255,
    'not null' => FALSE,
  ),
);
$indexes = array(
  'name' => array('name'),
);
return array(
  'columns' => $columns,
  'indexes' => $indexes,
);
}

Respuesta:

Basado en la respuesta de megadesk3000, terminé escribiendo el siguiente código:

function sheetnode_update_7002(&$sandbox) {
  $fields = field_info_fields();
  foreach ($fields as $field_name => $field) {
    if ($field['type'] == 'sheetfield' && $field['storage']['type'] == 'field_sql_storage') {
      $schema = sheetnode_field_schema_7002($field);
      foreach ($field['storage']['details']['sql'] as $type => $table_info) {
        foreach ($table_info as $table_name => $columns) {
          $column_name = _field_sql_storage_columnname($field_name, 'name');
          db_add_field($table_name, $column_name, $schema['columns']['name']);
          db_add_index($table_name, $column_name, array($column_name));
        }
      }
    }
  }
  field_cache_clear();
}

Esto pareció funcionar bien.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top

web tasarım