You are here

userpoints.install in User Points 5

File

userpoints.install
View source
<?php

/**
 * Install the initial schema.
 */
function userpoints_install() {
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      db_query("CREATE TABLE {userpoints} (\n          uid           INT(10) NOT NULL DEFAULT '0',\n          points        INT(10) NOT NULL DEFAULT '0',\n          max_points    INT(10) NOT NULL DEFAULT '0',\n          last_update   INT(11) NOT NULL DEFAULT '0',\n          PRIMARY KEY (uid),\n          KEY (last_update)\n        ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
      db_query("CREATE TABLE {userpoints_txn} (\n          txn_id        INT     NOT NULL AUTO_INCREMENT,\n          uid           INT(10) NOT NULL DEFAULT '0',\n          approver_uid  INT(10) NOT NULL DEFAULT '0',\n          points        INT(10) NOT NULL DEFAULT '0',\n          time_stamp    INT(11) NOT NULL DEFAULT '0',\n          status        INT(1) NOT NULL DEFAULT '0',\n          event         VARCHAR(32),\n          description   TEXT,\n          reference     varchar(128),\n          PRIMARY KEY (txn_id),\n          KEY (event),\n          KEY (reference),\n          KEY (status)\n        ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
      break;
    case 'pgsql':
      db_query("CREATE TABLE {userpoints} (\n          uid           SERIAL,\n\t        points        INTEGER NOT NULL default '0',\n\t        max_points    INTEGER NOT NULL default '0',\n\t        last_update   INTEGER NOT NULL default '0',\n\t        PRIMARY KEY (uid)\n        );");
      db_query("CREATE TABLE {userpoints_txn} (\n          txn_id        SERIAL,\n\t        uid           INTEGER NOT NULL default '0',\n\t        approver_uid  INTEGER NOT NULL default '0',\n\t        points        INTEGER NOT NULL default '0',\n\t        time_stamp    INTEGER NOT NULL default '0',\n\t        status        INTEGER NOT NULL default '0',\n\t        event         VARCHAR,\n\t        description   VARCHAR,\n\t        PRIMARY KEY (txn_id)\n\t      );");
      break;
  }
}

/**
* Implementation of hook_uninstall().
*/
function userpoints_uninstall() {
  db_query('DROP TABLE {userpoints}');
  db_query('DROP TABLE {userpoints_txn}');
  db_query("DELETE FROM {variable} WHERE name like '%userpoints%'");
}
function userpoints_update_1() {
  return _system_update_utf8(array(
    'userpoints',
  ));
}
function userpoints_update_2() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':

      // Add the max_points column
      $ret[] = update_sql("ALTER TABLE {userpoints} ADD max_points INT(10) NOT NULL DEFAULT '0' AFTER points");

      // Make the points column bigger
      $ret[] = update_sql("ALTER TABLE {userpoints} CHANGE points points INT(10) NOT NULL DEFAULT '0'");
      break;
  }
  return $ret;
}
function userpoints_update_3() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':

      // Add the description column
      $ret[] = update_sql("ALTER TABLE {userpoints_txn} ADD description TEXT AFTER event");
      break;
  }
  return $ret;
}
function userpoints_update_4() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':

      // Add the description column
      $ret[] = update_sql("ALTER TABLE {userpoints_txn} CHANGE event event VARCHAR(32)");
      $ret[] = update_sql("ALTER TABLE {userpoints_txn} CHANGE status status INTEGER NOT NULL DEFAULT '0' AFTER time_stamp");
      break;
  }
  return $ret;
}
function userpoints_update_5() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':

      // Add the reference column and its index
      $ret[] = update_sql("ALTER TABLE {userpoints_txn} ADD COLUMN reference VARCHAR(128) AFTER description");
      $ret[] = update_sql("ALTER TABLE {userpoints_txn} ADD INDEX reference (reference )");
      break;
  }
  return $ret;
}