--- /var/www/media_mover/media_mover_api.install	2008-09-03 10:27:46.000000000 -0400
+++ media_mover_api.install	2008-09-22 03:04:59.000000000 -0400
@@ -2,245 +2,118 @@
 
 /* $Id: media_mover_api.install,v 1.1.2.16 2008/09/03 14:27:46 arthuregg Exp $ */
 
-/*
- @ TODO make psql correct
+/**
+ * @FILE media mover db files
+ * NOTE, this will only upgrade a D5 version of media mover from the  > 1-0-BETA1 release
 */
 
 // media_mover.install
 
-function media_mover_api_install() {
-  switch ($GLOBALS['db_type']) {
-    case 'mysqli':
-    case 'mysql':
-      db_query("CREATE TABLE {media_mover_files} (
-        `mmfid` int(11) DEFAULT NULL,
-        `nid` int(11) DEFAULT NULL,
-        `fid` int(11) NOT NULL DEFAULT 0,
-        `cid` int(11) DEFAULT NULL,
-        `harvest_file` varchar(255) DEFAULT NULL,
-        `harvest_type` varchar(20) NOT NULL DEFAULT 'local',
-        `process_file` varchar(255) DEFAULT NULL,
-        `storage_file` varchar(255) DEFAULT NULL,
-        `complete_file` VARCHAR(225) DEFAULT NULL,
-        `url` varchar(255) NOT NULL DEFAULT '',
-        `status` VARCHAR(48) NOT NULL DEFAULT '',
-        `date` int(11) DEFAULT NULL,
-        `data` blob NOT NULL,
-        PRIMARY KEY  (`mmfid`)
-       ) DEFAULT CHARACTER SET=utf8");
-
-      // stores the configuration config data
-      db_query("CREATE TABLE {media_mover_configurations} (
-        `cid` int(11) NOT NULL default '0',
-        `verb` varchar(128) DEFAULT null,
-        `module` varchar(255) NOT NULL default '',
-        `action` varchar(255) NOT NULL default '',
-        `configuration` blob NOT NULL
-        )");
-
-      // stores the configuration meta data
-      db_query("CREATE TABLE {media_mover_config_list} (
-        `cid` int(11) NOT NULL default '0',
-        `name` varchar(255) default NULL,
-        `description` varchar(255) default NULL,
-        `status` VARCHAR(48) NOT NULL default 'disabled',
-        `start_time` int(11) NOT null DEFAULT 0,
-        `last_start_time` int(11) NOT null DEFAULT 0,
-        `settings` blob NOT null,
-        `cron` int(2) NOT null DEFAULT 0,
-        `weight` int(3) NOT null DEFAULT 0,
-        PRIMARY KEY  (`cid`)
-      ) DEFAULT CHARACTER SET=utf8");
-      
-      // create a cache 
-      db_query("CREATE TABLE IF NOT EXISTS {cache_media_mover} (
-        `cid` varchar(255) NOT NULL default '',
-        `data` longblob,
-        `expire` int(11) NOT NULL default '0',
-        `created` int(11) NOT NULL default '0',
-        `headers` text,
-        PRIMARY KEY  (`cid`),
-        KEY `expire` (`expire`)
-      ) ENGINE=MyISAM DEFAULT CHARSET=utf8;");
-      break;
-
-    //@TODO pgsql
-    case 'pgsql':
-    break;
-  }
+/**
+* Implementation of hook_install().
+*/
+function media_mover_install() {
+  // Create tables.
+  drupal_install_schema('media_mover_api');
 }
 
+
 /**
  * Implementation of hook_uninstall
  * deletes all media mover tables
  */
 function media_mover_api_uninstall() {
-  db_query('DROP TABLE {media_mover_files}');
-  db_query('DROP TABLE {media_mover_configurations}');
-  db_query('DROP TABLE {media_mover_config_list}');
-}
-
-/**
- * addes a status col to the configuration table
- */
-function media_mover_api_update_1() {
-  switch ($GLOBALS['db_type']) {
-    case 'mysqli':
-    case 'mysql':
-     $ret[] =  update_sql("ALTER TABLE {media_mover_config_list} CHANGE status status VARCHAR(48) NOT NULL DEFAULT 'disabled'");
-    break;
-  }
-
-  return $ret;
-}
-
-/**
- * adds data col to the files table
- */
-function media_mover_api_update_2() {
-  switch ($GLOBALS['db_type']) {
-    case 'mysqli':
-    case 'mysql':
-      $ret[] = update_sql('ALTER TABLE {media_mover_files} ADD data BLOB NOT NULL AFTER status');
-    break;
-  }
-  return $ret;
-}
-
-/**
- * Creates the file harvest comparison table
- */
-function media_mover_api_update_3() {
-  switch ($GLOBALS['db_type']) {
-    case 'mysqli':
-    case 'mysql':
-      $ret[] = update_sql('ALTER TABLE {media_mover_config_list} ADD start_time int(11) NOT null DEFAULT 0 AFTER status');
-      $ret[] = update_sql('ALTER TABLE {media_mover_config_list} ADD last_start_time int(11) NOT null DEFAULT 0 AFTER start_time');
-
-    break;
-  }
-  if ($ret) {return $ret;}
-}
-
-/**
- * adds data col to the files table
- */
-function media_mover_api_update_4() {
-  switch ($GLOBALS['db_type']) {
-    case 'mysqli':
-    case 'mysql':
-      $ret[] = update_sql('ALTER TABLE {media_mover_files} ADD mmfid int(11) DEFAULT null FIRST');
-      $ret[] = update_sql('ALTER TABLE {media_mover_files} DROP INDEX nid');
-      $ret[] = update_sql('ALTER TABLE {media_mover_files} DROP PRIMARY KEY');
-    break;
-  }
-  return $ret;
-}
-
-/**
- * increases the size of the file tables
- */
-function media_mover_api_update_5() {
-  switch ($GLOBALS['db_type']) {
-    case 'mysqli':
-    case 'mysql':
-      $ret[] = update_sql('ALTER TABLE {media_mover_files} CHANGE `harvest_file` `harvest_file` VARCHAR( 225 ) ');
-      $ret[] = update_sql('ALTER TABLE {media_mover_files} CHANGE `process_file` `process_file` VARCHAR( 225 ) ');
-      $ret[] = update_sql('ALTER TABLE {media_mover_files} CHANGE `storage_file` `storage_file` VARCHAR( 225 ) ');
-    break;
-  }
-  return $ret;
-}
-
-/**
- * add the completion stuff
- */
-function media_mover_api_update_6() {
-  switch ($GLOBALS['db_type']) {
-    case 'mysqli':
-    case 'mysql':
-      $ret[] = update_sql('ALTER TABLE {media_mover_files} ADD `complete_file` VARCHAR(225) NOT NULL AFTER `storage_file`');
-      $ret[] = update_sql('ALTER TABLE {media_mover_files} ADD `complete_action` VARCHAR(225) NOT NULL AFTER `storage_file`');
-      $ret[] = update_sql('ALTER TABLE {media_mover_files} ADD `complete_module` VARCHAR(225) NOT NULL AFTER `storage_file` ');
-    break;
-  }
-  return $ret;
+  drupal_uninstall_schema('media_mover_api');
 }
 
 
 /**
- * add dates for when files were harvested
+ * implementation of hook_schema()
  */
-function media_mover_api_update_9() {
-  switch ($GLOBALS['db_type']) {
-    case 'mysqli':
-    case 'mysql':
-      $ret[] = update_sql('ALTER TABLE {media_mover_files} ADD `date` int(11) DEFAULT 0 AFTER `status`');
-      $ret[] = update_sql('UPDATE {media_mover_files} SET date = '. time() .' WHERE date = 0');
-    break;
+function media_mover_api_schema() {
+  $schema['media_mover_files'] = array(
+    'fields' => array (
+      'mmfid' => array('type' => 'serial'),
+      'nid' => array('type' => 'int', 'unsigned' => TRUE),
+      'fid' => array('type' => 'int', 'unsigned' => TRUE),
+      'cid' => array('type' => 'int', 'unsigned' => TRUE),
+      'harvest_file' => array('type' => 'varchar', 'length' => 255, 'default' => ''),
+      'process_file' => array('type' => 'varchar', 'length' => 255, 'default' => ''),
+      'storage_file' => array('type' => 'varchar', 'length' => 255, 'default' => ''),
+      'complete_file' => array('type' => 'varchar', 'length' => 225, 'default' => ''),
+      'status' => array('type' => 'int', 'unsigned' => TRUE),
+      'date' => array('type' => 'int', 'unsigned' => TRUE),
+      'data' => array('type' => 'text', 'size' => 'medium'),    
+    ),
+    'indexes' => array (
+      'mmfid' => array('mmfid'),
+      'nid' => array('nid'),
+    ),    
+    'primary key' => array ('mmfid'),
+  );
+  
+  $schema['media_mover_configurations'] = array(
+    'fields' => array (
+      'cid'  => array('type' => 'int', 'int', 'unsigned' => TRUE, 'description' => 'Configuration id'),
+      'verb'  => array('type' => 'varchar', 'length' => 255, 'default' => ''),
+      'module'  => array('type' => 'varchar', 'length' => 255, 'default' => ''),
+      'action'  => array('type' => 'varchar', 'length' => 255, 'default' => ''),
+      'configuration'  => array('type' => 'text', 'size' => 'medium'),
+    ),
+    'indexes' => array (
+      'cid' => array('cid'),
+    ),    
+  );
+  
+  $schema['media_mover_config_list'] = array(
+    'fields' => array (
+      'cid'  => array('type' => 'serial'),
+      'name'  => array('type' => 'varchar', 'length' => 255, 'default' => ''),
+      'description'  => array('type' => 'text', 'size' => 'normal'),
+      'status'  => array('type' => 'varchar', 'length' => 255, 'default' => ''),
+      'start_time'  => array('type' => 'int', 'unsigned' => TRUE),
+      'last_start_time'  => array('type' => 'int', 'unsigned' => TRUE),
+      'settings'  => array('type' => 'text', 'size' => 'medium'),
+      'cron'  => array('type' => 'int', 'unsigned' => TRUE),
+      'weight'  => array('type' => 'int', 'unsigned' => TRUE),
+    ),
+    'indexes' => array (
+      'cid' => array('cid'),
+    ),    
+    'primary key' => array('cid'),    
+  );
+  
+  $schema['cache_media_mover'] = array(
+    'fields' => array (
+      'cid'  => array('type' => 'text', size => 'small'),
+      'data'  => array('type' => 'text', 'size' => 'medium'),
+      'expire'  => array('type' => 'int', 'unsigned' => TRUE),
+      'created'  => array('type' => 'int', 'unsigned' => TRUE),
+      'headers'  => array('type' => 'text'),
+    ),
+    'indexes' => array (
+      'cid' => array('cid'),
+    ),    
+    'primary key' => array('cid'),
+  );
+  
+  return $schema;
+}
+
+
+/**
+ * updates for 5x -> 6x 
+ */
+function media_mover_api_update_6000() {
+  if (db_column_exists('media_mover_files', 'url')) {
+    $ret[] = update_sql('ALTER TABLE {media_mover_files} DROP url');
   }
-  return $ret;
- }
-
- /**
-  * changes the names of modules to reflect the new module naming scheme
-  */
-function media_mover_api_update_10() {
-  switch ($GLOBALS['db_type']) {
-    case 'mysqli':
-    case 'mysql':
-      $ret[] = update_sql('UPDATE {media_mover_files} SET harvest_module = "mm_node" WHERE harvest_module = "media_mover" AND harvest_action != 1');
-      $ret[] = update_sql('UPDATE {media_mover_files} SET storage_module = "mm_node" WHERE storage_module = "media_mover" AND storage_action != 1');
-      $ret[] = update_sql('UPDATE {media_mover_files} SET process_module = "mm_node" WHERE process_module = "media_mover" AND process_action != 1');
-      $ret[] = update_sql('UPDATE {media_mover_files} SET storage_module = "mm_node" WHERE storage_module = "media_mover" AND storage_action != 1');
-      $ret[] = update_sql('UPDATE {media_mover_configurations} SET module = "mm_node" WHERE module = "media_mover" AND action != 1');
-      $ret[] = update_sql('UPDATE {media_mover_configurations} SET module = "media_mover_api" WHERE module = "media_mover" AND action = 1');
-    break;
+  if (db_column_exists('media_mover_files', 'harvest_type')) {
+   $ret[] = update_sql('ALTER TABLE {media_mover_files} DROP harvest_type');
   }
   return $ret;
 }
 
-/**
- * renumbers the action id values in the mm_node module
- */
-function media_mover_api_update_11() {
-  switch ($GLOBALS['db_type']) {
-    case 'mysqli':
-    case 'mysql':
-      // move action id 6 to 1
-      $ret[] = update_sql('UPDATE {media_mover_configurations} SET action = 1 WHERE action = 6 AND module = "mm_node"');
-      $ret[] = update_sql('UPDATE {media_mover_files} SET harvest_action = 1 WHERE harvest_action = 6 AND harvest_module = "mm_node"');
-    break;
-  }
-  return $ret;
-}
-
-/**
- * drops the cols for data that can be recreated from the configuration tables
- */
-function media_mover_api_update_12() {
-  switch ($GLOBALS['db_type']) {
-    case 'mysqli':
-    case 'mysql':
-      $ret[] = update_sql('ALTER TABLE {media_mover_files} DROP harvest_module,  DROP harvest_action, DROP process_module,  DROP process_action, DROP storage_module, DROP storage_action, DROP complete_module,  DROP complete_action');
-    break;
-  }
-  return $ret;
-}
-
-/**
- * adds a rss col to a configuraiton description
- */
-function media_mover_api_update_13() {
-  switch ($GLOBALS['db_type']) {
-    case 'mysqli':
-    case 'mysql':
-      $ret[] = update_sql('ALTER TABLE {media_mover_config_list} ADD `rss` int(2) NOT NULL default "0"');
-      $ret[] = update_sql('ALTER TABLE {media_mover_config_list} ADD `cron` int(2) NOT NULL default "0"');
-    break;
-  }
-  return $ret;
-}
 
 /**
  * creates the media mover file info caches
