drupal/modules/poll/poll.install

144 lines
3.7 KiB
Plaintext

<?php
// $Id$
/**
* Implementation of hook_install().
*/
function poll_install() {
// Create tables.
drupal_install_schema('poll');
}
/**
* Implementation of hook_uninstall().
*/
function poll_uninstall() {
// Remove tables.
drupal_uninstall_schema('poll');
}
/**
* Implementation of hook_schema().
*/
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'),
);
$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.',
),
'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',
'size' => 'tiny',
'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'),
);
$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.',
),
),
'primary key' => array('nid', 'uid', 'hostname'),
'indexes' => array(
'chid' => array('chid'),
'hostname' => array('hostname'),
'uid' => array('uid'),
),
);
return $schema;
}
/**
* Rename {poll_choices} table to {poll_choice} and {poll_votes} to {poll_vote}.
*/
function poll_update_7001() {
$ret = array();
db_rename_table($ret, 'poll_choices', 'poll_choice');
db_rename_table($ret, 'poll_votes', 'poll_vote');
return $ret;
}