123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215 |
- <?php
- function poll_schema() {
- $schema['poll'] = array(
- 'description' => 'Stores poll-specific information for poll nodes.',
- 'fields' => array(
- 'nid' => array(
- 'type' => 'int',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- 'default' => 0,
- 'description' => "The poll's {node}.nid.",
- ),
- 'runtime' => array(
- 'type' => 'int',
- 'not null' => TRUE,
- 'default' => 0,
- 'description' => 'The number of seconds past {node}.created during which the poll is open.',
- ),
- 'active' => array(
- 'type' => 'int',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- 'default' => 0,
- 'description' => 'Boolean indicating whether or not the poll is open.',
- ),
- ),
- 'primary key' => array('nid'),
- 'foreign keys' => array(
- 'poll_node' => array(
- 'table' => 'node',
- 'columns' => array('nid' => 'nid'),
- ),
- ),
- );
- $schema['poll_choice'] = array(
- 'description' => 'Stores information about all choices for all {poll}s.',
- 'fields' => array(
- 'chid' => array(
- 'type' => 'serial',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- 'description' => 'Unique identifier for a poll choice.',
- ),
- 'nid' => array(
- 'type' => 'int',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- 'default' => 0,
- 'description' => 'The {node}.nid this choice belongs to.',
- ),
- 'chtext' => array(
- 'type' => 'varchar',
- 'length' => 128,
- 'not null' => TRUE,
- 'default' => '',
- 'description' => 'The text for this choice.',
- 'translatable' => TRUE,
- ),
- 'chvotes' => array(
- 'type' => 'int',
- 'not null' => TRUE,
- 'default' => 0,
- 'description' => 'The total number of votes this choice has received by all users.',
- ),
- 'weight' => array(
- 'type' => 'int',
- 'not null' => TRUE,
- 'default' => 0,
- 'description' => 'The sort order of this choice among all choices for the same node.',
- ),
- ),
- 'indexes' => array(
- 'nid' => array('nid'),
- ),
- 'primary key' => array('chid'),
- 'foreign keys' => array(
- 'choice_node' => array(
- 'table' => 'node',
- 'columns' => array('nid' => 'nid'),
- ),
- ),
- );
- $schema['poll_vote'] = array(
- 'description' => 'Stores per-{users} votes for each {poll}.',
- 'fields' => array(
- 'chid' => array(
- 'type' => 'int',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- 'description' => "The {users}'s vote for this poll.",
- ),
- 'nid' => array(
- 'type' => 'int',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- 'description' => 'The {poll} node this vote is for.',
- ),
- 'uid' => array(
- 'type' => 'int',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- 'default' => 0,
- 'description' => 'The {users}.uid this vote is from unless the voter was anonymous.',
- ),
- 'hostname' => array(
- 'type' => 'varchar',
- 'length' => 128,
- 'not null' => TRUE,
- 'default' => '',
- 'description' => 'The IP address this vote is from unless the voter was logged in.',
- ),
- 'timestamp' => array(
- 'type' => 'int',
- 'not null' => TRUE,
- 'default' => 0,
- 'description' => 'The timestamp of the vote creation.',
- ),
- ),
- 'primary key' => array('nid', 'uid', 'hostname'),
- 'foreign keys' => array(
- 'poll_node' => array(
- 'table' => 'node',
- 'columns' => array('nid' => 'nid'),
- ),
- 'voter' => array(
- 'table' => 'users',
- 'columns' => array('uid' => 'uid'),
- ),
- ),
- 'indexes' => array(
- 'chid' => array('chid'),
- 'hostname' => array('hostname'),
- 'uid' => array('uid'),
- ),
- );
- return $schema;
- }
- function poll_update_7001() {
-
- db_add_field('poll_votes', 'chid', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0));
- db_add_index('poll_votes', 'chid', array('chid'));
- db_update('poll_votes')
- ->expression('chid', Database::getConnection()->prefixTables('COALESCE((SELECT chid FROM {poll_choices} c WHERE {poll_votes}.chorder = c.chorder AND {poll_votes}.nid = c.nid), 0)'))
- ->execute();
-
- db_delete('poll_votes')->condition('chid', 0)->execute();
-
- db_drop_field('poll_votes', 'chorder');
-
- db_change_field('poll_choices', 'chorder', 'weight', array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'size' => 'tiny'));
- db_rename_table('poll_votes', 'poll_vote');
- db_rename_table('poll_choices', 'poll_choice');
- }
- function poll_update_7002() {
- $field = array(
- 'type' => 'int',
- 'not null' => TRUE,
- 'default' => 0,
- );
- db_add_field('poll_vote', 'timestamp', $field);
- }
- function poll_update_7003() {
- db_change_field('poll_choice', 'weight', 'weight', array(
- 'type' => 'int',
- 'not null' => TRUE,
- 'default' => 0,
- 'description' => 'The sort order of this choice among all choices for the same node.',
- ));
- }
- function poll_update_7004() {
-
- db_change_field('poll_vote', 'chid', 'chid', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE));
- }
|