Forum OpenACS Q&A: Dropping a package

Collapse
Posted by Geoff King on
Hello everybody,

I am having big problems dropping packages when some data has been inserted into the acs_objects from the package prior to trying to delete the package.

I've written working drop scripts which clean up everything properly but when i go to the http://localhost/acs-admin/apm/package-delete page and try to delete the package it always has a foreign key error with the acs_objects table because it attempts to delete the package first

i.e
ERROR: update or delete on "acs_objects" violates foreign key constraint "acs_objects_context_id_fk" on "acs_objects"

SQL:
select apm_package__delete('867');

If it ran my drop scripts first this wouldn't be a problem. Im not sure what i need to do to get around this problem

Please help.

Kind regards,
Geoff.

Collapse
Posted by David Arroyo Menéndez on
what packages are you trying to drop?
Collapse
3: Re: Dropping a package (response to 1)
Posted by Geoff King on
Well the notes package for one doesn't work but also a package i've written myself based off the drop scripts from notes. Any package that has written to the acs_objects table causes it to fail on the drop.
Collapse
4: Re: Dropping a package (response to 1)
Posted by Geoff King on
If this helps when i create an acs_object I do the following as is suggested by the notes package;

(this is postgres function)

v_ad_id := acs_object__new (
p_ad_id,
p_object_type,
p_creation_date,
p_creation_user,
p_creation_ip,
p_context_id
);

So the package id is written to the acs_objects table, and this causes the violates foreign key constraint "acs_objects_context_id_fk" on "acs_objects" on the drop because it tried to delete the context id (package id) from the system first instead of deleteing the objects first and then the package.

Now through testing if I change my create scripts to do this instead;

v_ad_id := acs_object__new (
p_ad_id,
p_object_type,
p_creation_date,
p_creation_user,
p_creation_ip,
null
);

the package removes properlly with NO ERRORS.

Should I just not ever write the context_id tp the acs_objects table?

Collapse
Posted by David Arroyo Menéndez on
Perhaps you need to do:

delete from acs_objects where object_type='notes';

or similar, you can look the categories package or another like example. If you solve the bug send it to https://openacs.org/bugtracker/openacs/.

Regards

Collapse
6: Re: Dropping a package (response to 1)
Posted by Geoff King on
Yes I do all of that,

The problem is when i use the apm to drop the package it deletes the package instance (package_id object) objects first before it runs the drop scripts setup in /sql dir.

Of course deleting this first is wrong OpenACS should be running my drops scripts first and THEN trying to run apm_package__delete ( ).

What have I done wrong to cause this misorder?

Collapse
7: Re: Dropping a package (response to 1)
Posted by Dave Bauer on
Here is how the process works.

One install of a package, the files in package-key/sql/dbname/ *-create.sql are executed.

These are executed only once when the package is first installed.

When you uninstall the package completey all package instances are removed, and the package will be unavailable for use. This is the only time the *-drop.sql scripts are run.

When you want to delete one package instance, the drop scripts are not run. There are APM Tcl callbacks that can be executed when a package is deleted. See /acs-admin/apm/ click on a packgae name, then on #
# Tcl Callbacks (install, instantiate, mount)

There is a callback for the following events:

before-install
after-install
before-upgrade
after-upgrade
before-uninstall
after-instantiate
before-uninstantiate
after-mount
before-unmount

In the case of deleting one package instnace the callback to use is before-uninstantiate. In the before-uninstantiate callback, all objects that refer to the package_id of the pakcage instance must be removed or otherwise dereferenced from that package_id. At this time most packages do not handle this correctly. Basically what needs to be done is run code similar to the drop.sql script just for one package_id.

If you visit the callback page for one package, you can get more information about how the callbacks work, and when they are executed.

All packages should implement the before uninstantiate callback to allow delete of package instances.

Collapse
8: Re: Dropping a package (response to 1)
Posted by Geoff King on
Thankyou,

That worked perfectly.