0

I'm writing a module which utilises a .install file to create and configure things - specifically I'm creating a custom line item based on the commerce_example module. Turns out it's quite a bit of code and will take a bit of time to get right.

This is all good, but how can I go about testing this as I'm going? I'll inevitably want to add fields to the install function later on, but to do this I'll need to disable (and uninstall?) the module, deleting the existing line-items, and re-enable every time I need to test if it's working which seems so slow. Is there a better way of working when doing this?

0

Yes You can write in your hook_update_N() like this in your mymodule.install file:

function mymodule_update_7001() {
 db_add_field('table_name', 'field_name', array(
  'description' => 'The total amount to be paid for the order.',
  'type' => 'numeric',
  'precision' => 16,
  'scale' => 5,
  'not null' => TRUE,
  'default' => 0.0,
 ));
}

After writing this you can simply run your update.php file

  • I'm aware of this, but this means I will have a load of update functions as I add fields. I suppose this is the only way. – Chris Mar 10 '17 at 2:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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