You are here

function commerce_license_schema in Commerce License 7

Implements hook_schema().

File

./commerce_license.install, line 6

Code

function commerce_license_schema() {
  $schema['commerce_license'] = array(
    'description' => 'The base table for the commerce_license entity type.',
    'fields' => array(
      'license_id' => array(
        'description' => 'The primary identifier for a license.',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      // Defaults to NULL in order to avoid a brief period of potential
      // deadlocks on the index.
      'revision_id' => array(
        'description' => 'The current {commerce_license_revision}.revision_id identifier.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => FALSE,
        'default' => NULL,
      ),
      'type' => array(
        'description' => 'The license type.',
        'type' => 'varchar',
        'length' => 64,
        'not null' => TRUE,
      ),
      'uid' => array(
        'description' => 'The {users}.uid that created this license belongs to.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'product_id' => array(
        'description' => 'The {commerce_product}.product_id that is licensed.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'status' => array(
        'description' => 'The license status.',
        'type' => 'int',
        'size' => 'tiny',
        'not null' => TRUE,
        'default' => 0,
      ),
      'granted' => array(
        'description' => 'The Unix timestamp when the license was granted.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'size' => 'big',
      ),
      'expires' => array(
        'description' => 'The Unix timestamp when the license expires. 0 for never.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'size' => 'big',
      ),
      'expires_automatically' => array(
        'description' => 'Whether the module should expire the license automatically.',
        'type' => 'int',
        'size' => 'tiny',
        'not null' => TRUE,
        'default' => 1,
      ),
    ),
    'primary key' => array(
      'license_id',
    ),
    'indexes' => array(
      'uid' => array(
        'uid',
      ),
      'type' => array(
        'type',
      ),
      'status' => array(
        'status',
      ),
      'product_id' => array(
        'product_id',
      ),
    ),
    'unique keys' => array(
      'revision_id' => array(
        'revision_id',
      ),
    ),
    'foreign keys' => array(
      'current_revision' => array(
        'table' => 'commerce_license_revision',
        'columns' => array(
          'revision_id' => 'revision_id',
        ),
      ),
      'owner' => array(
        'table' => 'users',
        'columns' => array(
          'uid' => 'uid',
        ),
      ),
      'product' => array(
        'table' => 'commerce_product',
        'columns' => array(
          'product_id' => 'product_id',
        ),
      ),
    ),
  );
  $schema['commerce_license_revision'] = array(
    'description' => 'Stores information about each saved revision of a {commerce_license}.',
    'fields' => array(
      'license_id' => array(
        'description' => 'The {commerce_license}.license_id of the license this revision belongs to.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'revision_id' => array(
        'description' => 'The primary identifier for this revision.',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'product_id' => array(
        'description' => 'The {commerce_product}.product_id that is licensed for this revision.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'status' => array(
        'description' => 'The license status for this revision.',
        'type' => 'int',
        'size' => 'tiny',
        'not null' => TRUE,
        'default' => 0,
      ),
      'revision_created' => array(
        'description' => 'The Unix timestamp when the revision was created.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'size' => 'big',
      ),
      'revision_ended' => array(
        'description' => 'The Unix timestamp when the revision ended.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'size' => 'big',
      ),
      // Defaults to NULL to distinguish a lack of data from user 0 (anonymous,
      // or Drush).
      'revision_uid' => array(
        'description' => 'The {users}.uid of the user who created the revision.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => FALSE,
        'default' => NULL,
      ),
      'log' => array(
        'description' => 'The log entry explaining the changes in this revision.',
        'type' => 'text',
        'not null' => FALSE,
        'size' => 'big',
        'default' => NULL,
      ),
    ),
    'primary key' => array(
      'revision_id',
    ),
    'indexes' => array(
      'license_id' => array(
        'license_id',
      ),
      'product_id' => array(
        'product_id',
      ),
    ),
    'foreign keys' => array(
      'license' => array(
        'table' => 'commerce_license',
        'columns' => array(
          'license_id' => 'license_id',
        ),
      ),
      'product' => array(
        'table' => 'commerce_product',
        'columns' => array(
          'product_id' => 'product_id',
        ),
      ),
      'revision_uid' => array(
        'table' => 'users',
        'columns' => array(
          'revision_uid' => 'uid',
        ),
      ),
    ),
  );
  return $schema;
}