|
@@ -182,6 +182,55 @@ function tripal_chado_schema() {
|
|
|
// Map cvterm usage to chado tables
|
|
|
$schema['chado_cvterm_mapping'] = tripal_chado_chado_cvterm_mapping_schema();
|
|
|
|
|
|
+ // When a chado Tripal content type is created, a linking table is also created to
|
|
|
+ // link the entity to it's record in chado (@see tripal_chado_bundle_create() ).
|
|
|
+ // This table is created via db_create_table() but in order to expose it to
|
|
|
+ // the Drupal Schema API, we also need to define each one here.
|
|
|
+ if (db_table_exists('chado_bundle')) {
|
|
|
+ $resource = db_query('SELECT tb.name FROM chado_bundle cb LEFT JOIN tripal_bundle tb ON tb.id=cb.bundle_id');
|
|
|
+ foreach ($resource as $r) {
|
|
|
+ $bundle_name = $r->name;
|
|
|
+ // This makes an assumption about the name of the linking table.
|
|
|
+ // @todo: Switch to tripal_chado_get_bundle_entity_table($bundle).
|
|
|
+ $chado_entity_table = 'chado_' . $bundle_name;
|
|
|
+ $schema[$chado_entity_table] = array(
|
|
|
+ 'description' => 'The linker table that associates TripalEntities with Chado records for entities of type ' . $bundle_name . '.',
|
|
|
+ 'fields' => array(
|
|
|
+ 'mapping_id' => array(
|
|
|
+ 'type' => 'serial',
|
|
|
+ 'not null' => TRUE
|
|
|
+ ),
|
|
|
+ 'entity_id' => array(
|
|
|
+ 'description' => 'The unique entity id.',
|
|
|
+ 'type' => 'int',
|
|
|
+ 'not null' => TRUE,
|
|
|
+ ),
|
|
|
+ 'record_id' => array(
|
|
|
+ 'description' => 'The unique numerical identifier for the record that this entity is associated with (e.g. feature_id, stock_id, library_id, etc.).',
|
|
|
+ 'type' => 'int',
|
|
|
+ 'not null' => TRUE,
|
|
|
+ ),
|
|
|
+ 'nid' => array(
|
|
|
+ 'description' => 'Optional. For linking nid to the entity when migrating Tripal v2 content',
|
|
|
+ 'type' => 'int',
|
|
|
+ )
|
|
|
+ ),
|
|
|
+ 'primary key' => array(
|
|
|
+ 'mapping_id',
|
|
|
+ ),
|
|
|
+ 'indexes' => array(
|
|
|
+ 'record_id' => array('record_id'),
|
|
|
+ 'entity_id' => array('entity_id'),
|
|
|
+ 'nid' => array('nid'),
|
|
|
+ ),
|
|
|
+ 'unique keys' => array(
|
|
|
+ 'table_record' => array('record_id'),
|
|
|
+ 'entity_id' => array('entity_id'),
|
|
|
+ ),
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
return $schema;
|
|
|
}
|
|
|
|