<?php
// $Id: modr8.install,v 1.5 2010/04/02 02:59:08 pwolanin Exp $

/**
 * Implementation of hook_schema().
 */
function modr8_schema() {
  $schema['modr8_log'] = array(
    'fields' => array(
      'modid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE),
      'nid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
      'uid' => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
      'author_uid' => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
      'action' => array('type' => 'varchar', 'length' => 16, 'not null' => TRUE, 'default' => ''),
      'title' => array('type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'default' => ''),
      'message' => array('type' => 'text', 'size' => 'big',  'not null' => TRUE),
      'teaser' => array('type' => 'text', 'size' => 'big',  'not null' => TRUE),
      'timestamp' => array('type' => 'int', 'not null' => TRUE, 'default' => 0)
    ),
    'indexes' => array(
      'nid_time' => array('nid', 'modid'),
      'time_action' => array('timestamp', 'action'),
    ),
    'primary key' => array('modid'),
  );

  return $schema;
}

/**
 * Implementation of hook_install().
 */
function modr8_install() {
  // Create tables.
  drupal_install_schema('modr8');
}

/**
 * Implementation of hook_uninstall().
 */
function modr8_uninstall() {
  // Remove tables.
  drupal_uninstall_schema('modr8');
}

/**
 * Update table definitions.
 */
function modr8_update_1000() {
  $ret = array();
  $name = 'modr8_log';
  $table = array(
    'fields' => array(
      'modid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE),
      'nid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
      'uid' => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
      'author_uid' => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
      'action' => array('type' => 'varchar', 'length' => 16, 'not null' => TRUE, 'default' => ''),
      'title' => array('type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'default' => ''),
      'message' => array('type' => 'text', 'size' => 'big',  'not null' => TRUE),
      'teaser' => array('type' => 'text', 'size' => 'big',  'not null' => TRUE),
      'timestamp' => array('type' => 'int', 'not null' => TRUE, 'default' => 0)
    ),
    'indexes' => array(
      'nid_time' => array('nid', 'modid'),
      'action' => array('action')
    ),
    'primary key' => array('modid'),
  );
  db_create_table($ret, $name, $table);
  return $ret;
}

/**
 * Fix index for new block.
 */
function modr8_update_6001() {
  $ret = array();
  db_drop_index($ret, 'modr8_log', 'action');
  db_add_index($ret, 'modr8_log', 'time_action', array('timestamp', 'action'));
  return $ret;
}
