? type.diff Index: content-type.sql =================================================================== RCS file: /cvsroot/openacs-4/packages/acs-content-repository/sql/postgresql/content-type.sql,v retrieving revision 1.48 diff -u -r1.48 content-type.sql --- content-type.sql 25 Sep 2006 20:25:19 -0000 1.48 +++ content-type.sql 29 Jan 2007 07:17:39 -0000 @@ -119,6 +119,33 @@ item_row record; begin + -- If we are dealing with a revision, delete the revision with revision__delete + -- This way the integrity constraint with live revision is dealt with correctly + + -- (jiml) lets drop the objects before anything else (they ARE created last) + + if drop_type__drop_objects_p then + -- get rid of revisions + for revision_row in + select revision_id + from cr_revisions, acs_objects + where revision_id = object_id + and object_type = drop_type__content_type + loop + PERFORM content_revision__delete(revision_row.revision_id); + end loop; + + -- get rid of items + for item_row in + select item_id + from cr_items + where content_type = drop_type__content_type + loop + PERFORM content_item__delete(item_row.item_id); + end loop; + + end if; + -- first we''ll rid ourselves of any dependent child types, if any , -- along with their own dependent grandchild types @@ -163,6 +190,10 @@ ); end LOOP; + -- now we remove the views/trigger/rule + + PERFORM content_type__drop_view(drop_type__content_type); + -- we''ll remove the associated table if it exists select table_exists(lower(table_name)) into table_exists_p @@ -179,42 +210,10 @@ where object_type = drop_type__content_type; - -- drop the rule and input/output views for the type - -- being dropped. - -- FIXME: this did not exist in the oracle code and it needs to be - -- tested. Thanks to Vinod Kurup for pointing this out. - -- The rule dropping might be redundant as the rule might be dropped - -- when the view is dropped. - - -- different syntax for dropping a rule in 7.2 and 7.3 so check which - -- version is being used (olah). - execute ''drop table '' || v_table_name || '' cascade''; end if; - -- If we are dealing with a revision, delete the revision with revision__delete - -- This way the integrity constraint with live revision is dealt with correctly - if drop_type__drop_objects_p then - for revision_row in - select revision_id - from cr_revisions, acs_objects - where revision_id = object_id - and object_type = drop_type__content_type - loop - PERFORM content_revision__delete(revision_row.revision_id); - end loop; - - for item_row in - select item_id - from cr_items - where content_type = drop_type__content_type - loop - PERFORM content_item__delete(item_row.item_id); - end loop; - - end if; - PERFORM acs_object_type__drop_type(drop_type__content_type, drop_type__drop_objects_p); return 0; @@ -261,7 +260,12 @@ where supertype = drop_type__content_type LOOP - PERFORM content_type__drop_type(child_rec.object_type, ''t'', ''f''); + PERFORM content_type__drop_type + ( + child_rec.object_type, + ''t'', + drop_type__drop_table_p + ); end LOOP; end if; @@ -288,6 +292,8 @@ where object_type = drop_type__content_type; + PERFORM content_type__drop_view(drop_type__content_type); + if table_exists_p and drop_type__drop_table_p then select table_name into v_table_name @@ -296,26 +302,6 @@ where object_type = drop_type__content_type; - -- drop the rule and input/output views for the type - -- being dropped. - -- FIXME: this did not exist in the oracle code and it needs to be - -- tested. Thanks to Vinod Kurup for pointing this out. - -- The rule dropping might be redundant as the rule might be dropped - -- when the view is dropped. - - -- different syntax for dropping a rule in 7.2 and 7.3 so check which - -- version is being used (olah). - - if version() like ''%PostgreSQL 7.2%'' then - execute ''drop rule '' || v_table_name || ''_r''; - else - -- 7.3 syntax - execute ''drop rule '' || v_table_name || ''_r '' || ''on '' || v_table_name || ''i''; - end if; - - execute ''drop view '' || v_table_name || ''x''; - execute ''drop view '' || v_table_name || ''i''; - execute ''drop table '' || v_table_name; end if; @@ -739,6 +725,60 @@ end;' language 'plpgsql'; +select define_function_args('content_type__drop_trigger','content_type'); + +create or replace function content_type__drop_trigger (varchar) +returns integer as ' +declare + drop_trigger__content_type alias for $1; + + result integer default 1; + v_table_name varchar default ''''; +begin + select table_name + into v_table_name + from acs_object_types + where object_type = drop_trigger__content_type; + + result := content_type__drop_rule(drop_trigger__content_type); + + if(result) then + execute + ''drop function '' || + v_table_name || ''_f'' || + '' ('' || + v_table_name || ''i'' || + '');''; + end if; + + return result; +end; +' language 'plpgsql'; + + +select define_function_args('content_type__drop_rule','content_type'); + +create or replace function content_type__drop_rule (varchar) +returns integer as ' +declare + drop_rule__content_type alias for $1; + + v_table_name varchar; + result integer default 1; +begin + select table_name into v_table_name from acs_object_types + where object_type = drop_rule__content_type; + + execute + ''drop rule '' || + v_table_name || ''_r '' || + ''on '' || + v_table_name || ''i''; + + return result; +end; +' language 'plpgsql'; + select define_function_args('content_type__refresh_view','content_type'); create or replace function content_type__refresh_view (varchar) @@ -815,8 +855,9 @@ execute ''drop view '' || v_table_name || ''x''; end if; - execute ''create view '' || v_table_name || - ''x as select acs_objects.object_id, + execute + ''create view '' || v_table_name || ''x'' || + '' as select acs_objects.object_id, acs_objects.object_type, acs_objects.title as object_title, acs_objects.package_id as object_package_id, @@ -847,6 +888,36 @@ return 0; end;' language 'plpgsql'; + +select define_function_args('content_type__drop_view','content_type'); + +create or replace function content_type__drop_view(varchar) +returns integer as ' +declare + drop_view__content_type alias for $1; + result integer; + v_drop_trigger_result integer default 1; + v_table_name varchar; +begin + v_drop_trigger_result := + content_type__drop_trigger(drop_view__content_type); + + result := v_drop_trigger_result; + + select table_name into v_table_name from acs_object_types + where object_type = drop_view__content_type; + + if (result) then + -- now we can drop the views; do it + execute ''drop view '' || v_table_name || ''i'' || '';''; + execute ''drop view '' || v_table_name || ''x'' || '';''; + end if; + + return result; +end; +' language 'plpgsql'; + + select define_function_args('content_type__register_child_type','parent_type,child_type,relation_tag;generic,min_n;0,max_n'); -- procedure register_child_type