I'm running into some difficulty creating the drop script for organizations.
I copied the drop script from the developmental tutorial.
That looks like this:
--drop package, which drops all functions created with define_function_args
select drop_package('samplenote');
--drop permissions
delete from acs_permissions where object_id in (select note_id from samplenote);
--drop objects
create function inline_0 ()
returns integer as '
declare
object_rec record;
begin
for object_rec in select object_id from acs_objects where object_type=''samplenote''
loop
perform acs_object__delete( object_rec.object_id );
end loop;
return 0;
end;' language 'plpgsql';
select inline_0();
drop function inline_0();
--drop table
drop table samplenote;
--drop type
select acs_object_type__drop_type(
'samplenote',
't'
);
I then modified it to work with organizations
select drop_package('organization');
-- drop permissions
delete from acs_permissions where object_id in (select organization_id from organizations);
-- drop objects
create function inline_0 ()
returns integer as '
declare
object_rec record;
begin
for object_rec in select object_id from acs_objects where object_type=''organizations''
loop
perform acs_object__delete( object_rec.object_id );
end loop;
return 0;
end;' language 'plpgsql';
select inline_0();
drop function inline_0();
-- drop parties added by organizations
create function inline_0 ()
returns integer as '
declare
object_rec record;
begin
for object_rec in select party_id from parties where party_id in (select organization_id from organizations)
loop
perform organization__del( object_rec.party_id );
end loop;
return 0;
end;' language 'plpgsql';
select inline_0();
drop function inline_0();
--drop table
drop table organizations;
--drop type
select acs_object_type__drop_type(
'organization',
't'
);
drop table organization_types;
drop sequence organization__organization__seq;
The organizations table subclasses the parties table, so each organization is a party. The organization__del function deletes both the party, and the organization.
The problem I'm getting is in the portion that drops the organization type. Here's the error I get:
psql:organizations-drop.sql:48: ERROR: acs_objects_object_type_fk referential integrity violation - key in acs_object_types still referenced from acs_objects
That looks to me like everything is not being deleted. So I guess I'm wondering what I'm doing wrong. Can anyone help, please?