When you create a new table in hook_schema()
, should that table be added in a hook_update_N()
as well? Or is there some trick, or something I missed, to have databae-updates automatically add tables?
The documentation of hook_update_N() does not explain anything about introducing new tables, whereas the documentation of hook_schema()
says:
The tables declared by this hook will be automatically created when the module is first enabled, and removed when the module is uninstalled.
(Highlight is mine)
And if so, how to best avoid duplicating the schema definitions for the new table in both hook_update_N() and hook_schema(). Simply referring to the schema as follows:
function hook_update_N(&$sandbox) { $schema = hook_schema(); $name = "foo"; $table = $schema["foo"]; db_create_table($name, $table); }
Seems to work, but on changing the table again, will fail if a user runs the updates and gets to run two or more hook_update_N()s. After all: the first hook_update_N will then already install the correct database and the second hook_update_M() will try to add/change/alter columns that were already up-to-date.
How do you deal with this?