You are here

function flag_schema in Flag 7.3

Same name and namespace in other branches
  1. 8.4 flag.install \flag_schema()
  2. 6.2 flag.install \flag_schema()
  3. 6 flag.install \flag_schema()
  4. 7.2 flag.install \flag_schema()

Implements hook_schema().

File

./flag.install, line 11
Flag module install/schema/update hooks.

Code

function flag_schema() {
  $schema = array();
  $schema['flag'] = array(
    'description' => 'All available flags in the system.',
    'fields' => array(
      'fid' => array(
        'description' => 'The unique ID for this particular flag.',
        'type' => 'serial',
        'size' => 'small',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'entity_type' => array(
        'description' => 'The flag type, for example "node", "comment", or "user".',
        'type' => 'varchar',
        'length' => '128',
        'not null' => TRUE,
        'default' => '',
      ),
      'name' => array(
        'description' => 'The machine-name for this flag.',
        'type' => 'varchar',
        'length' => '32',
        'not null' => FALSE,
        'default' => '',
      ),
      'title' => array(
        'description' => 'The human-readable title for this flag.',
        'type' => 'varchar',
        'length' => '255',
        'not null' => FALSE,
        'default' => '',
      ),
      'global' => array(
        'description' => 'Whether this flag state should act as a single toggle to all users across the site.',
        'type' => 'int',
        'size' => 'tiny',
        'not null' => FALSE,
        'default' => 0,
      ),
      'options' => array(
        'description' => 'The options and configuration of this flag.',
        'type' => 'text',
        'not null' => FALSE,
      ),
    ),
    'primary key' => array(
      'fid',
    ),
    'unique keys' => array(
      'name' => array(
        'name',
      ),
    ),
  );
  $schema['flagging'] = array(
    'description' => 'Objects that have been flagged.',
    'fields' => array(
      'flagging_id' => array(
        'description' => 'The unique ID for this particular tag.',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'fid' => array(
        'description' => 'The unique flag ID this object has been flagged with, from {flag}.',
        'type' => 'int',
        'size' => 'small',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'entity_type' => array(
        'description' => 'The flag type, for example "node", "comment", or "user".',
        'type' => 'varchar',
        'length' => '128',
        'not null' => TRUE,
        'default' => '',
      ),
      'entity_id' => array(
        'description' => 'The unique ID of the flagged entity, for example the uid, cid, or nid.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'uid' => array(
        'description' => 'The user ID by whom this object was flagged.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'sid' => array(
        'description' => "The user's numeric sid from the session_api table.",
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'timestamp' => array(
        'description' => 'The UNIX time stamp representing when the flag was set.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'disp-size' => 11,
      ),
    ),
    'primary key' => array(
      'flagging_id',
    ),
    'unique keys' => array(
      'fid_entity_id_uid_sid' => array(
        'fid',
        'entity_id',
        'uid',
        'sid',
      ),
    ),
    'indexes' => array(
      'entity_type_uid_sid' => array(
        'entity_type',
        'uid',
        'sid',
      ),
      'entity_type_entity_id_uid_sid' => array(
        'entity_type',
        'entity_id',
        'uid',
        'sid',
      ),
      'entity_id_fid' => array(
        'entity_id',
        'fid',
      ),
    ),
  );
  $schema['flag_types'] = array(
    'description' => 'The entity bundles that are affected by a flag.',
    'fields' => array(
      'fid' => array(
        'description' => 'The unqiue flag ID as defined for the flag in {flag}.',
        'type' => 'int',
        'size' => 'small',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'type' => array(
        'description' => 'The entity bundles that can be flagged by this fid.',
        'type' => 'varchar',
        'length' => '128',
        'not null' => TRUE,
        'default' => '',
      ),
    ),
    'indexes' => array(
      'fid' => array(
        'fid',
      ),
    ),
  );
  $schema['flag_counts'] = array(
    'description' => 'The number of times an item has been flagged.',
    'fields' => array(
      'fid' => array(
        'type' => 'int',
        'size' => 'small',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'entity_type' => array(
        'description' => 'The flag type, for example "node", "comment", or "user".',
        'type' => 'varchar',
        'length' => '128',
        'not null' => TRUE,
        'default' => '',
      ),
      'entity_id' => array(
        'description' => 'The unique ID of the flagged entity, for example the uid, cid, or nid.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'disp-width' => '10',
      ),
      'count' => array(
        'description' => 'The number of times this object has been flagged for this flag.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'disp-width' => '10',
      ),
      'last_updated' => array(
        'description' => 'The UNIX time stamp representing when the flag was last updated.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'disp-size' => 11,
      ),
    ),
    'primary key' => array(
      'fid',
      'entity_id',
    ),
    'indexes' => array(
      'fid_entity_type' => array(
        'fid',
        'entity_type',
      ),
      'entity_type_entity_id' => array(
        'entity_type',
        'entity_id',
      ),
      'fid_count' => array(
        'fid',
        'count',
      ),
      'fid_last_updated' => array(
        'fid',
        'last_updated',
      ),
    ),
  );
  return $schema;
}