4

I was tasked with altering the signature/signature format and make the length larger than 255. Within the given time, I had to alter the table using hook_schema_alter, db_change_field and hook_update. While I am aware this is semi hacking, I want to know what if this could have a huge consequence on my website.

2
  • 2
    I can't find the reference right now but one of the core developers once told me that doing this was "a very Drupal 5 way of thinking" (it was in reference to this post I think). There shouldn't be any negative effects on your site (in fact you've done it exactly the right way), it just might not be considered 'best practice'
    – Clive
    Nov 13 '12 at 22:46
  • Gosh, I've had to change a varchar field from 255 to 1024 before and hadn't run into any problems, even without touching hook_schema. I'd love to hear if anyone can point out specific problems we might run into. It seemed to me that PDO threw exceptions on character limits, not the schema API. Nov 14 '12 at 2:32
0

For your case, as you are just altering a field's length, without adding new fields, or new indexes, the only problem could be code that handles the same field, and which uses an hardcoded value for its length. That could be code executed from a third-party module, or a future version of Drupal.
For example, user_validate_name(), the function that is used to validate the username entered during the account registration, or when the user account is edited, uses the following code.

if (drupal_strlen($name) > USERNAME_MAX_LENGTH) {
  return t('The username %name is too long: it must be %max characters or less.', array('%name' => $name, '%max' => USERNAME_MAX_LENGTH));
}

If a module alters the database field containing the username to make it bigger, Drupal would still throw an error when the username length is higher than USERNAME_MAX_LENGTH (actually 60, also in Drupal 8).

The reason why altering a database table defined from a module is not something suggested to do is that it would cause problems when more than one module do that for the same field. Imagine what would happen if a module increases the length of the signature field to 350, and another module changes it to 300.
The other problem is when the modules are uninstalled. Which size would the field get when one of the modules is uninstalled? If modules remember the size the field had before they were installed, there would be a problem when modules are uninstalled in an order that is different from the installation one. If modules restore the field size to the original one, that would cause a problem when only one module changing the field is uninstalled.

In the case a module adds a new field, there could be some performance issues if the module doesn't introduce an index. If the module introduces an index for the added field, there could be errors with the SQL queries used from the module that introduced the database table; if then those queries are not dynamic, it would not be possible for the module that added the field to alter them.

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.