summaryrefslogtreecommitdiff
path: root/database
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2005-12-27 14:34:21 +0000
committerDries Buytaert <dries@buytaert.net>2005-12-27 14:34:21 +0000
commit387b47ec2bb700776162086882ed66db9a2e7626 (patch)
treeb8cb3f17a0d2e61308fb71d6f1b6946f5edd503f /database
parent02eb24bfbd073383f185f4d68daefa09660c477f (diff)
downloadbrdo-387b47ec2bb700776162086882ed66db9a2e7626.tar.gz
brdo-387b47ec2bb700776162086882ed66db9a2e7626.tar.bz2
- Patch #41755 by Neil: normalize poll.polled database column.
Diffstat (limited to 'database')
-rw-r--r--database/database.mysql14
-rw-r--r--database/database.pgsql14
-rw-r--r--database/updates.inc56
3 files changed, 82 insertions, 2 deletions
diff --git a/database/database.mysql b/database/database.mysql
index c96c51ee3..92df2c686 100644
--- a/database/database.mysql
+++ b/database/database.mysql
@@ -536,12 +536,24 @@ CREATE TABLE permission (
CREATE TABLE poll (
nid int(10) unsigned NOT NULL default '0',
runtime int(10) NOT NULL default '0',
- polled longtext NOT NULL,
active int(2) unsigned NOT NULL default '0',
PRIMARY KEY (nid)
) TYPE=MyISAM;
--
+-- Table structure for table 'poll_votes'
+--
+
+CREATE TABLE poll_votes (
+ nid int(10) unsigned NOT NULL,
+ uid int(10) unsigned NOT NULL,
+ hostname varchar(128) NOT NULL,
+ INDEX (nid),
+ INDEX (uid),
+ INDEX (hostname)
+) TYPE=MyISAM;
+
+--
-- Table structure for table 'poll_choices'
--
diff --git a/database/database.pgsql b/database/database.pgsql
index 6278a766a..7883dd06c 100644
--- a/database/database.pgsql
+++ b/database/database.pgsql
@@ -531,12 +531,24 @@ CREATE INDEX permission_rid_idx ON permission(rid);
CREATE TABLE poll (
nid integer NOT NULL default '0',
runtime integer NOT NULL default '0',
- polled text NOT NULL default '',
active integer NOT NULL default '0',
PRIMARY KEY (nid)
);
--
+-- Table structure for poll_votes
+--
+
+CREATE TABLE poll_votes (
+ nid int(10) NOT NULL,
+ uid int(10) NOT NULL,
+ hostname varchar(128) NOT NULL
+);
+CREATE INDEX poll_voter_nid_idx ON poll_votes (nid);
+CREATE INDEX poll_votes_uid_idx ON poll_votes (uid);
+CREATE INDEX poll_votes_hostname_idx ON poll_votes (hostname);
+
+--
-- Table structure for poll_choices
--
diff --git a/database/updates.inc b/database/updates.inc
index f977fdbde..26f627342 100644
--- a/database/updates.inc
+++ b/database/updates.inc
@@ -1286,3 +1286,59 @@ function system_update_163() {
}
return $ret;
}
+
+function system_update_164() {
+ $ret = array();
+
+ switch ($GLOBALS['db_type']) {
+ case 'mysql':
+ case 'mysqli':
+ $ret[] = update_sql('CREATE TABLE {poll_votes} (
+ nid int(10) unsigned NOT NULL,
+ uid int(10) unsigned NOT NULL,
+ hostname varchar(128) NOT NULL,
+ INDEX (nid),
+ INDEX (uid),
+ INDEX (hostname)
+ )');
+ break;
+
+ case 'pgsql':
+ $ret[] = update_sql('CREATE TABLE {poll_votes} (
+ nid int(10) NOT NULL,
+ uid int(10) NOT NULL,
+ hostname varchar(128) NOT NULL
+ )');
+ $ret[] = update_sql('CREATE INDEX {poll_votes}_nid_idx ON {poll_votes} (nid)');
+ $ret[] = update_sql('CREATE INDEX {poll_votes}_uid_idx ON {poll_votes} (uid)');
+ $ret[] = update_sql('CREATE INDEX {poll_votes}_hostname_idx ON {poll_votes} (hostname)');
+ break;
+ }
+
+ $result = db_query('SELECT nid, polled FROM {poll}');
+ while ($poll = db_fetch_object($result)) {
+ foreach (explode(' ', $poll->polled) as $polled) {
+ if ($polled[0] == '_') {
+ // $polled is a user id
+ db_query('INSERT INTO {poll_votes} (nid, uid) VALUES (%d, %d)', $poll->nid, substr($polled, 1, -1));
+ }
+ else {
+ // $polled is a host
+ db_query("INSERT INTO {poll_votes} (nid, hostname) VALUES (%d, '%s')", $poll->nid, $polled);
+ }
+ }
+ }
+
+ switch ($GLOBALS['db_type']) {
+ case 'mysql':
+ case 'mysqli':
+ $ret[] = update_sql('ALTER TABLE {poll} DROP polled');
+ break;
+
+ case 'pgsql':
+ $ret[] = update_sql('ALTER TABLE {poll} RENAME polled TO polled_old');
+ break;
+ }
+
+ return $ret;
+}