<?php

/**
 * Implementation of hook_install().
 */
function eolapi_specimen_install() {
  $field = array(
    'type' => 'varchar',
    'length' => 255,
    'default' => '',
    'initial' => '',
  );

  // Create Index.
  $keys['indexes'] = array(
    'catalogue_number' => array('catalogue_number'),
  );

  db_add_field('eolapi', 'catalogue_number', $field, $keys);
  db_add_field('eolapi_revision', 'catalogue_number', $field, $keys);

  $keys['indexes'] = array(
    'specimen_identifier' => array('specimen_identifier'),
  );

  db_add_field('eolapi', 'specimen_identifier', $field, $keys);
  db_add_field('eolapi_revision', 'specimen_identifier', $field, $keys);
}


/**
 * Implementation of hook_uninstall().
 */
function eolapi_specimen_uninstall() {
  db_drop_index('eolapi', 'catalogue_number');
  db_drop_index('eolapi_revision', 'catalogue_number');
  db_drop_field('eolapi', 'catalogue_number');
  db_drop_field('eolapi_revision', 'catalogue_number');

  db_drop_index('eolapi', 'specimen_identifier');
  db_drop_index('eolapi_revision', 'specimen_identifier');
  db_drop_field('eolapi', 'specimen_identifier');
  db_drop_field('eolapi_revision', 'specimen_identifier');
}

/**
 * Implementation of hook_schema().
 */
function eolapi_specimen_schema(){
  return array(
    'eolapi_specimen_batch' => array(
      'fields' => array(
        'esid' => array(
          'description' => 'Primary key',
          'type' => 'serial',
          'unsigned' => TRUE,
          'not null' => TRUE
        ),
        'tid' => array(
          'description' => 'Taxa term ID',
          'type' => 'int',
          'unsigned' => TRUE,
          'not null' => TRUE,
          'default' => 0
        ),
        'term_name' => array(
          'description' => 'Taxa term name',
          'type' => 'varchar',
          'length' => 255,
          'not null' => TRUE,
          'default' => ''
        ),
        'info' => array(
          'description' => 'Serialized PHP data',
          'type' => 'text',
          'size' => 'big',
          'not null' => TRUE
        )
      ),
      'indexes' => array(
        'esid' => array(
          'esid'
        ),
      ), // FIXME - Add unique type/label key.
      'primary key' => array(
        'esid'
      )
    )
  );
}