<?php
// $Id: importexportapi.install,v 1.5 2006/11/05 07:03:29 jaza Exp $

/**
 * @file
 * Update file for the importexportapi module. All functions in this file are
 * implementations of hook_update_N(), unless indicated otherwise.
 */

/**
 * Implementation of hook_install().
 */
function importexportapi_install() {
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      db_query('CREATE TABLE {importexportapi_db_put_map} (
        put_map_id int(10) NOT NULL auto_increment,
        put_id int(10) NOT NULL default \'0\',
        entity varchar(255) NOT NULL default \'\',
        field varchar(255) NOT NULL default \'\',
        value_old int(10) NOT NULL default \'0\',
        value_new int(10) NOT NULL default \'0\',
        PRIMARY KEY (put_map_id),
        KEY (put_id)
        ) /*!40100 DEFAULT CHARACTER SET utf8 */
      ');
      db_query('CREATE TABLE {importexportapi_db_put_map_alt} (
        put_map_alt_id int(10) NOT NULL auto_increment,
        put_id int(10) NOT NULL default \'0\',
        entity varchar(255) NOT NULL default \'\',
        field varchar(255) NOT NULL default \'\',
        alt_field varchar(255) NOT NULL default \'\',
        value_alt varchar(255) NOT NULL default \'\',
        value_key int(10) NOT NULL default \'0\',
        PRIMARY KEY (put_map_alt_id),
        KEY (put_id)
        ) /*!40100 DEFAULT CHARACTER SET utf8 */
      ');
      break;
    case 'pgsql':
      db_query('CREATE TABLE {importexportapi_db_put_map} (
        put_map_id SERIAL,
        put_id integer NOT NULL default \'0\',
        entity varchar(255) NOT NULL default \'\',
        field varchar(255) NOT NULL default \'\',
        value_old integer NOT NULL default \'0\',
        value_new integer NOT NULL default \'0\',
        PRIMARY KEY (put_map_id)
        )
      ');
      db_query('CREATE INDEX {importexportapi_db_put_map}_put_id_idx
        ON {importexportapi_db_put_map} (put_id)
      ');
      db_query('CREATE TABLE {importexportapi_db_put_map_alt} (
        put_map_alt_id SERIAL,
        put_id integer NOT NULL default \'0\',
        entity varchar(255) NOT NULL default \'\',
        field varchar(255) NOT NULL default \'\',
        alt_field varchar(255) NOT NULL default \'\',
        value_alt varchar(255) NOT NULL default \'\',
        value_key integer NOT NULL default \'0\',
        PRIMARY KEY (put_map_alt_id)
        )
      ');
      db_query('CREATE INDEX {importexportapi_db_put_map_alt}_put_id_idx
        ON {importexportapi_db_put_map_alt} (put_id)
      ');

      break;
  }
}

function importexportapi_update_1() {
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      db_query('CREATE TABLE {importexportapi_db_put_map_alt} (
        put_map_alt_id int(10) NOT NULL auto_increment,
        put_id int(10) NOT NULL default \'0\',
        entity varchar(255) NOT NULL default \'\',
        field varchar(255) NOT NULL default \'\',
        alt_field varchar(255) NOT NULL default \'\',
        value_alt varchar(255) NOT NULL default \'\',
        value_key int(10) NOT NULL default \'0\',
        PRIMARY KEY (put_map_alt_id),
        KEY (put_id)
        ) /*!40100 DEFAULT CHARACTER SET utf8 */
      ');
      break;

    case 'pgsql':
      db_query('CREATE TABLE {importexportapi_db_put_map_alt} (
        put_map_alt_id SERIAL,
        put_id integer NOT NULL default \'0\',
        entity varchar(255) NOT NULL default \'\',
        field varchar(255) NOT NULL default \'\',
        alt_field varchar(255) NOT NULL default \'\',
        value_alt varchar(255) NOT NULL default \'\',
        value_key integer NOT NULL default \'0\',
        PRIMARY KEY (put_map_id)
        )
      ');
      db_query('CREATE INDEX {importexportapi_db_put_map_alt}_put_id_idx
        ON {importexportapi_db_put_map_alt} (put_id)
      ');
      break;
  }

  db_query('ALTER TABLE {importexportapi_put_map} RENAME TO {importexportapi_db_put_map}');

  return array();
}
