Commit db536802 authored by Dries's avatar Dries

- Patch #880132 by bojanz: hook_schema() doesn't support compound foreign...

- Patch #880132 by bojanz: hook_schema() doesn't support compound foreign keys; inconsistent implementations in core.
parent 39d67044
...@@ -75,10 +75,11 @@ ...@@ -75,10 +75,11 @@
* - 'unique keys': An associative array of unique keys ('keyname' => * - 'unique keys': An associative array of unique keys ('keyname' =>
* specification). Each specification is an array of one or more * specification). Each specification is an array of one or more
* key column specifiers (see below) that form a unique key on the table. * key column specifiers (see below) that form a unique key on the table.
* - 'foreign keys': An associative array, each key references a column * - 'foreign keys': An associative array of relations ('my_relation' =>
* of the local table, each value is an array with a single key pair as * specification). Each specification is an array containing the name of
* 'tablename' => 'column' where 'column' is the foreign column to * the referenced table ('table'), and an array of column mappings
* reference. * ('columns'). Column mappings are defined by key pairs ('source_column' =>
* 'referenced_column').
* - 'indexes': An associative array of indexes ('indexname' => * - 'indexes': An associative array of indexes ('indexname' =>
* specification). Each specification is an array of one or more * specification). Each specification is an array of one or more
* key column specifiers (see below) that form an index on the * key column specifiers (see below) that form an index on the
...@@ -131,8 +132,14 @@ ...@@ -131,8 +132,14 @@
* 'vid' => array('vid'), * 'vid' => array('vid'),
* ), * ),
* 'foreign keys' => array( * 'foreign keys' => array(
* 'vid' => array('node_revision' => 'vid'), * 'node_revision' => array(
* 'uid' => array('users' => 'uid'), * 'table' => 'node_revision',
* 'columns' => array('vid' => 'vid'),
* ),
* 'node_author' => array(
* 'table' => 'users',
* 'columns' => array('uid' => 'uid'),
* ),
* ), * ),
* 'primary key' => array('nid'), * 'primary key' => array('nid'),
* ); * );
......
...@@ -80,7 +80,10 @@ function aggregator_schema() { ...@@ -80,7 +80,10 @@ function aggregator_schema() {
'fid' => array('fid'), 'fid' => array('fid'),
), ),
'foreign keys' => array( 'foreign keys' => array(
'cid' => array('aggregator_category' => 'cid'), 'aggregator_category' => array(
'table' => 'aggregator_category',
'columns' => array('cid' => 'cid'),
),
), ),
); );
...@@ -105,7 +108,10 @@ function aggregator_schema() { ...@@ -105,7 +108,10 @@ function aggregator_schema() {
'iid' => array('iid'), 'iid' => array('iid'),
), ),
'foreign keys' => array( 'foreign keys' => array(
'cid' => array('aggregator_category' => 'cid'), 'aggregator_category' => array(
'table' => 'aggregator_category',
'columns' => array('cid' => 'cid'),
),
), ),
); );
...@@ -264,7 +270,10 @@ function aggregator_schema() { ...@@ -264,7 +270,10 @@ function aggregator_schema() {
'fid' => array('fid'), 'fid' => array('fid'),
), ),
'foreign keys' => array( 'foreign keys' => array(
'fid' => array('aggregator_feed' => 'fid'), 'aggregator_feed' => array(
'table' => 'aggregator_feed',
'columns' => array('fid' => 'fid'),
),
), ),
); );
......
...@@ -456,8 +456,14 @@ function comment_schema() { ...@@ -456,8 +456,14 @@ function comment_schema() {
), ),
'primary key' => array('cid'), 'primary key' => array('cid'),
'foreign keys' => array( 'foreign keys' => array(
'nid' => array('node' => 'nid'), 'comment_node' => array(
'uid' => array('users' => 'uid'), 'table' => 'node',
'columns' => array('nid' => 'nid'),
),
'comment_author' => array(
'table' => 'users',
'columns' => array('uid' => 'uid'),
),
), ),
); );
...@@ -510,8 +516,16 @@ function comment_schema() { ...@@ -510,8 +516,16 @@ function comment_schema() {
'last_comment_uid' => array('last_comment_uid'), 'last_comment_uid' => array('last_comment_uid'),
), ),
'foreign keys' => array( 'foreign keys' => array(
'nid' => array('node' => 'nid'), 'statistics_node' => array(
'last_comment_uid' => array('users' => 'uid'), 'table' => 'node',
'columns' => array('nid' => 'nid'),
),
'last_comment_author' => array(
'table' => 'users',
'columns' => array(
'last_comment_uid' => 'uid',
),
),
), ),
); );
......
...@@ -153,8 +153,13 @@ function forum_schema() { ...@@ -153,8 +153,13 @@ function forum_schema() {
), ),
'primary key' => array('vid'), 'primary key' => array('vid'),
'foreign keys' => array( 'foreign keys' => array(
'nid' => array('node' => 'nid'), 'forum_node' => array(
'vid' => array('node' => 'vid'), 'table' => 'node',
'columns' => array(
'nid' => 'nid',
'vid' => 'vid',
),
),
), ),
); );
...@@ -214,8 +219,16 @@ function forum_schema() { ...@@ -214,8 +219,16 @@ function forum_schema() {
'forum_topics' => array('tid', 'sticky', 'last_comment_timestamp'), 'forum_topics' => array('tid', 'sticky', 'last_comment_timestamp'),
), ),
'foreign keys' => array( 'foreign keys' => array(
'node' => 'nid', 'tracked_node' => array(
'taxonomy_term_data' => 'tid', 'table' => 'node',
'columns' => array('nid' => 'nid'),
),
'term' => array(
'table' => 'taxonomy_term_data',
'columns' => array(
'tid' => 'tid',
),
),
), ),
); );
...@@ -291,8 +304,16 @@ function forum_update_7001() { ...@@ -291,8 +304,16 @@ function forum_update_7001() {
'forum_topics' => array('tid', 'sticky', 'last_comment_timestamp'), 'forum_topics' => array('tid', 'sticky', 'last_comment_timestamp'),
), ),
'foreign keys' => array( 'foreign keys' => array(
'node' => 'nid', 'tracked_node' => array(
'taxonomy_term_data' => 'tid', 'table' => 'node',
'columns' => array('nid' => 'nid'),
),
'term' => array(
'table' => 'taxonomy_term_data',
'columns' => array(
'tid' => 'tid',
),
),
), ),
); );
db_create_table('forum_index', $forum_index); db_create_table('forum_index', $forum_index);
......
...@@ -98,7 +98,10 @@ function image_schema() { ...@@ -98,7 +98,10 @@ function image_schema() {
'weight' => array('weight'), 'weight' => array('weight'),
), ),
'foreign keys' => array( 'foreign keys' => array(
'isid' => array('image_styles' => 'isid'), 'image_style' => array(
'table' => 'image_styles',
'columns' => array('isid' => 'isid'),
),
), ),
); );
...@@ -180,7 +183,10 @@ function image_update_7000() { ...@@ -180,7 +183,10 @@ function image_update_7000() {
'weight' => array('weight'), 'weight' => array('weight'),
), ),
'foreign keys' => array( 'foreign keys' => array(
'isid' => array('image_styles' => 'isid'), 'image_style' => array(
'table' => 'image_styles',
'columns' => array('isid' => 'isid'),
),
), ),
); );
......
...@@ -335,7 +335,10 @@ function locale_schema() { ...@@ -335,7 +335,10 @@ function locale_schema() {
), ),
'primary key' => array('language', 'lid', 'plural'), 'primary key' => array('language', 'lid', 'plural'),
'foreign keys' => array( 'foreign keys' => array(
'lid' => array('locales_source' => 'lid'), 'locales_source' => array(
'table' => 'locales_source',
'columns' => array('lid' => 'lid'),
),
), ),
'indexes' => array( 'indexes' => array(
'lid' => array('lid'), 'lid' => array('lid'),
......
...@@ -118,8 +118,14 @@ function node_schema() { ...@@ -118,8 +118,14 @@ function node_schema() {
'vid' => array('vid'), 'vid' => array('vid'),
), ),
'foreign keys' => array( 'foreign keys' => array(
'vid' => array('node_revision' => 'vid'), 'node_revision' => array(
'uid' => array('users' => 'uid'), 'table' => 'node_revision',
'columns' => array('vid' => 'vid'),
),
'node_author' => array(
'table' => 'users',
'columns' => array('uid' => 'uid'),
),
), ),
'primary key' => array('nid'), 'primary key' => array('nid'),
); );
...@@ -174,7 +180,12 @@ function node_schema() { ...@@ -174,7 +180,12 @@ function node_schema() {
), ),
), ),
'primary key' => array('nid', 'gid', 'realm'), 'primary key' => array('nid', 'gid', 'realm'),
'foreign keys' => array('node' => 'nid'), 'foreign keys' => array(
'affected_node' => array(
'table' => 'node',
'columns' => array('nid' => 'nid'),
),
),
); );
$schema['node_revision'] = array( $schema['node_revision'] = array(
...@@ -249,8 +260,14 @@ function node_schema() { ...@@ -249,8 +260,14 @@ function node_schema() {
), ),
'primary key' => array('vid'), 'primary key' => array('vid'),
'foreign keys' => array( 'foreign keys' => array(
'node' => 'nid', 'versioned_node' => array(
'users' => 'uid' 'table' => 'node',
'columns' => array('nid' => 'nid'),
),
'version_author' => array(
'table' => 'users',
'columns' => array('uid' => 'uid'),
),
), ),
); );
......
...@@ -36,7 +36,10 @@ function poll_schema() { ...@@ -36,7 +36,10 @@ function poll_schema() {
), ),
'primary key' => array('nid'), 'primary key' => array('nid'),
'foreign keys' => array( 'foreign keys' => array(
'nid' => array('node' => 'nid'), 'poll_node' => array(
'table' => 'node',
'columns' => array('nid' => 'nid'),
),
), ),
); );
...@@ -82,7 +85,10 @@ function poll_schema() { ...@@ -82,7 +85,10 @@ function poll_schema() {
), ),
'primary key' => array('chid'), 'primary key' => array('chid'),
'foreign keys' => array( 'foreign keys' => array(
'nid' => array('node' => 'nid'), 'choice_node' => array(
'table' => 'node',
'columns' => array('nid' => 'nid'),
),
), ),
); );
...@@ -124,8 +130,14 @@ function poll_schema() { ...@@ -124,8 +130,14 @@ function poll_schema() {
), ),
'primary key' => array('nid', 'uid', 'hostname'), 'primary key' => array('nid', 'uid', 'hostname'),
'foreign keys' => array( 'foreign keys' => array(
'nid' => array('node' => 'nid'), 'poll_node' => array(
'uid' => array('users' => 'uid'), 'table' => 'node',
'columns' => array('nid' => 'nid'),
),
'voter' => array(
'table' => 'users',
'columns' => array('uid' => 'uid'),
),
), ),
'indexes' => array( 'indexes' => array(
'chid' => array('chid'), 'chid' => array('chid'),
......
...@@ -138,8 +138,14 @@ function profile_schema() { ...@@ -138,8 +138,14 @@ function profile_schema() {
'fid' => array('fid'), 'fid' => array('fid'),
), ),
'foreign keys' => array( 'foreign keys' => array(
'fid' => array('profile_field' => 'fid'), 'profile_field' => array(
'uid' => array('users' => 'uid'), 'table' => 'profile_field',
'columns' => array('fid' => 'fid'),
),
'profile_user' => array(
'table' => 'users',
'columns' => array('uid' => 'uid'),
),
), ),
); );
......
...@@ -85,8 +85,13 @@ function search_schema() { ...@@ -85,8 +85,13 @@ function search_schema() {
'sid_type' => array('sid', 'type'), 'sid_type' => array('sid', 'type'),
), ),
'foreign keys' => array( 'foreign keys' => array(
'sid' => array('search_dataset' => 'sid'), 'search_dataset' => array(
'type' => array('search_dataset' => 'type'), 'table' => 'search_dataset',
'columns' => array(
'sid' => 'sid',
'type' => 'type',
),
),
), ),
'primary key' => array('word', 'sid', 'type'), 'primary key' => array('word', 'sid', 'type'),
); );
......
...@@ -63,7 +63,10 @@ function shortcut_schema() { ...@@ -63,7 +63,10 @@ function shortcut_schema() {
), ),
'primary key' => array('set_name'), 'primary key' => array('set_name'),
'foreign keys' => array( 'foreign keys' => array(
'set_name' => array('menu_links' => 'menu_name'), 'menu_name' => array(
'table' => 'menu_links',
'columns' => array('set_name' => 'menu_name'),
),
), ),
); );
...@@ -90,8 +93,14 @@ function shortcut_schema() { ...@@ -90,8 +93,14 @@ function shortcut_schema() {
'set_name' => array('set_name'), 'set_name' => array('set_name'),
), ),
'foreign keys' => array( 'foreign keys' => array(
'uid' => array('users' => 'uid'), 'set_user' => array(
'set_name' => array('shortcut_set' => 'set_name'), 'table' => 'users',
'columns' => array('uid' => 'uid'),
),
'set_name' => array(
'table' => 'shortcut_set',
'columns' => array('set_name' => 'set_name'),
),
), ),
); );
......
...@@ -90,7 +90,10 @@ function statistics_schema() { ...@@ -90,7 +90,10 @@ function statistics_schema() {
), ),
'primary key' => array('aid'), 'primary key' => array('aid'),
'foreign keys' => array( 'foreign keys' => array(
'uid' => array('users' => 'uid'), 'visitor' => array(
'table' => 'users',
'columns' => array('uid' => 'uid'),
),
), ),
); );
......
...@@ -2566,6 +2566,16 @@ function hook_schema() { ...@@ -2566,6 +2566,16 @@ function hook_schema() {
'nid_vid' => array('nid', 'vid'), 'nid_vid' => array('nid', 'vid'),
'vid' => array('vid') 'vid' => array('vid')
), ),
'foreign keys' => array(
'node_revision' => array(
'table' => 'node_revision',
'columns' => array('vid' => 'vid'),
),
'node_author' => array(
'table' => 'users',
'columns' => array('uid' => 'uid')
),
),
'primary key' => array('nid'), 'primary key' => array('nid'),
); );
return $schema; return $schema;
......
...@@ -831,7 +831,10 @@ function system_schema() { ...@@ -831,7 +831,10 @@ function system_schema() {
), ),
'primary key' => array('fid'), 'primary key' => array('fid'),
'foreign keys' => array( 'foreign keys' => array(
'uid' => array('users' => 'uid'), 'file_owner' => array(
'table' => 'users',
'columns' => array('uid' => 'uid'),
),
), ),
); );
...@@ -1508,7 +1511,10 @@ function system_schema() { ...@@ -1508,7 +1511,10 @@ function system_schema() {
'ssid' => array('ssid'), 'ssid' => array('ssid'),
), ),
'foreign keys' => array( 'foreign keys' => array(
'uid' => array('users' => 'uid'), 'session_user' => array(
'table' => 'users',
'columns' => array('uid' => 'uid'),
),
), ),
); );
......
...@@ -66,7 +66,10 @@ function taxonomy_schema() { ...@@ -66,7 +66,10 @@ function taxonomy_schema() {
), ),
'primary key' => array('tid'), 'primary key' => array('tid'),
'foreign keys' => array( 'foreign keys' => array(
'vid' => array('taxonomy_vocabulary' => 'vid'), 'vocabulary' => array(
'table' => 'taxonomy_vocabulary',
'columns' => array('vid' => 'vid'),
),
), ),
'indexes' => array( 'indexes' => array(
'taxonomy_tree' => array('vid', 'weight', 'name'), 'taxonomy_tree' => array('vid', 'weight', 'name'),
...@@ -97,7 +100,10 @@ function taxonomy_schema() { ...@@ -97,7 +100,10 @@ function taxonomy_schema() {
'parent' => array('parent'), 'parent' => array('parent'),
), ),
'foreign keys' => array( 'foreign keys' => array(
'tid' => array('taxonomy_term_data' => 'tid'), 'taxonomy_term_data' => array(
'table' => 'taxonomy_term_data',
'columns' => array('tid' => 'tid'),
),
), ),
'primary key' => array('tid', 'parent'), 'primary key' => array('tid', 'parent'),
); );
...@@ -201,8 +207,14 @@ function taxonomy_schema() { ...@@ -201,8 +207,14 @@ function taxonomy_schema() {
'nid' => array('nid'), 'nid' => array('nid'),
), ),
'foreign keys' => array( 'foreign keys' => array(
'node' => 'nid', 'tracked_node' => array(
'taxonomy_term_data' => 'tid', 'table' => 'node',
'columns' => array('nid' => 'nid'),
),
'term' => array(
'table' => 'taxonomy_term_data',
'columns' => array('tid' => 'tid'),
),
), ),
); );
...@@ -328,8 +340,14 @@ function taxonomy_update_7004() { ...@@ -328,8 +340,14 @@ function taxonomy_update_7004() {
'nid' => array('nid'), 'nid' => array('nid'),
), ),
'foreign keys' => array( 'foreign keys' => array(
'node' => 'nid', 'tracked_node' => array(
'taxonomy_term_data' => 'tid', 'table' => 'node',
'columns' => array('nid' => 'nid'),
),
'term' => array(
'table' => 'taxonomy_term_data',
'columns' => array('tid' => 'tid'),
),
), ),
); );
db_create_table('taxonomy_index', $taxonomy_index); db_create_table('taxonomy_index', $taxonomy_index);
......
...@@ -56,7 +56,10 @@ function tracker_schema() { ...@@ -56,7 +56,10 @@ function tracker_schema() {
), ),
'primary key' => array('nid'), 'primary key' => array('nid'),
'foreign keys' => array( 'foreign keys' => array(
'node' => 'nid', 'tracked_node' => array(
'table' => 'node',
'columns' => array('nid' => 'nid'),
),
), ),
); );
...@@ -96,8 +99,14 @@ function tracker_schema() { ...@@ -96,8 +99,14 @@ function tracker_schema() {
), ),
'primary key' => array('nid', 'uid'), 'primary key' => array('nid', 'uid'),
'foreign keys' => array( 'foreign keys' => array(
'node' => 'nid', 'tracked_node' => array(
'users' => 'uid', 'table' => 'node',
'columns' => array('nid' => 'nid'),
),
'tracked_user' => array(
'table' => 'users',
'columns' => array('uid' => 'uid'),
),
), ),
); );
...@@ -143,7 +152,10 @@ function tracker_update_7000() { ...@@ -143,7 +152,10 @@ function tracker_update_7000() {
), ),
'primary key' => array('nid'), 'primary key' => array('nid'),
'foreign keys' => array( 'foreign keys' => array(
'node' => 'nid', 'tracked_node' => array(
'table' => 'node',
'columns' => array('nid' => 'nid'),
),
),