You are here

function eck_schema in Entity Construction Kit (ECK) 7.2

Same name and namespace in other branches
  1. 7.3 eck.install \eck_schema()
  2. 7 eck.install \eck_schema()

Implements hook_schema().

Create the database table that will store the entities information. All that we need for each entity is a name and a label.

File

./eck.install, line 36
ECK's requirements, schemas, and logic for install and uninstall.

Code

function eck_schema() {
  $schema = array();

  // Schema for an eck only cache table.
  $schema['cache_eck'] = drupal_get_schema_unprocessed('system', 'cache');

  // Schema for the eck table.
  $schema['eck_entity_type'] = array(
    'description' => "The base table for entity type information",
    'fields' => array(
      'id' => array(
        'description' => "The primary identifier for a bundle",
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'name' => array(
        'description' => "The machine name of the entity",
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
      ),
      'label' => array(
        'description' => "The entity's Label",
        'type' => 'varchar',
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
      ),
      'properties' => array(
        'type' => 'text',
        'not null' => TRUE,
        'serialize' => TRUE,
        'initial' => serialize(array()),
        'description' => 'A serialized list of properties attached to this entity.',
      ),
    ),
    'primary key' => array(
      'id',
    ),
    'unique keys' => array(
      'name' => array(
        'name',
      ),
    ),
    'indexes' => array(),
  );
  $schema['eck_bundle'] = array(
    'description' => "The base table for bundle information",
    'fields' => array(
      'id' => array(
        'description' => "The primary identifier for a bundle",
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'machine_name' => array(
        'description' => "A combination of the entity type and the name of" . "this bundle, this combination is unique",
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
      ),
      'entity_type' => array(
        'description' => "The entity type this bundle belongs to",
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
      ),
      'name' => array(
        'description' => "The bundle's name",
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
      ),
      'label' => array(
        'description' => "A human readable name for the bundle (not that the type is not human readable)",
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
      ),
      'config' => array(
        'description' => 'A serialized list of the bundle settings.',
        'type' => 'text',
        'serialize' => TRUE,
        'initial' => serialize(array()),
        'not null' => TRUE,
      ),
    ),
    'primary key' => array(
      'id',
    ),
    'unique' => array(
      'machine_name' => array(
        'machine_name',
      ),
    ),
  );

  // At the installation stage, ECK has not been created, so what is this for?
  // The schema is not only used during installation, it is used at many other
  // stages and by many other processes withing drupal. Because we are creating
  // tables dynamically with eck, we need to expose those schemas through this
  // function, that is why we are doing this.
  return $schema;
}