2

I specifically wish to solve this problem http://drupal.org/node/1514826#comment-5866494.

Currently the fivestar module's field schema looks like this:

<?php
 function fivestar_field_schema() {
  return array(
    'columns' => array(
      'rating' => array(
        'type' => 'int', 
        'unsigned' => TRUE, 
        'not null' => FALSE, 
        'sortable' => TRUE,
      ), 
      'target' => array(
        'type' => 'int', 
        'unsigned' => TRUE, 
        'not null' => FALSE,
      ),
    ),
  );
}
?>

I would like to change it to:

<?php
 function fivestar_field_schema() {
  return array(
    'columns' => array(
      'rating' => array(
        'type' => 'float', // Change to float from int
        'unsigned' => TRUE, 
        'not null' => FALSE, 
        'sortable' => TRUE,
      ), 
      'target' => array(
        'type' => 'int', 
        'unsigned' => TRUE, 
        'not null' => FALSE,
      ),
    ),
  );
}
?>

This would work for new Fivestar fields. However, those that contain data cannot be updated. Since the field storage can be in SQL or Mongo or Solr, I would like to create a generic update to this. However, the most commonly used sql storage does not allow column changes if it has data (see field_sql_storage_field_storage_update_field()).

Is there a suggested way out? Thanks.

0

1 Answer 1

1

I have no idea if this is a "suggested way out," I'm tending to think not, but, with your site offline, you should be able to use phpmyadmin and:

  1. Add a field to the database table (your float field),

  2. copy all of the data from the original column/field to this new one (something as simple as UPDATE "tablename" SET "newfield" = "oldfield" would probably do it),

  3. drop the original integer field from the table,

  4. rename the new field with the old field's name, and

then take drupal online with the new schema and code that is expecting a float in there instead of an integer.

You could also just rename instead of dropping the original field so you could quickly go back if this screwed up, but I would definitely back things up before trying this in any case :)

1
  • Since this is for a contrib module that many sites use, its impossible to do site-specific fixes. Apr 26, 2012 at 14:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.