[development] D6 SAPI: using hook_install to ALTER {tables}
Barry Jaspan
barry at jaspan.org
Tue Feb 12 20:03:13 UTC 2008
> What if a contrib module wants to ALTER an existing table (created by
> another module)?
>
> Q1) Do I still use hook_schema() to define the extra field and call it
> from hook_install() as in the examples?
>
> Q2) Or, do I call db_add_field() from hook_install()?
>
> Q3) Is it considered best practice to create your own tables rather
> than adding fields to existing tables "belonging" to other modules?
Generally, case (3) is correct: Don't modify other modules' tables;
create your own instead.
D6 does in fact support a hook_schema_alter(). In principal, you
could (a) implement hook_schema_alter() to put your changes into an
existing table and (b) implement a hook_update_N() function or
hook_install() function using the db_*() functions to actually make
the change. However, no part of core (or contrib that I know of) does
this and it certainly has not been tested. There are many unanswered
questions; for example, what if the module whose table you altered
changes its schema and drops the table? Your data will be lost. So
it is best for now not to use it (and it is not documented for this
exact reason).
Thanks,
Barry
More information about the development
mailing list