<?php
// $Id$

/**
 * @file
 * Install, update and uninstall functions for the field_sql_storage module.
 */

/**
 * Implements hook_schema().
 */
function field_sql_storage_schema() {
  $schema = array();

  // Static (meta-data) tables.
  $schema['field_config_entity_type'] = array(
    'fields' => array(
      'etid' => array(
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'description' => 'The unique id for this entity type',
      ),
      'type' => array(
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
        'description' => 'An entity type',
      ),
    ),
    'primary key' => array('etid'),
    'unique keys' => array('type' => array('type')),
  );

  // Dynamic (data) tables.
  if (db_table_exists('field_config')) {
    $fields = field_read_fields(array(), array('include_deleted' => TRUE, 'include_inactive' => TRUE));
    drupal_load('module', 'field_sql_storage');
    foreach ($fields as $field) {
      if ($field['storage']['type'] == 'field_sql_storage') {
        $schema += _field_sql_storage_schema($field);
      }
    }
  }
  return $schema;
}
