Add hook_create_table

Created on 24 June 2007, almost 18 years ago
Updated 9 April 2025, 13 days ago

db_create_table currently is:

function db_create_table(&$ret, $table) {
  $statements = db_create_table_sql($table);
  foreach ($statements as $statement) {
    $ret[] = update_sql($statement);
  }
}

I think modules should be able to inject additional SQL statements to create a table. Something like:

function db_create_table(&$ret, $table) {
  $statements = array_merge(db_create_table_sql($table), module_invoke_all('create_table', $table));
  foreach ($statements as $statement) {
    $ret[] = update_sql($statement);
  }
}

A similar hook would be necessary for db_drop_table. Not sure about db_add/drop_field, key, or index.

Why do I want this? One example: I think it would make it possible to implement foreign keys incrementally via an optional module. Any module could use hook_schema_alter() to add foreign key info and then foreign_keys.module (or whatever) would then hook_create_table() to add ALTER TABLE foo ADD FOREIGN KEY... statements, and use the new deletion API to provide cascade on delete semantics when necessary.

I'll think about this more and, if I still like the idea in the morning, will submit a patch.

πŸ“Œ Task
Status

Postponed: needs info

Version

11.0 πŸ”₯

Component

database system

Created by

πŸ‡ΊπŸ‡ΈUnited States bjaspan

Live updates comments and jobs are added and updated live.
  • stale-issue-cleanup

    To track issues in the developing policy for closing stale issues, [Policy, no patch] closing older issues

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Thank you for creating this issue to improve Drupal.

    We are working to decide if this task is still relevant to a currently supported version of Drupal. There hasn't been any discussion here for over 8 years which suggests that this has either been implemented or is no longer relevant. Your thoughts on this will allow a decision to be made.

    Since we need more information to move forward with this issue, the status is now Postponed (maintainer needs more info). If we don't receive additional information to help with the issue, it may be closed after three months.

    Thanks!

Production build 0.71.5 2024