You are here

function userpoints_schema in User Points 7.2

Same name and namespace in other branches
  1. 6 userpoints.install \userpoints_schema()
  2. 7 userpoints.install \userpoints_schema()

Implements hook_schema().

File

./userpoints.install, line 11
Install time hook userpoints module.

Code

function userpoints_schema() {
  $schema = array();
  $schema['userpoints'] = array(
    'description' => 'Holds the user points',
    'fields' => array(
      'pid' => array(
        'description' => 'Points ID',
        'type' => 'serial',
        'not null' => TRUE,
      ),
      'uid' => array(
        'description' => 'User ID',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'points' => array(
        'description' => 'Current Points',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'max_points' => array(
        'description' => 'Out of a maximum points',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'last_update' => array(
        'description' => 'Timestamp',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'tid' => array(
        'description' => 'Category ID',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'primary key' => array(
      'pid',
    ),
    'indexes' => array(
      'last_update' => array(
        'last_update',
      ),
      'points' => array(
        'points',
      ),
    ),
    'unique keys' => array(
      'uid_tid' => array(
        'uid',
        'tid',
      ),
    ),
  );
  $schema['userpoints_total'] = array(
    'description' => 'Holds the total user points',
    'fields' => array(
      'uid' => array(
        'description' => 'User ID',
        'type' => 'int',
        'not null' => TRUE,
      ),
      'points' => array(
        'description' => 'Current Points',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'max_points' => array(
        'description' => 'Out of a maximum points',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'last_update' => array(
        'description' => 'Timestamp',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'primary key' => array(
      'uid',
    ),
    'indexes' => array(
      'last_update' => array(
        'last_update',
      ),
      'points' => array(
        'points',
      ),
    ),
  );
  $schema['userpoints_txn'] = array(
    'description' => 'Userpoints Transactions',
    'fields' => array(
      'txn_id' => array(
        'description' => 'Transaction ID',
        'type' => 'serial',
        'not null' => TRUE,
      ),
      'type' => array(
        'description' => 'Bundle',
        'type' => 'varchar',
        'length' => 100,
        'not null' => TRUE,
      ),
      'uid' => array(
        'description' => 'User ID',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'approver_uid' => array(
        'description' => 'Moderator User ID',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'points' => array(
        'description' => 'Points',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'time_stamp' => array(
        'description' => 'Timestamp',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'changed' => array(
        'description' => 'Effective timestamp of last action on this transaction, for tracking purposes.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'status' => array(
        'description' => 'Status',
        'type' => 'int',
        'size' => 'tiny',
        'not null' => TRUE,
        'default' => 0,
      ),
      'description' => array(
        'description' => 'Description',
        'type' => 'text',
      ),
      'reference' => array(
        'description' => 'Reserved for module specific use',
        'type' => 'varchar',
        'length' => 128,
      ),
      'expirydate' => array(
        'description' => 'Expirydate',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'expired' => array(
        'description' => 'Expiration status',
        'type' => 'int',
        'size' => 'tiny',
        'not null' => TRUE,
        'default' => 0,
      ),
      'parent_txn_id' => array(
        'description' => 'Parent Transaction ID',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'tid' => array(
        'description' => 'Category ID',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'entity_id' => array(
        'description' => 'ID of an entity in the Database',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'entity_type' => array(
        'description' => 'Type of entity',
        'type' => 'varchar',
        'length' => 128,
      ),
      'operation' => array(
        'description' => 'Operation being carried out',
        'type' => 'varchar',
        'length' => 48,
      ),
    ),
    'primary key' => array(
      'txn_id',
    ),
    'indexes' => array(
      'operation' => array(
        'operation',
      ),
      'reference' => array(
        'reference',
      ),
      'status_expired_expiry' => array(
        'status',
        'expired',
        'expirydate',
      ),
      //Optional as in update_6011
      'changed' => array(
        'changed',
      ),
      'uid' => array(
        'uid',
      ),
      'approver_uid' => array(
        'approver_uid',
      ),
      'points' => array(
        'points',
      ),
    ),
  );
  $schema['userpoints_txn_type'] = array(
    'description' => 'Userpoints transaction type',
    'fields' => array(
      'id' => array(
        'description' => 'Transaction type id',
        'type' => 'serial',
        'not null' => TRUE,
      ),
      'name' => array(
        'description' => 'Machine name',
        'type' => 'varchar',
        'length' => 100,
        'not null' => TRUE,
      ),
      'label' => array(
        'description' => 'Human-readable name',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ),
      'status' => array(
        'description' => 'Type status used by Entity API',
        'type' => 'int',
        'size' => 'tiny',
        'not null' => TRUE,
        'default' => 0x1,
      ),
      'module' => array(
        'description' => 'Module owner of type used by Entity API',
        'type' => 'varchar',
        'length' => 100,
        'not null' => FALSE,
      ),
    ),
    'primary key' => array(
      'id',
    ),
    'unique keys' => array(
      'name' => array(
        'name',
      ),
    ),
  );
  return $schema;
}