--- userpoints.install	2008-01-20 20:23:02.283620800 -0700
+++ userpoints.new.install	2008-01-20 20:14:41.767995800 -0700
@@ -39,6 +39,14 @@ function userpoints_install() {
           KEY (reference),
           KEY (status)
         ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
+      db_query("CREATE TABLE {userpoints} (
+          uid           INT(10) NOT NULL DEFAULT '0',
+          points        INT(10) NOT NULL DEFAULT '0',
+          max_points    INT(10) NOT NULL DEFAULT '0',
+          last_update   INT(11) NOT NULL DEFAULT '0',
+          PRIMARY KEY (uid),
+          KEY (last_update)
+        ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
       break;
 
     case 'pgsql':
@@ -63,6 +71,13 @@ function userpoints_install() {
           parent_txn_id INTEGER NOT NULL default '0'
 	        PRIMARY KEY (txn_id)
 	      );");
+      db_query("CREATE TABLE {userpoints_summary} (
+          uid           SERIAL,
+	        points        INTEGER NOT NULL default '0',
+	        max_points    INTEGER NOT NULL default '0',
+	        last_update   INTEGER NOT NULL default '0',
+	        PRIMARY KEY (uid)
+        );");
       break;
   }
 }
@@ -79,6 +94,7 @@ function userpoints_uninstall() {
 
   db_query('DROP TABLE {userpoints}');
   db_query('DROP TABLE {userpoints_txn}');
+  db_query('DROP TABLE {userpoints_summary}');
   db_query("DELETE FROM {variable} WHERE name like '%userpoints%'");
 }
 
@@ -191,3 +207,20 @@ function userpoints_update_8() {
   }
   return $ret;
 }
+function userpoints_update_9() {
+  $ret = array();
+  switch ($GLOBALS['db_type']) {
+    case 'mysql':
+    case 'mysqli':
+      $ret[] = update_sql("CREATE TABLE {userpoints_summary} (
+                          uid           SERIAL,
+	                        points        INTEGER NOT NULL default '0',
+	                        max_points    INTEGER NOT NULL default '0',
+	                        last_update   INTEGER NOT NULL default '0',
+	                        PRIMARY KEY (uid)
+                          )");
+      $ret[] = update_sql("INSERT INTO {userpoints_summary} (uid, points, max_points, last_update) SELECT uid, SUM(points) AS points, SUM(max_points) AS max_points, NULL AS last_update FROM {userpoints} WHERE 1 GROUP BY uid");
+      break;
+  }
+  return $ret;
+}
