<?php

/**
 * @file
 * Bean UUID installation and schema hooks.
 */

/**
 * Implements hook_schema_alter().
 */
function bean_uuid_schema_alter(&$schema = array()) {
  module_load_include('install', 'uuid');
  $field = uuid_schema_field_definition();
  $schema['bean']['fields']['uuid'] = $field;
  $schema['bean_revision']['fields']['vuuid'] = $field;
}

/**
 * Implements hook_install().
 */
function bean_uuid_install() {
  module_load_include('install', 'uuid');
  $field = uuid_schema_field_definition();
  db_add_field('bean', 'uuid', $field);
  db_add_index('bean', 'uuid', array('uuid'));
  db_add_field('bean_revision', 'vuuid', $field);
  db_add_index('bean_revision', 'vuuid', array('vuuid'));
}

/**
 * Implements hook_enable().
 */
function bean_uuid_enable() {
  uuid_sync_all();
}

/**
 * Implements hook_uninstall().
 */
function bean_uuid_uninstall() {
  db_drop_field('bean', 'uuid');
  db_drop_index('bean', 'uuid');
  db_drop_field('bean_revision', 'vuuid');
  db_drop_index('bean_revision', 'vuuid');
}

/**
 * Add vuuid field to bean_revision table
 */
function bean_uuid_update_7201() {
  module_load_include('install', 'uuid');
  $field = uuid_schema_field_definition();
  db_add_field('bean_revision', 'vuuid', $field);
  db_add_index('bean_revision', 'vuuid', array('vuuid'));
}
