Tables defined on hook_schema are created automatically, is not necessary to create them on hook_enable or hook_install. Same applies for removing tables on hook_uninstall.

So, those functions can be removed: http://cgit.drupalcode.org/sandbox-AnnaSan-2503695/tree/smartest.install...

Comments

David Hernández’s picture

Status: Active » Needs review
StatusFileSize
new1.26 KB
fran seva’s picture

@David Hernández I think the hook_uninstall is necessary but should be that way:

/**
 * Implements hook_uninstall().
 */
function smartest_uninstall(){ 
 drupal_uninstall_schema('smartest');
}

This is the only way to make a real module delete, I mean, remove all database stored content.

David Hernández’s picture

From the API: https://api.drupal.org/api/drupal/modules%21system%21system.api.php/func...

Database tables defined by hook_schema() will be removed automatically.

So, I think it is not really necessary.

fran seva’s picture

Status: Needs review » Reviewed & tested by the community

@David Hernández yeah!
You were right, sorry I think what I was saying happened in D6 :S

The patch is good for me.

gabrielhruiz’s picture

I think that hook_enable() it's interesting. For example, if you have a new version of the module and this version is linked to a new table in our data base, this table will not be added when you re-install the new version. In my opinion hook_enable() allows that this is possible. This is true?

fran seva’s picture

If you need to update a table, add data to a table or create a table in a new version, it should be used the hook_update_N [1] that allow update a installed module.

As user, when a new module version is lunch I expect just download the code and execute update.php to check if the module needs database update.

@gabrielhruiz can you check if [1] is what you need? I think is the drupal way to implement what you said in #5

[1] https://api.drupal.org/api/drupal/modules%21system%21system.api.php/func...

gabrielhruiz’s picture

You're right. Now I have everything clear, Thanks.

I tested the patch and it's okey for me too.

David Hernández’s picture

When altering a table, it should be done in two places:

  • hook_schema: for new installations.
  • hook_update_N: for people who already installed the module and is updating it.

anabsanchez’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.