Index: location.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/location/location.install,v
retrieving revision 1.2.2.4
diff -u -F^f -r1.2.2.4 location.install
--- location.install	5 Jan 2007 02:34:23 -0000	1.2.2.4
+++ location.install	10 Jan 2007 00:41:39 -0000
@@ -8,6 +8,7 @@ function location_install() {
       db_query("
       CREATE TABLE {location} (
         eid int unsigned NOT NULL default '0',
+        lid int(10) unsigned NOT NULL default '0',
         type varchar(6) NOT NULL default '',
         name varchar(255) default NULL,
         street varchar(255) default NULL,
@@ -19,7 +20,8 @@ function location_install() {
         latitude decimal(10,6) default NULL,
         longitude decimal(10,6) default NULL,
         source tinyint default '0',
-        PRIMARY KEY  (type,eid)
+        is_primary tinyint(1) NOT NULL default '0',
+        PRIMARY KEY  (lid)
       ) /*!40100 DEFAULT CHARACTER SET utf8 */;
       ");
     
@@ -46,6 +48,7 @@ function location_install() {
     case 'pgsql':
       db_query("CREATE TABLE {location} (
         eid int NOT NULL default '0' CHECK (eid >= 0),
+        lid int NOT NULL default '0' CHECK (eid >= 0),
         type varchar(6) NOT NULL default '',
         name varchar(255) default NULL,
         street varchar(255) default NULL,
@@ -57,7 +60,8 @@ function location_install() {
         latitude decimal(10,6) default NULL,
         longitude decimal(10,6) default NULL,
         source smallint default '0',
-        PRIMARY KEY (type,eid)
+        is_primary smallint default '0',
+        PRIMARY KEY (lid)
       )");
     
       db_query("CREATE TABLE {zipcodes} (
@@ -82,6 +86,9 @@ function location_install() {
       break;
   } // End case
 
+  db_query("DELETE FROM {sequences} WHERE name = '{location}_lid'");
+  db_query("INSERT INTO {sequences} (name, id) VALUES ('{location}_lid', 0)");
+
   if ($success) {
     drupal_set_message(t('Location module installed tables successfully. If you would also like a database of zip codes, please manually import the appropriate zipcode.XX.YYYY file(s) in the %module directory.', array('%module' => drupal_get_path('module', 'location') . '/database')));
   }
@@ -160,3 +167,41 @@ function location_update_4() {
   
   return $ret;
 }
+
+
+// Poor PostgreSQL
+// I forgot all about you in the previous update
+function location_update_5() {
+  $ret = array();
+  
+  switch ($GLOBALS['db_type']) {
+    case 'pgsql':
+      $ret[] = update_sql("ALTER TABLE {location} ADD COLUMN lid int NOT NULL default '0' CHECK (eid >= 0)");
+      
+      $result = db_query("SELECT eid, type FROM {location}");
+      $next_id = 0;
+      while ($row = db_fetch_object($result)) {
+        $next_id++;
+        db_query("UPDATE {location} SET lid = %d WHERE eid = %d AND type = '%s'", $next_id, $row->eid, $row->type);
+      }
+      
+      $ret[] = update_sql("ALTER TABLE {location}_KEY DROP CONSTRAINT {location}_TYPE_PKEY CASCADE;");
+      $ret[] = update_sql("ALTER TABLE {location} ADD PRIMARY KEY (lid)");
+      
+      db_query("INSERT INTO {sequences} (name, id) VALUES ('{location}_lid', %d)", $next_id);
+      $ret[] = update_sql("ALTER TABLE {location} ADD COLUMN is_primary smallint default '0'");
+      $ret[] = update_sql("UPDATE {location} SET is_primary = 1 WHERE type = 'user'");
+
+      break;
+  }
+  
+  // The following is commented out as it was executed in the previous update irrespective of DB type
+  //foreach (node_get_types() as $type => $name) {
+    //$new_setting = variable_get('location_'. $type, 0) ? 1 : 0;
+    //variable_del('location_'. $type);
+    //variable_set('location_maxnum_'. $type, $new_setting);
+    //variable_set('location_defaultnum_'. $type, $new_setting);
+  //}
+  
+  return $ret;
+}
\ No newline at end of file
