Index: openacs-4/packages/acs-kernel/sql/postgresql/upgrade/upgrade-5.0d7-5.0d9.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-kernel/sql/postgresql/upgrade/upgrade-5.0d7-5.0d9.sql,v
diff -u -r1.4 -r1.5
--- openacs-4/packages/acs-kernel/sql/postgresql/upgrade/upgrade-5.0d7-5.0d9.sql	30 Sep 2003 09:45:27 -0000	1.4
+++ openacs-4/packages/acs-kernel/sql/postgresql/upgrade/upgrade-5.0d7-5.0d9.sql	26 Jan 2004 15:39:45 -0000	1.5
@@ -5,13 +5,10 @@
 -- *** Remove a column not needed
 -- See http://openacs.org/bugtracker/openacs/bug?bug%5fnumber=555
 -- Seems PG 7.2 doesn't support this
--- alter table apm_packages drop enabled_p;
+alter table apm_packages drop enabled_p;
 
--- *** Get rid of file-related data no longer used
-drop table apm_package_file_types;
-drop table apm_package_files;
 -- View was dropped by previous drop
---drop view apm_file_info;
+drop view apm_file_info;
 drop function apm_package_version__add_file (integer,integer,varchar,varchar, varchar);
 drop function apm_package_version__remove_file (integer,varchar);
 drop function apm_package__disable (integer);
@@ -63,3 +60,75 @@
 	-- return 0;
    
 end;' language 'plpgsql';
+
+create or replace function apm_package_version__delete (integer)
+returns integer as '
+declare
+  delete__version_id             alias for $1;  
+begin
+      delete from apm_package_owners 
+      where version_id = delete__version_id; 
+
+      delete from apm_package_dependencies
+      where version_id = delete__version_id;
+
+      delete from apm_package_versions 
+	where version_id = delete__version_id;
+
+      PERFORM acs_object__delete(delete__version_id);
+
+      return 0; 
+end;' language 'plpgsql';
+
+create or replace function apm_package_version__copy (integer,integer,varchar,varchar,boolean)
+returns integer as '
+declare
+  copy__version_id             alias for $1;  
+  copy__new_version_id         alias for $2;  -- default null  
+  copy__new_version_name       alias for $3;  
+  copy__new_version_uri        alias for $4;  
+  copy__copy_owners_p          alias for $5;
+  v_version_id                 integer;       
+begin
+	v_version_id := acs_object__new(
+		copy__new_version_id,
+		''apm_package_version'',
+                now(),
+                null,
+                null,
+                null
+        );    
+
+	insert into apm_package_versions(version_id, package_key, version_name,
+					version_uri, summary, description_format, description,
+					release_date, vendor, vendor_uri, auto_mount)
+	    select v_version_id, package_key, copy__new_version_name,
+		   copy__new_version_uri, summary, description_format, description,
+		   release_date, vendor, vendor_uri, auto_mount
+	    from apm_package_versions
+	    where version_id = copy__version_id;
+    
+	insert into apm_package_dependencies(dependency_id, version_id, dependency_type, service_uri, service_version)
+	    select nextval(''t_acs_object_id_seq''), v_version_id, dependency_type, service_uri, service_version
+	    from apm_package_dependencies
+	    where version_id = copy__version_id;
+    
+        insert into apm_package_callbacks (version_id, type, proc)
+                select v_version_id, type, proc
+                from apm_package_callbacks
+                where version_id = copy__version_id;
+    
+        if copy__copy_owners_p then
+            insert into apm_package_owners(version_id, owner_uri, owner_name, sort_key)
+                select v_version_id, owner_uri, owner_name, sort_key
+                from apm_package_owners
+                where version_id = copy__version_id;
+        end if;
+    
+	return v_version_id;
+   
+end;' language 'plpgsql';
+
+-- *** Get rid of file-related data no longer used
+drop table apm_package_file_types;
+drop table apm_package_files;
