<?php
/**
 * @file
 * Contains functions used to install/uninstall tripal.
 */

/**
 * Implementation of hook_install().
 *
 * @ingroup tripal
 */
function tripal_install() {

}
/**
 * Implementation of hook_schema().
 *
 * @ingroup tripal
 */
function tripal_schema() {
  $schema = array();
  $schema['tripal_jobs'] = array(
    'fields' => array(
      'job_id' => array(
        'type' => 'serial',
        'unsigned' => TRUE,
        'not NULL' => TRUE
      ),
      'uid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not NULL' => TRUE,
        'description' => 'The Drupal userid of the submitee'
      ),
      'job_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'
      ),
      'callback' => array(
        'type' => 'varchar',
        'length' => 255,
        'not NULL' => TRUE
      ),
      'arguments' => array(
        'type' => 'text',
        'size' => 'normal',
        'not NULL' => FALSE
      ),
      'progress' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'default' => 0,
        'not NULL' => FALSE,
        'description' => 'a value from 0 to 100 indicating percent complete'
      ),
      'status' => array(
        'type' => 'varchar',
        'length' => 50,
        'not NULL' => TRUE
      ),
      'submit_date' => array(
        'type' => 'int',
        'not NULL' => TRUE,
        'description' => 'UNIX integer submit time'
      ),
      'start_time' => array(
        'type' => 'int',
        'not NULL' => FALSE,
        'description' => 'UNIX integer start time'
      ),
      'end_time' => array(
        'type' => 'int',
        'not NULL' => FALSE,
        'description' => 'UNIX integer end time'
      ),
      'error_msg' => array(
        'type' => 'text',
        'size' => 'normal',
        'not NULL' => FALSE
      ),
      'pid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not NULL' => FALSE,
        'description' => 'The process id for the job'
      ),
      'priority' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not NULL' => TRUE,
        'default' => '0',
        'description' => 'The job priority'
      ),
      'mlock' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not NULL' => FALSE,
        'description' => 'If set to 1 then all jobs for the module are held until this one finishes'
      ),
      'lock' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not NULL' => FALSE,
        'description' => 'If set to 1 then all jobs are held until this one finishes'
      ),
    ),
    'indexes' => array(
      'job_id' => array('job_id'),
      'job_name' => array('job_name')
    ),
    'primary key' => array('job_id'),
  );

  $schema['tripal_token_formats'] = array(
    'fields' => array(
      'tripal_format_id' => array(
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE
      ),
      'content_type' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE
      ),
      'application' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE
      ),
      'format' => array(
        'type' => 'text',
        'not null' => TRUE
      ),
      'tokens' => array(
        'type' => 'text',
        'not null' => TRUE
      ),
    ),
    'unique keys' => array(
      'type_application' => array('content_type', 'application'),
    ),
    'primary key' => array('tripal_format_id'),
  );


  $schema['tripal_variables'] = array(
    'description' => 'This table houses a list of unique variable names that ' .
      'can be used in the tripal_node_variables table.',
    'fields' => array(
      'variable_id' => array (
        'type' => 'serial',
        'not null' => TRUE,
      ),
      'name' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ),
      'description' => array(
        'type' => 'text',
        'not null' => TRUE,
      ),
    ),
    'primary key' => array (
        0 => 'variable_id',
    ),
    'unique keys' => array (
      'tripal_variables_c1' => array (
        0 => 'name',
      ),
    ),
    'indexes' => array (
      'tripal_variable_names_idx1' => array (
        0 => 'variable_id',
      ),
    ),
  );

  return $schema;
}
