diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc index 17e2a66..8bae144 100644 --- a/core/includes/install.core.inc +++ b/core/includes/install.core.inc @@ -899,6 +899,9 @@ function install_base_system(&$install_state) { // Enable the user module so that sessions can be recorded during the // upcoming bootstrap step. + // A user module table references a filter module table, so it must be + // installed first. + module_enable(array('filter'), FALSE); module_enable(array('user'), FALSE); // Save the list of other modules to install for the upcoming tasks. diff --git a/core/lib/Drupal/Core/Database/Driver/mysql/Schema.php b/core/lib/Drupal/Core/Database/Driver/mysql/Schema.php index d88633f..8b96fa1 100644 --- a/core/lib/Drupal/Core/Database/Driver/mysql/Schema.php +++ b/core/lib/Drupal/Core/Database/Driver/mysql/Schema.php @@ -278,6 +278,11 @@ class Schema extends DatabaseSchema { $keys[] = 'INDEX `' . $index . '` (' . $this->createKeysSqlHelper($fields) . ')'; } } + if (!empty($spec['foreign keys'])) { + foreach ($spec['foreign keys'] as $key => $definition) { + $keys[] = 'FOREIGN KEY (`' . implode('`, `', array_keys($definition['columns'])) . '`) REFERENCES ' . $definition['table'] . '(`' . implode('`, `', $definition['columns']) . '`)'; + } + } return $keys; } diff --git a/core/lib/Drupal/Core/Database/Driver/pgsql/Schema.php b/core/lib/Drupal/Core/Database/Driver/pgsql/Schema.php index 0b65280..c041738 100644 --- a/core/lib/Drupal/Core/Database/Driver/pgsql/Schema.php +++ b/core/lib/Drupal/Core/Database/Driver/pgsql/Schema.php @@ -141,6 +141,11 @@ class Schema extends DatabaseSchema { $sql_keys[] = 'CONSTRAINT ' . $this->prefixNonTable($name, $key_name, 'key') . ' UNIQUE (' . implode(', ', $key) . ')'; } } + if (isset($table['foreign keys']) && is_array($table['foreign keys'])) { + foreach ($table['foreign keys'] as $key_name => $key) { + $sql_keys[] = 'FOREIGN KEY (' . implode(', ', array_keys($key['columns'])) . ') REFERENCES ' . $key['table'] . ' (' . implode(', ', $key['columns']) . ')'; + } + } $sql = "CREATE TABLE {" . $name . "} (\n\t"; $sql .= implode(",\n\t", $sql_fields); diff --git a/core/modules/forum/forum.install b/core/modules/forum/forum.install index 8e6fddf..a1fc89b 100644 --- a/core/modules/forum/forum.install +++ b/core/modules/forum/forum.install @@ -163,6 +163,7 @@ function forum_schema() { ), 'primary key' => array('vid'), 'foreign keys' => array( +/* Does not match primary key of referenced table. 'forum_node' => array( 'table' => 'node', 'columns' => array( @@ -170,6 +171,7 @@ function forum_schema() { 'vid' => 'vid', ), ), +*/ ), ); diff --git a/core/modules/node/node.install b/core/modules/node/node.install index ac777f3..6850f8a 100644 --- a/core/modules/node/node.install +++ b/core/modules/node/node.install @@ -127,10 +127,12 @@ function node_schema() { 'uuid' => array('uuid'), ), 'foreign keys' => array( +/* node_revision table not yet created. Can't change the table creation order because they each refer to the other. 'node_revision' => array( 'table' => 'node_revision', 'columns' => array('vid' => 'vid'), ), +*/ 'node_author' => array( 'table' => 'users', 'columns' => array('uid' => 'uid'), @@ -190,10 +192,12 @@ function node_schema() { ), 'primary key' => array('nid', 'gid', 'realm'), 'foreign keys' => array( +/* node_install() creates a record with nid = 0, which cannot exist since nid is serial and must be > 0. https://drupal.org/node/1703222 'affected_node' => array( 'table' => 'node', 'columns' => array('nid' => 'nid'), ), +*/ ), ); diff --git a/core/modules/shortcut/shortcut.install b/core/modules/shortcut/shortcut.install index c4023d7..872c3d0 100644 --- a/core/modules/shortcut/shortcut.install +++ b/core/modules/shortcut/shortcut.install @@ -52,10 +52,12 @@ function shortcut_schema() { ), 'primary key' => array('set_name'), 'foreign keys' => array( +/* shortcut_set_save() creates shortcut_set records before menu_links records, violating this constraint. https://drupal.org/node/1703208 'menu_name' => array( 'table' => 'menu_links', 'columns' => array('set_name' => 'menu_name'), ), +*/ ), ); diff --git a/core/modules/system/system.install b/core/modules/system/system.install index 05459d0..553e5f8 100644 --- a/core/modules/system/system.install +++ b/core/modules/system/system.install @@ -1378,10 +1378,12 @@ function system_schema() { 'ssid' => array('ssid'), ), 'foreign keys' => array( +/* system module is installed first, before users table is created. 'session_user' => array( 'table' => 'users', 'columns' => array('uid' => 'uid'), ), +*/ ), );