Every module that requires at least one new database table has a hook_schema to define the table layout. It's very handy because you don't have to write the SQL create table syntax yourself. Although useful, it's useless without the implementation of hook_install, and a call to drupal_install_schema to install the schema for you.

So this begs the question, why don't we just automatically install/uninstall the module's hook_schema when the module is installed/uninstalled, without requiring the implementation of hook_install/hook_uninstall? We can see examples of where this would benefit us within the Drupal core code itself. If you look at the source of aggregator.install, you see aggregator_install with one line telling Drupal to install its own module. Shouldn't Drupal be smart enough to just install the schema for us?

CommentFileSizeAuthor
#4 312618.patch27.55 KBRobLoach
#3 312618.patch26.16 KBRobLoach
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Crell’s picture

Status: Active » Postponed (maintainer needs more info)

Excellent question! :-) I'd ask Barry if there was a particular reason he didn't do that originally. If so, it should be documented. Can someone point him in this direction?

RobLoach’s picture

Thing brings up another issue of system_install installing the schemas of the 'system', 'filter', 'block', 'user', 'node', 'comment', and 'taxonomy' modules.

RobLoach’s picture

Status: Postponed (maintainer needs more info) » Needs work
FileSize
26.16 KB

Tests not running? Hmmm.....

RobLoach’s picture

Status: Needs work » Needs review
FileSize
27.55 KB

Whoops, fixed some things. You can install and uninstall modules, but tests don't run and I'm not quite sure why.... Going to have to investigate later on.

bjaspan’s picture

We discussed this when developing the initial schema api patch. I think the main reason we left it out was just to have one fewer thing change in what was already a pretty large patch.

One advantage to not installing and uninstalling the schema automatically is that it lets a module control whether other actions it wants to perform occur before or after the tables are created or dropped. Sure, the current approach requires a one-line hook_un/install, but that really is not a particularly big burden.

I could see an argument that if a module has hook_schema but not hook_un/install, then the schema is automatically created/dropped, but if there is a hook_un/install, it is responsible to creating/dropping the tables itself as it is now.

Anonymous’s picture

Status: Needs review » Needs work

The last submitted patch failed testing.

David_Rothstein’s picture

Status: Needs work » Fixed

This was recently committed in #306151: Automatically install/uninstall schema, so if @bjaspan's concerns are still relevant it might be worth repeating them over there. I can't at the moment think of a case where a module would really need to control the order that carefully, but maybe there is...

I see the above patch also has code for things like creating a new user_install() function, so if that is still relevant, this issue could be repurposed and reopened.

Status: Fixed » Closed (fixed)

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