<?php
// $Id: uc_node_checkout.install,v 1.3.2.3 2009/01/30 14:18:37 rszrama Exp $

/**
 * Implementation of hook_install().
 */
function uc_node_checkout_install() {
  // Create tables.
  drupal_install_schema('uc_node_checkout');
}
/**
 * Implementation of hook_uninstall().
 */
function uc_node_checkout_uninstall() {
  // Remove tables.
  drupal_uninstall_schema('uc_node_checkout');
}

/**
 * Implementation of hook_schema().
 */
function uc_node_checkout_schema() {
  $schema['uc_node_checkout_types'] = array(
    'fields' => array(
      'node_type' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'product_nid' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'node_view' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
    ),
    'indexes' => array(
      'node_type' => array('node_type'),
    ),
  );

  $schema['uc_node_checkout_order_products'] = array(
    'fields' => array(
      'nid' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'order_product_id' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'primary key' => array('nid'),
  );

  return $schema;
}

/**
 * Implementation of hook_update_N().
 */
function uc_node_checkout_update_6200() {
  $ret = array();

  // Change the type column to a varchar(255).
  db_change_field($ret, 'uc_node_checkout_types', 'type', 'node_type', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''));

  // Add the node_view column.
  db_add_field($ret, 'uc_node_checkout_types', 'node_view', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''));

  // Add the uc_node_checkout_order_products table.
  $table = array(
    'fields' => array(
      'nid' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'order_product_id' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'primary key' => array('nid'),
  );

  db_create_table($ret, 'uc_node_checkout_order_products', $table);

  return $ret;
}
