Index: openacs-4/packages/acs-kernel/sql/postgresql/upgrade/upgrade-5.3.0d1-5.3.0d2.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-kernel/sql/postgresql/upgrade/upgrade-5.3.0d1-5.3.0d2.sql,v
diff -u -r1.1 -r1.2
--- openacs-4/packages/acs-kernel/sql/postgresql/upgrade/upgrade-5.3.0d1-5.3.0d2.sql	24 Sep 2006 08:16:37 -0000	1.1
+++ openacs-4/packages/acs-kernel/sql/postgresql/upgrade/upgrade-5.3.0d1-5.3.0d2.sql	24 Sep 2006 09:26:36 -0000	1.2
@@ -1,2 +1,40 @@
 alter table acs_object_types alter column table_name drop not null;
-alter table acs_object_types alter column id_column drop not null;
\ No newline at end of file
+alter table acs_object_types alter column id_column drop not null;
+
+create or replace function apm_package__delete (integer) returns integer as '
+declare
+   delete__package_id   alias for $1;
+   cur_val              record;
+   v_folder_row         record;
+begin
+    -- Delete all parameters.
+    for cur_val in select value_id from apm_parameter_values
+	where package_id = delete__package_id loop
+    	PERFORM apm_parameter_value__delete(cur_val.value_id);
+    end loop;    
+
+   -- Delete the folders
+    for v_folder_row in select
+        folder_id
+        from cr_folders
+        where package_id = delete__package_id
+    loop
+        perform content_folder__del(v_folder_row.folder_id,''t'');
+    end loop;
+
+    delete from apm_applications where application_id = delete__package_id;
+    delete from apm_services where service_id = delete__package_id;
+    delete from apm_packages where package_id = delete__package_id;
+    -- Delete the site nodes for the objects.
+    for cur_val in select node_id from site_nodes
+	where object_id = delete__package_id loop
+    	PERFORM site_node__delete(cur_val.node_id);
+    end loop;
+
+    -- Delete the object.
+    PERFORM acs_object__delete (
+       delete__package_id
+    );   
+
+    return 0;
+end;' language 'plpgsql';
