Index: openacs-4/packages/acs-kernel/sql/postgresql/upgrade/upgrade-5.10.1d11-5.10.1d12.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-kernel/sql/postgresql/upgrade/upgrade-5.10.1d11-5.10.1d12.sql,v diff -u -r1.1.2.1 -r1.1.2.2 --- openacs-4/packages/acs-kernel/sql/postgresql/upgrade/upgrade-5.10.1d11-5.10.1d12.sql 8 Oct 2022 20:07:17 -0000 1.1.2.1 +++ openacs-4/packages/acs-kernel/sql/postgresql/upgrade/upgrade-5.10.1d11-5.10.1d12.sql 27 Oct 2022 09:00:31 -0000 1.1.2.2 @@ -19,7 +19,28 @@ -- -- Drop the two (!) materialized views for the privilege hierarchy. -- -DROP TABLE IF EXISTS acs_privilege_descendant_map; + +-- +-- In case the script was already executed, the DROP TABLE IF EXISTS +-- will lead to an error that "acs_privilege_descendant_map" is not a table +-- HINT: Use DROP VIEW to remove a view. +-- So, we apply here the old fashioned approach by querying pg_tables. +-- +DO $$ +DECLARE + v_found boolean; +BEGIN + SELECT EXISTS ( + SELECT 1 FROM pg_tables WHERE + schemaname = 'public' AND + tablename = 'acs_privilege_descendant_map' + ) into v_found; + + if v_found IS TRUE then + DROP TABLE acs_privilege_descendant_map; + end if; +END $$; + DROP TABLE IF EXISTS acs_privilege_hierarchy_index CASCADE; DROP TRIGGER IF EXISTS acs_priv_hier_ins_del_tr ON acs_privilege_hierarchy;