--- /Users/lordscott/Downloads/contemplate/contemplate.install	2008-02-28 14:05:38.000000000 -0500
+++ /Users/lordscott/Sites/thinkyhead/drupal/sites/all/modules/contemplate/contemplate.install	2008-12-09 23:00:40.000000000 -0500
@@ -1,84 +1,64 @@
 <?php
 // $Id: contemplate.install,v 1.5.2.2 2008/02/28 19:05:38 jrglasgow Exp $
+/**
+ * @file
+ * Contains install and update functions for ConTemplate.
+ */
 
 function contemplate_install() {
-  switch ($GLOBALS['db_type']) {
-  case 'mysql':
-  case 'mysqli':
-    db_query("CREATE TABLE {contemplate} (
-      type varchar(32) NOT NULL default '',
-      teaser text NOT NULL,
-      body text NOT NULL,
-      rss text NOT NULL,
-      enclosure varchar(128) NOT NULL,
-      flags int(8) unsigned NOT NULL default '7',
-      KEY type (type)
-      ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
-    db_query("CREATE TABLE {contemplate_files} (
-      site varchar(255) NOT NULL,
-      `data` longblob NOT NULL,
-      UNIQUE KEY site (site(255))
-      ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
-    db_query("UPDATE {system} SET weight = 10 WHERE name = 'contemplate'");
-    break;
-  case 'pgsql':
-    db_query("CREATE TABLE {contemplate} (
-      type varchar(32) NOT NULL default '',
-      teaser text NOT NULL,
-      body text NOT NULL,
-      rss text NOT NULL,
-      enclosure varchar(128) NOT NULL,
-      flags int_unsigned NOT NULL default '0',
-      PRIMARY KEY (type)
-      );");
-
-    db_query("CREATE TABLE {contemplate_files} (
-      site varchar(255) NOT NULL,
-      data bytea NOT NULL
-      );");  // This code is untested. Please post a fix to the issue queue if incorrect
-
-    db_query("CREATE UNIQUE INDEX {contemplate_files}_site_idx ON {contemplate_files} (site)");
-    db_query("UPDATE {system} SET weight = 10 WHERE name = 'contemplate'");
-    break;
-  }
-   drupal_set_message(t('Database tables for ConTemplate module have been installed.'));
- }
-
-function contemplate_update_1() {
-  $ret = array();
+  drupal_install_schema('contemplate');
+}
 
-  switch ($GLOBALS['db_type']) {
-    case 'mysql':
-    case 'mysqli':
-      $ret[] = update_sql('ALTER TABLE {contemplate} ADD rss text NOT NULL');
-      $ret[] = update_sql('ALTER TABLE {contemplate} ADD enclosure varchar(128) NOT NULL');
-      $ret[] = update_sql("ALTER TABLE {contemplate} ADD flags int(8) unsigned NOT NULL default '7'");
-      break;
-    }
+function contemplate_uninstall() {
+  drupal_uninstall_schema('contemplate');
+}
 
-  return $ret;
+/**
+ * Implementation of hook_schema().
+ */
+function contemplate_schema() {
+  // Currently, schema 1 is the only schema we have. As we make updates,
+  // we might either create a new schema 2 or make adjustments here.
+  return contemplate_schema_1();
 }
 
-function contemplate_update_2() {
-  $ret = array();
+/**
+ * Contemplate's initial schema; separated for the purposes of updates.
+ */
+function contemplate_schema_1() {
+  $schema['contemplate'] = array(
+    'fields' => array(
+      'type' => array('type' => 'varchar', 'length' => '32', 'not null' => TRUE, 'default' => ''),
+      'teaser' => array('type' => 'text', 'not null' => TRUE),
+      'body' => array('type' => 'text', 'not null' => TRUE),
+      'rss' => array('type' => 'text', 'not null' => TRUE),
+      'enclosure' => array('type' => 'varchar', 'length' => '128', 'not null' => TRUE),
+      'flags' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 7, 'disp-width' => '8')
+    ),
+    'indexes' => array('type' => array('type')),
+  );
+  $schema['contemplate_files'] = array(
+    'fields' => array(
+      'site' => array('type' => 'varchar', 'length' => '255', 'not null' => TRUE),
+      'data' => array('type' => 'blob', 'size' => 'big', 'not null' => TRUE)
+    ),
+    'unique keys' => array('site' => array('site')),
+  );
+  return $schema;
+}
 
-  switch ($GLOBALS['db_type']) {
-    case 'mysql':
-    case 'mysqli':
-      $ret[] = update_sql('CREATE TABLE {contemplate_files} (
-      site varchar(255) NOT NULL,
-      data longblob NOT NULL,
-      UNIQUE KEY site (site(255))
-      ) /*!40100 DEFAULT CHARACTER SET utf8 */;');
-      break;
-    }
+/**
+ * Update a site to Drupal 6!
+ */
+function contemplate_update_6000() {
+  // This is mostly the same as drupal_install_schema, but it forces
+  // contemplate_schema_1 rather than the default schema. This will be important
+  // if we have table updates.
+  $schema = contemplate_schema_1();
+  _drupal_initialize_schema('contemplate', $schema);
 
+  foreach ($schema as $name => $table) {
+    db_create_table($ret, $name, $table);
+  }
   return $ret;
-
 }
-
-function contemplate_uninstall() {
-  db_query('DROP TABLE {contemplate}');
-  db_query('DROP TABLE {contemplate_files}');
-  drupal_set_message(t('The ConTemplate tables have been removed from the database'));
-}
\ No newline at end of file
