Index: trunk/Nebulous-Server/lib/Nebulous/Server/SQL.pm
===================================================================
--- trunk/Nebulous-Server/lib/Nebulous/Server/SQL.pm	(revision 16181)
+++ trunk/Nebulous-Server/lib/Nebulous/Server/SQL.pm	(revision 16244)
@@ -1,5 +1,5 @@
 # Copyright (c) 2004  Joshua Hoblitt
 #
-# $Id: SQL.pm,v 1.43 2008-01-22 21:27:46 jhoblitt Exp $
+# $Id: SQL.pm,v 1.44 2008-01-26 02:04:46 jhoblitt Exp $
 
 package Nebulous::Server::SQL;
@@ -35,10 +35,5 @@
     },
     delete_object       => qq{
-        DELETE
-            storage_object,
-            storage_object_attr 
-        FROM storage_object
-        JOIN storage_object_attr
-            USING (so_id)
+        DELETE FROM storage_object
         WHERE storage_object.so_id = ?
     },
@@ -310,4 +305,5 @@
 CREATE TABLE storage_object_attr (
     so_id BIGINT NOT NULL AUTO_INCREMENT,
+    FOREIGN KEY(so_id) REFERENCES storage_object(so_id) ON DELETE CASCADE,
     read_lock TINYINT DEFAULT 0 NOT NULL,
     write_lock ENUM( 'write' ),
@@ -321,4 +317,5 @@
 CREATE TABLE storage_object_xattr (
     so_id BIGINT NOT NULL AUTO_INCREMENT,
+    FOREIGN KEY(so_id) REFERENCES storage_object(so_id) ON DELETE CASCADE,
     name VARCHAR(255),
     value BLOB,
@@ -331,4 +328,5 @@
     ins_id BIGINT NOT NULL AUTO_INCREMENT,
     so_id BIGINT NOT NULL,
+    FOREIGN KEY(so_id) REFERENCES storage_object(so_id),
     vol_id INT NOT NULL,
     uri VARCHAR(255) NOT NULL UNIQUE,
@@ -347,4 +345,5 @@
 CREATE TABLE lock_record (
     so_id BIGINT NOT NULL,
+    FOREIGN KEY(so_id) REFERENCES storage_object(so_id),
     type ENUM( 'read', 'write' ) NOT NULL,
     epoch TIMESTAMP,
@@ -363,4 +362,5 @@
     PRIMARY KEY(vol_id),
     KEY(name(16)),
+    KEY(path(255)),
     KEY(allocate),
     KEY(available)
@@ -391,9 +391,12 @@
 CREATE TABLE mountedvol(
     mountpoint VARCHAR(255) NOT NULL,
+    FOREIGN KEY(mountpoint) REFERENCES mount(mountpoint),
     total BIGINT NOT NULL,
     used BIGINT NOT NULL,
     vol_id INT NOT NULL,
+    FOREIGN KEY(vol_id) REFERENCES volume(vol_id),
     name VARCHAR(255) NOT NULL,
     path VARCHAR(255) NOT NULL,
+    FOREIGN KEY(path) REFERENCES volume(path),
     allocate BOOLEAN DEFAULT FALSE,
     available BOOLEAN DEFAULT FALSE,
