--- tokenauth.install.orig	2008-08-09 17:57:02.000000000 -0400
+++ tokenauth.install	2008-08-09 20:58:06.000000000 -0400
@@ -15,30 +15,41 @@ function tokenauth_schema() {
        'description'     => 'The user specific token',
        'type'            => 'varchar',
        'length'          => 50,
-       'not null'        => FALSE,
-       'default'         => NULL,
+       'not null'        => TRUE,
      ),
+   ),
    'primary key'       => array('token'),
-   'unique key'       => array('uid'),
-   )
- );
+   'unique keys'         => array(
+     'uid_key'           => array('uid')
+   ),
+  );
  return $schema;
 }
- 
+
 
 function tokenauth_install() {
-  drupal_install_schema('tokenauth_tokens');
+  drupal_install_schema('tokenauth');
 }
 
 function tokenauth_enable() {
-  // give an initial token to all
-  $subquery = "SELECT u.uid, '%s' FROM {users} u LEFT JOIN {tokenauth_tokens} tt ON u.uid=tt.uid WHERE u.uid > 0 AND tt.token IS NULL";
-  $sql = "INSERT INTO {tokenauth_tokens} (uid, token) $subquery";
-  db_query($sql, user_password());
+  $has_token = array();
+  $result = db_query("SELECT uid FROM {tokenauth_tokens}");
+  while ($row = db_fetch_array($result)) {
+    $has_token[$row['uid']] = TRUE;
+  }
+
+  $result = db_query("SELECT uid FROM {users}");
+  while ($row = db_fetch_array($result)) {
+    $uid = $row['uid'];
+    if (!$has_token[$uid]) {
+      db_query("INSERT INTO {tokenauth_tokens} (uid,token) VALUES (%d,'%s')",
+               $uid, user_password());
+    }
+  }
 }
 
 function tokenauth_uninstall() {
-  drupal_uninstall_schema('tokenauth_tokens');
+  drupal_uninstall_schema('tokenauth');
   variable_del('tokenauth_length');
   variable_del('tokenauth_pages');
   variable_del('tokenauth_reset');
