Skip to content

Instantly share code, notes, and snippets.

@pedrorocha-net
Created August 16, 2015 20:28
Show Gist options
  • Save pedrorocha-net/3ed63f33b513d9c9ff86 to your computer and use it in GitHub Desktop.
Save pedrorocha-net/3ed63f33b513d9c9ff86 to your computer and use it in GitHub Desktop.
Approach using hook_schema (as on Drupal 7)
$schema['votingapi_vote'] = array(
'fields' => array(
'vote_id' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE),
'entity_type' => array('type' => 'varchar', 'length' => 64, 'not null' => TRUE, 'default' => 'node'),
'entity_id' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
'value' => array('type' => 'float', 'not null' => TRUE, 'default' => 0),
'value_type' => array('type' => 'varchar', 'length' => 64, 'not null' => TRUE, 'default' => 'percent'),
'tag' => array('type' => 'varchar', 'length' => 64, 'not null' => TRUE, 'default' => 'vote'),
'uid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
'timestamp' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
'vote_source' => array('type' => 'varchar', 'length' => 255),
),
'primary key' => array('vote_id'),
'indexes' => array(
'content_uid' => array('entity_type', 'entity_id', 'uid'),
'content_uid_2' => array('entity_type', 'uid'),
'content_source' => array('entity_type', 'entity_id', 'vote_source'),
'content_value_tag' => array('entity_type', 'entity_id', 'value_type', 'tag'),
),
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment