diff options
author | Dries Buytaert <dries@buytaert.net> | 2007-05-25 12:46:46 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2007-05-25 12:46:46 +0000 |
commit | 3cafffe63f70f418d0b6ca32ac5e0f3e27dceb41 (patch) | |
tree | cd59a40556a084f35b7b5a3bc3caa50874087541 /modules/poll | |
parent | ae762838c0e92bded86370103df4583874c50da7 (diff) | |
download | brdo-3cafffe63f70f418d0b6ca32ac5e0f3e27dceb41.tar.gz brdo-3cafffe63f70f418d0b6ca32ac5e0f3e27dceb41.tar.bz2 |
- Killer patch #144765 by bjaspan, frando et al: schema API 1 hits core. Oh, behave.
Diffstat (limited to 'modules/poll')
-rw-r--r-- | modules/poll/poll.install | 67 | ||||
-rw-r--r-- | modules/poll/poll.schema | 42 |
2 files changed, 46 insertions, 63 deletions
diff --git a/modules/poll/poll.install b/modules/poll/poll.install index 733d71c65..877b6ed48 100644 --- a/modules/poll/poll.install +++ b/modules/poll/poll.install @@ -5,73 +5,14 @@ * Implementation of hook_install(). */ function poll_install() { - switch ($GLOBALS['db_type']) { - case 'mysql': - case 'mysqli': - db_query("CREATE TABLE {poll} ( - nid int unsigned NOT NULL default '0', - runtime int NOT NULL default '0', - active int unsigned NOT NULL default '0', - PRIMARY KEY (nid) - ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); - - db_query("CREATE TABLE {poll_votes} ( - nid int unsigned NOT NULL, - uid int unsigned NOT NULL default 0, - chorder int NOT NULL default -1, - hostname varchar(128) NOT NULL default '', - INDEX (nid), - INDEX (uid), - INDEX (hostname) - ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); - - db_query("CREATE TABLE {poll_choices} ( - chid int unsigned NOT NULL auto_increment, - nid int unsigned NOT NULL default '0', - chtext varchar(128) NOT NULL default '', - chvotes int NOT NULL default '0', - chorder int NOT NULL default '0', - PRIMARY KEY (chid), - KEY nid (nid) - ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); - break; - - case 'pgsql': - db_query("CREATE TABLE {poll} ( - nid int_unsigned NOT NULL default '0', - runtime int NOT NULL default '0', - active int_unsigned NOT NULL default '0', - PRIMARY KEY (nid) - )"); - - db_query("CREATE TABLE {poll_votes} ( - nid int_unsigned NOT NULL, - uid int_unsigned NOT NULL default 0, - chorder int NOT NULL default -1, - hostname varchar(128) NOT NULL default '' - )"); - db_query("CREATE INDEX {poll_votes}_nid_idx ON {poll_votes} (nid)"); - db_query("CREATE INDEX {poll_votes}_uid_idx ON {poll_votes} (uid)"); - db_query("CREATE INDEX {poll_votes}_hostname_idx ON {poll_votes} (hostname)"); - - db_query("CREATE TABLE {poll_choices} ( - chid serial CHECK (chid >= 0), - nid int_unsigned NOT NULL default '0', - chtext varchar(128) NOT NULL default '', - chvotes int NOT NULL default '0', - chorder int NOT NULL default '0', - PRIMARY KEY (chid) - )"); - db_query("CREATE INDEX {poll_choices}_nid_idx ON {poll_choices} (nid)"); - break; - } + // Create tables. + drupal_install_schema('poll'); } /** * Implementation of hook_uninstall(). */ function poll_uninstall() { - db_query('DROP TABLE {poll}'); - db_query('DROP TABLE {poll_votes}'); - db_query('DROP TABLE {poll_choices}'); + // Remove tables. + drupal_uninstall_schema('poll'); } diff --git a/modules/poll/poll.schema b/modules/poll/poll.schema new file mode 100644 index 000000000..7a9a35509 --- /dev/null +++ b/modules/poll/poll.schema @@ -0,0 +1,42 @@ +<?php +// $Id$ + +function poll_schema() { + $schema['poll'] = array( + 'fields' => array( + 'nid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), + 'runtime' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), + 'active' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0) + ), + 'primary key' => array('nid'), + ); + + $schema['poll_choices'] = array( + 'fields' => array( + 'chid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE), + 'nid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), + 'chtext' => array('type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'default' => ''), + 'chvotes' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), + 'chorder' => array('type' => 'int', 'not null' => TRUE, 'default' => 0) + ), + 'indexes' => array('nid' => array('nid')), + 'primary key' => array('chid'), + ); + + $schema['poll_votes'] = array( + 'fields' => array( + 'nid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE), + 'uid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), + 'chorder' => array('type' => 'int', 'not null' => TRUE, 'default' => -1), + 'hostname' => array('type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'default' => '') + ), + 'indexes' => array( + 'hostname' => array('hostname'), + 'nid' => array('nid'), + 'uid' => array('uid') + ), + ); + + return $schema; +} + |