Index: openacs-4/packages/acs-service-contract/sql/postgresql/upgrade/upgrade-5.9.1b3-5.9.1b4.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-service-contract/sql/postgresql/upgrade/upgrade-5.9.1b3-5.9.1b4.sql,v
diff -u -N
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/acs-service-contract/sql/postgresql/upgrade/upgrade-5.9.1b3-5.9.1b4.sql	17 Mar 2017 13:40:20 -0000	1.1.2.1
@@ -0,0 +1,22 @@
+
+-- Before we were forgetting to delete acs_object. Now we exploit
+-- cascade constraint on service contract table. TODO: put cascade
+-- constraints on other tables referencing service contracts (like
+-- authorities table)
+
+CREATE OR REPLACE FUNCTION acs_sc_impl__delete(
+   p_impl_contract_name varchar,
+   p_impl_name varchar
+) RETURNS integer AS $$
+DECLARE
+   v_impl_id integer;
+BEGIN
+
+    v_impl_id := acs_sc_impl__get_id(p_impl_contract_name,p_impl_name);
+
+    perform acs_object__delete(v_impl_id);
+
+    return 0;
+
+END;
+$$ LANGUAGE plpgsql;
