Index: openacs-4/packages/acs-kernel/sql/postgresql/acs-objects-create.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-kernel/sql/postgresql/acs-objects-create.sql,v
diff -u -r1.71.2.4 -r1.71.2.5
--- openacs-4/packages/acs-kernel/sql/postgresql/acs-objects-create.sql	15 Nov 2019 14:43:09 -0000	1.71.2.4
+++ openacs-4/packages/acs-kernel/sql/postgresql/acs-objects-create.sql	24 Mar 2021 09:51:12 -0000	1.71.2.5
@@ -249,6 +249,14 @@
 	unique (context_id, object_id)
 );
 
+--
+-- Avoid potential loops on context_ids. A context_id must be
+-- different from the object_id. If no context_id should be checked, its
+-- value must be NULL. Note that this constraint is not guaranteed to
+-- avoid all loops; it is still possible to create indirect recursive
+-- loops but excludes some real-world problems.
+ALTER TABLE acs_objects ADD CONSTRAINT acs_objects_context_id_ck CHECK (context_id != object_id);
+
 -- The unique constraint above will force create of this index...
 -- create index acs_objects_context_object_idx onacs_objects (context_id, object_id);
 
@@ -262,6 +270,7 @@
 
 create index acs_objects_object_type_idx on acs_objects (object_type);
 
+
 CREATE OR REPLACE FUNCTION acs_objects_mod_ip_insert_tr () RETURNS trigger AS $$
 BEGIN
   new.modifying_ip := new.creation_ip;
