You are here

restful_test.install in RESTful 7.2

Same filename and directory in other branches
  1. 7 tests/modules/restful_test/restful_test.install

Install, update and uninstall functions for the entity_test module.

File

tests/modules/restful_test/restful_test.install
View source
<?php

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

/**
 * Implements hook_install().
 */
function restful_test_install() {
  if (!db_field_exists('entity_test', 'uuid')) {
    db_add_field('entity_test', 'uuid', array(
      'type' => 'char',
      'length' => 36,
      'not null' => TRUE,
      'default' => '',
      'description' => 'The Universally Unique Identifier.',
    ));
    db_add_index('entity_test', 'uuid', array(
      'uuid',
    ));
  }
}

/**
 * Implements hook_schema_alter().
 */
function restful_test_schema_alter(&$schema = array()) {
  $field = array(
    'type' => 'char',
    'length' => 36,
    'not null' => TRUE,
    'default' => '',
    'description' => 'The Universally Unique Identifier.',
  );
  foreach (array(
    'entity_test',
    'restful_test_translatable_entity',
  ) as $table) {
    $schema[$table]['fields']['uuid'] = $field;
  }
}

/**
 * Implements hook_uninstall().
 */
function restful_test_uninstall() {
  variable_del('restful_test_alternative_id_error');
  field_attach_delete_bundle('restful_test_translatable_entity', 'restful_test_translatable_entity');
}

/**
 * Implements hook_schema().
 */
function restful_test_schema() {
  $schema['restful_test_translatable_entity'] = array(
    'description' => 'Stores restful_test_translatable_entity items.',
    'fields' => array(
      'pid' => array(
        'type' => 'serial',
        'not null' => TRUE,
        'description' => 'Primary Key: Unique restful_test_translatable_entity item ID.',
      ),
      'name' => array(
        'description' => 'The name of the restful_test_translatable_entity.',
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
        'default' => '',
      ),
      'uid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => FALSE,
        'default' => NULL,
        'description' => "The {users}.uid of the associated user.",
      ),
      'label' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'uuid' => array(
        'type' => 'char',
        'length' => 36,
        'not null' => TRUE,
        'default' => '',
        'description' => 'The Universally Unique Identifier.',
      ),
    ),
    'indexes' => array(
      'uid' => array(
        'uid',
      ),
      'uuid' => array(
        'uuid',
      ),
    ),
    'foreign keys' => array(
      'uid' => array(
        'users' => 'uid',
      ),
    ),
    'primary key' => array(
      'pid',
    ),
  );

  // Defining table via hook_install() due to drupal_write_record().
  $schema['restful_test_db_query'] = array(
    'description' => 'Table for DbQuery testing.',
    'fields' => array(
      'id' => array(
        'description' => 'The primary identifier for a record.',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'str_field' => array(
        'description' => 'String piece of data.',
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
        'default' => '',
      ),
      'int_field' => array(
        'description' => 'An int piece of data.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'serialized_field' => array(
        'description' => 'An serialized piece of data.',
        'type' => 'blob',
        'serialize' => TRUE,
      ),
    ),
    'primary key' => array(
      'id',
    ),
  );
  return $schema;
}