Index: /trunk/Nebulous-Server/Changes
===================================================================
--- /trunk/Nebulous-Server/Changes	(revision 16243)
+++ /trunk/Nebulous-Server/Changes	(revision 16244)
@@ -2,4 +2,5 @@
 
 0.07
+    - redo database schema with foreign keys
     - add Nebulous::Keys pod
 
Index: /trunk/Nebulous-Server/Todo
===================================================================
--- /trunk/Nebulous-Server/Todo	(revision 16243)
+++ /trunk/Nebulous-Server/Todo	(revision 16244)
@@ -7,5 +7,4 @@
 - add support for SQL and/or Apache logging
 - make copy replicate source attributes, implement as replicate/reparent?
-- redo database schema with foreign keys
 - validation of URIs
 - test that client->delete_instance removes the storage object too
Index: /trunk/Nebulous-Server/lib/Nebulous/Server.pm
===================================================================
--- /trunk/Nebulous-Server/lib/Nebulous/Server.pm	(revision 16243)
+++ /trunk/Nebulous-Server/lib/Nebulous/Server.pm	(revision 16244)
@@ -1,5 +1,5 @@
 # Copyright (c) 2004  Joshua Hoblitt
 #
-# $Id: Server.pm,v 1.49 2008-01-25 02:11:23 jhoblitt Exp $
+# $Id: Server.pm,v 1.50 2008-01-26 02:04:46 jhoblitt Exp $
 
 package Nebulous::Server;
@@ -1004,5 +1004,5 @@
             $query->finish;
             
-            # if we affected something other then one row something very bad
+            # if we affected something other then two rows something very bad
             # has happened
             unless ( $rows == 1 ) {
@@ -1019,8 +1019,6 @@
             $query->finish;
 
-            # if we affected something other then two rows something very bad
-            # has happened
-            # this will have to be changed in order to support hardlinks
-            unless ( $rows == 2 ) {
+            # TODO: this will have to be changed in order to support hardlinks
+            unless ( $rows == 1 ) {
                 $log->logdie( "affected row count is $rows instead of 2" );
             }
Index: /trunk/Nebulous-Server/lib/Nebulous/Server/SQL.pm
===================================================================
--- /trunk/Nebulous-Server/lib/Nebulous/Server/SQL.pm	(revision 16243)
+++ /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,
Index: /trunk/Nebulous/Changes
===================================================================
--- /trunk/Nebulous/Changes	(revision 16243)
+++ /trunk/Nebulous/Changes	(revision 16244)
@@ -2,4 +2,5 @@
 
 0.07
+    - redo database schema with foreign keys
     - add Nebulous::Keys pod
 
Index: /trunk/Nebulous/Todo
===================================================================
--- /trunk/Nebulous/Todo	(revision 16243)
+++ /trunk/Nebulous/Todo	(revision 16244)
@@ -7,5 +7,4 @@
 - add support for SQL and/or Apache logging
 - make copy replicate source attributes, implement as replicate/reparent?
-- redo database schema with foreign keys
 - validation of URIs
 - test that client->delete_instance removes the storage object too
Index: /trunk/Nebulous/lib/Nebulous/Server.pm
===================================================================
--- /trunk/Nebulous/lib/Nebulous/Server.pm	(revision 16243)
+++ /trunk/Nebulous/lib/Nebulous/Server.pm	(revision 16244)
@@ -1,5 +1,5 @@
 # Copyright (c) 2004  Joshua Hoblitt
 #
-# $Id: Server.pm,v 1.49 2008-01-25 02:11:23 jhoblitt Exp $
+# $Id: Server.pm,v 1.50 2008-01-26 02:04:46 jhoblitt Exp $
 
 package Nebulous::Server;
@@ -1004,5 +1004,5 @@
             $query->finish;
             
-            # if we affected something other then one row something very bad
+            # if we affected something other then two rows something very bad
             # has happened
             unless ( $rows == 1 ) {
@@ -1019,8 +1019,6 @@
             $query->finish;
 
-            # if we affected something other then two rows something very bad
-            # has happened
-            # this will have to be changed in order to support hardlinks
-            unless ( $rows == 2 ) {
+            # TODO: this will have to be changed in order to support hardlinks
+            unless ( $rows == 1 ) {
                 $log->logdie( "affected row count is $rows instead of 2" );
             }
Index: /trunk/Nebulous/lib/Nebulous/Server/SQL.pm
===================================================================
--- /trunk/Nebulous/lib/Nebulous/Server/SQL.pm	(revision 16243)
+++ /trunk/Nebulous/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,
