123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729 |
- <?php
- function tripal_chado_install() {
- // // The foreign key specification doesn't really add one to the
- // // Drupal schema, it is just used internally, but we want one.
- // db_query('
- // ALTER TABLE {tripal_custom_tables}
- // ADD CONSTRAINT tripal_custom_tables_fk1
- // FOREIGN KEY (mview_id) REFERENCES {tripal_mviews} (mview_id)
- // ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED
- // ');
- if (chado_is_installed()) {
- // For an upgraded site we need to move some vocabulary terms over
- // to the new 'local' vocabulary:
- tripal_insert_db(array(
- 'name' => 'local',
- 'description' => variable_get('site_name', 'This site.'),
- ));
- // Move the library properties out of the tripal database and into the
- // local database.
- $sql = "
- UPDATE {dbxref}
- SET db_id = (SELECT db_id FROM {db} WHERE name = 'local')
- WHERE dbxref_id IN (
- SELECT DISTINCT CVT.dbxref_id
- FROM {cvterm} CVT
- INNER JOIN {cv} CV ON CV.cv_id = CVT.cv_id
- WHERE CV.name IN (
- 'library_property',
- 'library_type',
- 'project_property',
- 'nd_experiment_types',
- 'nd_geolocation_property',
- 'tripal_analysis'
- )
- )
- ";
- chado_query($sql);
- }
- }
- /**
- * Implementation of hook_uninstall().
- *
- * @ingroup tripal
- */
- function tripal_chado_uninstall() {
- // // Drop the foreign key between tripal_custom_tables and tripal_mviews
- // // so that Drupal can then drop the tables
- // db_query('
- // ALTER TABLE {tripal_custom_tables}
- // DROP CONSTRAINT tripal_custom_tables_fk1 CASCADE
- // ');
- variable_set('tripal_chado_is_prepared', FALSE);
- }
- function tripal_chado_chado_semweb_schema(){
- return array(
- 'fields' => array(
- 'chado_semweb_id' => array(
- 'type' => 'serial',
- 'not null' => TRUE
- ),
- 'chado_table' => array(
- 'type' => 'varchar',
- 'length ' => 128,
- 'not null' => TRUE
- ),
- 'chado_column' => array(
- 'type' => 'text',
- 'length ' => 128,
- 'not null' => TRUE
- ),
- 'cvterm_id' => array(
- 'type' => 'int',
- ),
- ),
- 'primary key' => array(
- 0 => 'chado_semweb_id',
- ),
- 'indexes' => array(
- 'chado_semweb_id_idx1' => array('cvterm_id'),
- 'chado_semweb_id_idx2' => array('chado_column'),
- 'chado_semweb_id_idx3' => array('chado_table'),
- ),
- 'unique keys' => array(
- 'chado_semweb_uq1' => array('chado_table', 'chado_column'),
- ),
- );
- }
- /**
- * Table definition for the tripal_cv_obo table
- * @param $schema
- */
- function tripal_chado_tripal_cv_obo_schema() {
- return array(
- 'fields' => array(
- 'obo_id' => array(
- 'type' => 'serial',
- 'unsigned' => TRUE,
- 'not null' => TRUE
- ),
- 'name' => array(
- 'type' => 'varchar',
- 'length' => 255
- ),
- 'path' => array(
- 'type' => 'varchar',
- 'length' => 1024
- ),
- ),
- 'indexes' => array(
- 'tripal_cv_obo_idx1' => array('obo_id'),
- ),
- 'primary key' => array('obo_id'),
- );
- }
- /**
- *
- */
- function tripal_chado_enable() {
- // If Tripal v2 is already installed, then when the module is first enabled
- // after an upgade, the installation of this module will try and recreate
- // some of the tables created with tripal_core and the installation will fail.
- // Therefore, the tables were temporarily moved out of the way to preserve
- // the data. Now we'll move them back.
- tripal_chado_upgrade_v2_v3_enable();
- }
- /**
- * Implements hook_schema().
- */
- function tripal_chado_schema() {
- // If Tripal v2 is already installed, then when the module is first enabled
- // after an upgade, the installation of this module will try and recreate
- // some of the tables created with tripal_core and the installation will fail.
- // Therefore, we need to temporarily move those tables out of the way, let
- // the module install and then move them back.
- $migrated = variable_get('tripal_v2_upgrade_v3_check_chado', FALSE);
- if (!$migrated) {
- try {
- tripal_chado_upgrade_v2_v3_pre_enable();
- variable_set('tripal_v2_upgrade_v3_check_chado', TRUE);
- }
- catch(Exception $e) {
- watchdog_exception('tripal_chado', $e);
- }
- }
- // Links TripalEntity entities to the chado record.
- $schema['chado_entity'] = tripal_chado_chado_entity_schema();
- $schema['chado_bundle'] = tripal_chado_chado_bundle_schema();
- $schema['chado_semweb'] = tripal_chado_chado_semweb_schema();
- $schema['tripal_mviews'] = tripal_chado_tripal_mviews_schema();
- $schema['tripal_custom_tables'] = tripal_chado_tripal_custom_tables_schema();
- $schema['tripal_cv_obo'] = tripal_chado_tripal_cv_obo_schema();
- $schema['tripal_pub_import'] = tripal_chado_tripal_pub_import_schema();
- // if this module is already installed and enabled, then we want to provide
- // the schemas for all of the custom tables. This will allow Views to
- // see the schemas. We check if the module is installed because during
- // installation we don't want to make these custom tables available as we don't
- // want them created in the Drupal database. The custom tables go in the
- // Chado database.
- if (db_table_exists('tripal_custom_tables')) {
- $sql = 'SELECT * FROM {tripal_custom_tables}';
- $results = db_query($sql);
- foreach ($results as $custom) {
- $schema[$custom->table_name] = unserialize($custom->schema);
- }
- }
- // Map cvterm usage to chado tables
- $schema['chado_cvterm_mapping'] = tripal_chado_chado_cvterm_mapping_schema();
- return $schema;
- }
- /**
- * This function should be executed only one time during upgrade of v2 to v3.
- */
- function tripal_chado_upgrade_v2_v3_pre_enable() {
- // If Tripal v2 is already installed, then when the module is first enabled
- // after an upgade, the installation of this module will try and recreate
- // some of the tables created with tripal_core and the installation will fail.
- // Therefore, we need to temporarily move those tables out of the way, let
- // the module install and then move them back.
- if (db_table_exists('tripal_mviews')) {
- // Move the tripal_mviews table out of the way.
- $sql = "ALTER TABLE tripal_mviews RENAME TO tripal_mviews2";
- db_query($sql);
- if (db_query("SELECT 1 FROM pg_indexes WHERE indexname = 'tripal_mviews_mv_name_key'")->fetchField()) {
- $sql = "ALTER INDEX tripal_mviews_mv_name_key RENAME TO tripal_mviews_mv_name_key2";
- }
- else {
- $sql = "CREATE UNIQUE INDEX tripal_mviews_mv_name_key2 ON tripal_mviews2 USING btree (name)";
- }
- db_query($sql);
- if (db_query("SELECT 1 FROM pg_indexes WHERE indexname = 'tripal_mviews_mv_table_key'")->fetchField()) {
- $sql = "ALTER INDEX tripal_mviews_mv_table_key RENAME TO tripal_mviews_mv_table_key2";
- }
- else {
- $sql = "CREATE UNIQUE INDEX tripal_mviews_mv_table_key2 ON tripal_mviews2 USING btree (mv_table)";
- }
- db_query($sql);
- if (db_query("SELECT 1 FROM pg_indexes WHERE indexname = 'tripal_mviews_mview_id_idx'")->fetchField()) {
- $sql = "ALTER INDEX tripal_mviews_mview_id_idx RENAME TO tripal_mviews_mview_id_idx2";
- }
- else {
- $sql = "CREATE INDEX tripal_mviews_mview_id_idx2 ON tripal_mviews2 USING btree (mview_id)";
- }
- db_query($sql);
- if (db_query("SELECT 1 FROM pg_indexes WHERE indexname = 'tripal_mviews_pkey'")->fetchField()) {
- $sql = "ALTER INDEX tripal_mviews_pkey RENAME TO tripal_mviews_pkey2";
- }
- else {
- $sql = "CREATE UNIQUE INDEX tripal_mviews_pkey2 ON tripal_mviews2 USING btree (mview_id)";
- }
- db_query($sql);
- }
- if (db_table_exists('tripal_custom_tables')) {
- // Move the tripal_custom_tables table out of the way.
- $sql = "ALTER TABLE tripal_custom_tables RENAME TO tripal_custom_tables2";
- db_query($sql);
- if (db_query("SELECT 1 FROM pg_indexes WHERE indexname = 'tripal_custom_tables_pkey'")->fetchField()) {
- $sql = "ALTER INDEX tripal_custom_tables_pkey RENAME TO tripal_custom_tables_pkey2";
- }
- else {
- $sql = "CREATE UNIQUE INDEX tripal_custom_tables_pkey2 ON tripal_custom_tables2 USING btree (table_id)";
- }
- db_query($sql);
- if (db_query("SELECT 1 FROM pg_indexes WHERE indexname = 'tripal_custom_tables_table_id_idx'")->fetchField()) {
- $sql = "ALTER INDEX tripal_custom_tables_table_id_idx RENAME TO tripal_custom_tables_table_id_idx2";
- }
- else {
- $sql = "CREATE INDEX tripal_custom_tables_table_id_idx2 ON tripal_custom_tables2 USING btree (table_id)";
- }
- db_query($sql);
- }
- if (db_table_exists('tripal_cv_obo')) {
- // Move the tripal_cv_obo table out of the way.
- $sql = "ALTER TABLE tripal_cv_obo RENAME TO tripal_cv_obo2";
- db_query($sql);
- if (db_query("SELECT 1 FROM pg_indexes WHERE indexname = 'tripal_cv_obo_obo_id_idx'")->fetchField()) {
- $sql = "ALTER INDEX tripal_cv_obo_obo_id_idx RENAME TO tripal_cv_obo_obo_id_idx2";
- }
- else {
- $sql = "CREATE INDEX tripal_cv_obo_obo_id_idx2 ON tripal_cv_obo2 USING btree (obo_id)";
- }
- db_query($sql);
- if (db_query("SELECT 1 FROM pg_indexes WHERE indexname = 'tripal_cv_obo_pkey'")->fetchField()) {
- $sql = "ALTER INDEX tripal_cv_obo_pkey RENAME TO tripal_cv_obo_pkey2";
- }
- else {
- $sql = "CREATE UNIQUE INDEX tripal_cv_obo_pkey2 ON tripal_cv_obo2 USING btree (obo_id)";
- }
- db_query($sql);
- }
- /* if (db_table_exists('tripal_cv_defaults')) {
- // Move the tripal_cv_defaults table out of the way.
- $sql = "ALTER TABLE tripal_cv_defaults RENAME TO tripal_cv_defaults2";
- db_query($sql);
- if (db_query("SELECT 1 FROM pg_indexes WHERE indexname = 'tripal_cv_defaults_pkey'")->fetchField()) {
- $sql = "ALTER INDEX tripal_cv_defaults_pkey RENAME TO tripal_cv_defaults_pkey2";
- }
- else {
- $sql = "CREATE UNIQUE INDEX tripal_cv_defaults_pkey2 ON tripal_cv_defaults2 USING btree (cv_default_id)";
- }
- db_query($sql);
- if (db_query("SELECT 1 FROM pg_indexes WHERE indexname = 'tripal_cv_defaults_tripal_cv_defaults_idx1_idx'")->fetchField()) {
- $sql = "ALTER INDEX tripal_cv_defaults_tripal_cv_defaults_idx1_idx RENAME TO tripal_cv_defaults_tripal_cv_defaults_idx1_idx2";
- }
- else {
- $sql = "CREATE INDEX tripal_cv_defaults_tripal_cv_defaults_idx1_idx2 ON tripal_cv_defaults2 USING btree (table_name, field_name)";
- }
- db_query($sql);
- if (db_query("SELECT 1 FROM pg_indexes WHERE indexname = 'tripal_cv_defaults_tripal_cv_defaults_unq1_key'")->fetchField()) {
- $sql = "ALTER INDEX tripal_cv_defaults_tripal_cv_defaults_unq1_key RENAME TO tripal_cv_defaults_tripal_cv_defaults_unq1_key2";
- }
- else {
- $sql = "CREATE UNIQUE INDEX tripal_cv_defaults_tripal_cv_defaults_unq1_key2 ON tripal_cv_defaults2 USING btree (table_name, field_name, cv_id)";
- }
- db_query($sql);
- } */
- if (db_table_exists('tripal_pub_import')) {
- // Move the tripal_pub_import table out of the way.
- $sql = "ALTER TABLE tripal_pub_import RENAME TO tripal_pub_import2";
- db_query($sql);
- if (db_query("SELECT 1 FROM pg_indexes WHERE indexname = 'tripal_pub_import_name_idx'")->fetchField()) {
- $sql = "ALTER INDEX tripal_pub_import_name_idx RENAME TO tripal_pub_import_name_idx2";
- }
- else {
- $sql = "CREATE INDEX tripal_pub_import_name_idx2 ON tripal_pub_import2 USING btree (name)";
- }
- db_query($sql);
- if (db_query("SELECT 1 FROM pg_indexes WHERE indexname = 'tripal_pub_import_pkey'")->fetchField()) {
- $sql = "ALTER INDEX tripal_pub_import_pkey RENAME TO tripal_pub_import_pkey2";
- }
- else {
- $sql = "CREATE UNIQUE INDEX tripal_pub_import_pkey2 ON tripal_pub_import2 USING btree (pub_import_id)";
- }
- db_query($sql);
- }
- }
- /**
- * This function should be executed only one time during upgrade of v2 to v3.
- */
- function tripal_chado_upgrade_v2_v3_enable() {
- // If Tripal v2 is already installed, the installation of this module
- // will try and recreate some of the tables created with tripal_core and the
- // installation will fail. Therefore, in the install we renamed it. Now
- // we want to move it back.
- if (db_table_exists('tripal_mviews2')) {
- // tripal_mviews
- $sql = "DROP TABLE tripal_mviews";
- db_query($sql);
- $sql = "ALTER TABLE tripal_mviews2 RENAME to tripal_mviews";
- db_query($sql);
- $sql = "ALTER INDEX tripal_mviews_mv_name_key2 RENAME TO tripal_mviews_mv_name_key";
- db_query($sql);
- $sql = "ALTER INDEX tripal_mviews_mv_table_key2 RENAME TO tripal_mviews_mv_table_key";
- db_query($sql);
- $sql = "ALTER INDEX tripal_mviews_mview_id_idx2 RENAME TO tripal_mviews_mview_id_idx";
- db_query($sql);
- $sql = "ALTER INDEX tripal_mviews_pkey2 RENAME TO tripal_mviews_pkey";
- db_query($sql);
- }
- // tripal_custom_tables
- if (db_table_exists('tripal_custom_tables2')) {
- $sql = "DROP TABLE tripal_custom_tables";
- db_query($sql);
- $sql = "ALTER TABLE tripal_custom_tables2 RENAME to tripal_custom_tables";
- db_query($sql);
- $sql = "ALTER INDEX tripal_custom_tables_pkey2 RENAME TO tripal_custom_tables_pkey";
- db_query($sql);
- $sql = "ALTER INDEX tripal_custom_tables_table_id_idx2 RENAME TO tripal_custom_tables_table_id_idx";
- db_query($sql);
- }
- // tripal_cv_obo
- if (db_table_exists('tripal_cv_obo2')) {
- $sql = "DROP TABLE tripal_cv_obo";
- db_query($sql);
- $sql = "ALTER TABLE tripal_cv_obo2 RENAME to tripal_cv_obo";
- db_query($sql);
- $sql = "ALTER INDEX tripal_cv_obo_obo_id_idx2 RENAME TO tripal_cv_obo_obo_id_idx";
- db_query($sql);
- $sql = "ALTER INDEX tripal_cv_obo_pkey2 RENAME TO tripal_cv_obo_pkey";
- db_query($sql);
- }
- // tripal_cv_defaults
- /* if (db_table_exists('tripal_cv_defaults2')) {
- $sql = "DROP TABLE tripal_cv_defaults";
- db_query($sql);
- $sql = "ALTER TABLE tripal_cv_defaults2 RENAME to tripal_cv_defaults";
- db_query($sql);
- $sql = "ALTER INDEX tripal_cv_defaults_pkey2 RENAME TO tripal_cv_defaults_pkey";
- db_query($sql);
- $sql = "ALTER INDEX tripal_cv_defaults_tripal_cv_defaults_idx1_idx2 RENAME TO tripal_cv_defaults_tripal_cv_defaults_idx1_idx";
- db_query($sql);
- $sql = "ALTER INDEX tripal_cv_defaults_tripal_cv_defaults_unq1_key2 RENAME TO tripal_cv_defaults_tripal_cv_defaults_unq1_key";
- db_query($sql);
- } */
- // tripal_pub_import
- if (db_table_exists('tripal_pub_import2')) {
- $sql = "DROP TABLE tripal_pub_import";
- db_query($sql);
- $sql = "ALTER TABLE tripal_pub_import2 RENAME to tripal_pub_import";
- db_query($sql);
- $sql = "ALTER INDEX tripal_pub_import_name_idx2 RENAME TO tripal_pub_import_name_idx";
- db_query($sql);
- $sql = "ALTER INDEX tripal_pub_import_pkey2 RENAME TO tripal_pub_import_pkey";
- db_query($sql);
- }
- }
- /**
- * @section
- * Schema Definitions.
- */
- /**
- * Implementation of hook_schema().
- *
- * @ingroup tripal_pub
- */
- function tripal_chado_tripal_pub_import_schema() {
- return array(
- 'fields' => array(
- 'pub_import_id' => array(
- 'type' => 'serial',
- 'not null' => TRUE
- ),
- 'name' => array(
- 'type' => 'varchar',
- 'length' => 255,
- 'not null' => TRUE
- ),
- 'criteria' => array(
- 'type' => 'text',
- 'size' => 'normal',
- 'not null' => TRUE,
- 'description' => 'Contains a serialized PHP array containing the search criteria'
- ),
- 'disabled' => array(
- 'type' => 'int',
- 'unsigned' => TRUE,
- 'not NULL' => TRUE,
- 'default' => 0
- ),
- 'do_contact' => array(
- 'type' => 'int',
- 'unsigned' => TRUE,
- 'not NULL' => TRUE,
- 'default' => 0
- ),
- ),
- 'primary key' => array('pub_import_id'),
- 'indexes' => array(
- 'name' => array('name')
- ),
- );
- }
- /**
- * Describes the Tripal Custom Tables (tripal_custom_tables) table
- * This keeps track of tables created by Tripal and stored in chado that may or may not
- * also be materialized views.
- *
- * @ingroup tripal
- */
- function tripal_chado_tripal_custom_tables_schema() {
- return array(
- 'fields' => array(
- 'table_id' => array(
- 'type' => 'serial',
- 'unsigned' => TRUE,
- 'not NULL' => TRUE
- ),
- 'table_name' => array(
- 'type' => 'varchar',
- 'length' => 255,
- 'not NULL' => TRUE
- ),
- 'schema' => array(
- 'type' => 'text',
- 'not NULL' => TRUE
- ),
- 'mview_id' => array(
- 'type' => 'int',
- 'not NULL' => FALSE
- )
- ),
- 'indexes' => array(
- 'table_id' => array('table_id'),
- ),
- 'primary key' => array('table_id'),
- 'foreign keys' => array(
- 'tripal_mviews' => array(
- 'table' => 'tripal_mviews',
- 'columns' => array(
- 'mview_id' => 'mview_id'
- ),
- ),
- ),
- );
- }
- /**
- * Describes the Tripal Materialized View (tripal_mviews) table
- * This table keeps track of all materialized views created by Tripal and stored in chado
- *
- * @ingroup tripal
- */
- function tripal_chado_tripal_mviews_schema() {
- return array(
- 'fields' => array(
- 'mview_id' => array(
- 'type' => 'serial',
- 'unsigned' => TRUE,
- 'not NULL' => TRUE
- ),
- 'name' => array(
- 'type' => 'varchar',
- 'length' => 255,
- 'not NULL' => TRUE
- ),
- 'modulename' => array(
- 'type' => 'varchar',
- 'length' => 50,
- 'not NULL' => TRUE,
- 'description' => 'The module name that provides the callback for this job'
- ),
- 'mv_table' => array(
- 'type' => 'varchar',
- 'length' => 128,
- 'not NULL' => FALSE
- ),
- 'mv_specs' => array(
- 'type' => 'text',
- 'size' => 'normal',
- 'not NULL' => FALSE
- ),
- 'mv_schema' => array(
- 'type' => 'text',
- 'size' => 'normal',
- 'not NULL' => FALSE
- ),
- 'indexed' => array(
- 'type' => 'text',
- 'size' => 'normal',
- 'not NULL' => FALSE
- ),
- 'query' => array(
- 'type' => 'text',
- 'size' => 'normal',
- 'not NULL' => TRUE
- ),
- 'special_index' => array(
- 'type' => 'text',
- 'size' => 'normal',
- 'not NULL' => FALSE
- ),
- 'last_update' => array(
- 'type' => 'int',
- 'not NULL' => FALSE,
- 'description' => 'UNIX integer time'
- ),
- 'status' => array(
- 'type' => 'text',
- 'size' => 'normal',
- 'not NULL' => FALSE
- ),
- 'comment' => array(
- 'type' => 'text',
- 'size' => 'normal',
- 'not NULL' => FALSE
- ),
- ),
- 'indexes' => array(
- 'mview_id' => array('mview_id')
- ),
- 'unique keys' => array(
- 'mv_table' => array('mv_table'),
- 'mv_name' => array('name'),
- ),
- 'primary key' => array('mview_id'),
- );
- }
- /**
- * Links Biological Data Entities to the chado "base" table the data is stored in.
- * This is where we would specify that a particular gene maps to the record in the
- * chado.feature table with a feature_id=2432;
- */
- function tripal_chado_chado_entity_schema() {
- $schema = array(
- 'description' => 'The linker table that associates an enitity from the public.tripal_entity table with a "base" record in Chado',
- 'fields' => array(
- 'chado_entity_id' => array(
- 'description' => 'The primary identifier for this table.',
- 'type' => 'serial',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- ),
- 'entity_id' => array(
- 'description' => 'The unique entity id.',
- 'type' => 'int',
- 'not null' => TRUE,
- ),
- 'data_table' => array(
- 'description' => 'The table in that this record belongs to',
- 'type' => 'varchar',
- 'length' => 128,
- 'not null' => TRUE,
- 'default' => '',
- ),
- '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',
- )
- ),
- 'indexes' => array(
- 'record_id' => array('record_id'),
- 'entity_id' => array('entity_id'),
- 'data_table' => array('data_table'),
- 'nid' => array('nid'),
- ),
- 'unique keys' => array(
- 'table_record' => array('data_table', 'record_id'),
- 'entity_id' => array('entity_id'),
- ),
- 'primary key' => array('chado_entity_id'),
- );
- return $schema;
- }
- /**
- * Links Biological Data Entities to the chado "base" table the data is stored in.
- * This is where we would specify that a particular gene maps to the record in the
- * chado.feature table with a feature_id=2432;
- */
- function tripal_chado_chado_bundle_schema() {
- $schema = array(
- 'description' => 'Describes how a bundle maps data to Chado',
- 'fields' => array(
- 'chado_bundle_id' => array(
- 'description' => 'The primary identifier for this table.',
- 'type' => 'serial',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- ),
- 'bundle_id' => array(
- 'description' => 'The unique entity id.',
- 'type' => 'int',
- 'not null' => TRUE,
- ),
- 'data_table' => array(
- 'description' => 'The table in Chado that this term services (e.g. feature, stock, library, etc.)',
- 'type' => 'varchar',
- 'length' => 128,
- 'not null' => TRUE,
- 'default' => '',
- ),
- 'type_linker_table' => array(
- 'description' => 'If a linker table (e.g. cvterm/prop) is needed to uniquely identify a content type then that table name is provided here.',
- 'type' => 'varchar',
- 'length' => 128,
- 'not null' => FALSE,
- 'default' => '',
- ),
- 'type_column' => array(
- 'description' => 'The column in the data table or linker table that distinguishes the data type. This must be in a foreign key relationship to the cvterm table.',
- 'type' => 'varchar',
- 'length' => 128,
- 'not null' => FALSE,
- 'default' => '',
- ),
- 'type_id' => array(
- 'description' => 'If a type_column is set then this is the cvterm_id of the data type that this bundle maps to.',
- 'type' => 'varchar',
- 'length' => 128,
- 'not null' => TRUE,
- 'default' => '',
- ),
- 'type_value' => array(
- 'description' => 'If a property table is used for a linker, then the value that should be matched to identify this content type is stored here.',
- 'type' => 'text',
- 'not null' => FALSE,
- 'default' => '',
- )
- ),
- 'indexes' => array(
- 'bundle_id' => array('bundle_id'),
- 'data_table' => array('data_table'),
- ),
- 'unique keys' => array(
- 'record' => array('bundle_id'),
- ),
- 'primary key' => array('chado_bundle_id'),
- );
- return $schema;
- }
- /**
- * Tripal cvterm mapping schema
- * Map cvterms to chado tables that use them
- */
- function tripal_chado_chado_cvterm_mapping_schema() {
- $schema = array (
- 'table' => 'chado_cvterm_mapping',
- 'fields' => array (
- 'mapping_id' => array(
- 'type' => 'serial',
- 'not null' => TRUE
- ),
- 'cvterm_id' => array (
- 'type' => 'int',
- 'not null' => TRUE
- ),
- 'chado_table' => array (
- 'type' => 'varchar',
- 'length' => 128,
- 'not null' => TRUE
- ),
- 'chado_field' => array (
- 'type' => 'varchar',
- 'length' => 128,
- 'not null' => FALSE
- ),
- ),
- 'primary key' => array (
- 0 => 'mapping_id'
- ),
- 'unique key' => array(
- 'cvterm_id',
- ),
- 'indexes' => array(
- 'tripal_cvterm2table_idx1' => array('cvterm_id'),
- 'tripal_cvterm2table_idx2' => array('chado_table'),
- 'tripal_cvterm2table_idx3' => array('chado_table', 'chado_field'),
- ),
- );
- return $schema;
- }
|