Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deleting data use case issues #7 #174

Closed
haubourg opened this issue Feb 24, 2017 · 7 comments
Closed

Deleting data use case issues #7 #174

haubourg opened this issue Feb 24, 2017 · 7 comments

Comments

@haubourg
Copy link
Contributor

haubourg commented Feb 24, 2017

In the idea of finalizing the demo data sample to v1.2.1 model version, I continued the work started here #2

Removing meters via vw_element_meter

delete from qwat_od.vw_element_meter a where NOT a.geometry && (st_makebox2d(st_makePoint(559144, 143502), st_makepoint(561817, 140796)))

will throw fk constraint errors on meter_reference table

delete from qwat_od.vw_element_meter a where NOT a.geometry && (st_makebox2d(st_makePoint(559144, 143502), st_makepoint(561817, 140796)))
ft_element_meter_delete seem to miss the cascading delete for meter_reference table

@haubourg
Copy link
Contributor Author

haubourg commented Feb 24, 2017

adding
DELETE FROM qwat_od.meter_reference WHERE fk_meter = OLD.id; in ft_element_meter_delete() does the trick.

@haubourg haubourg added this to the T1-2017 milestone Feb 24, 2017
@haubourg
Copy link
Contributor Author

but.. that trigger function is generated by the meta-projects recursive scripts..

@haubourg
Copy link
Contributor Author

SOoo, if I get it well, the solution would be to add a trigger on qwat_od.meter to delete meter_reference on delete. @3nids Can you confirm that I get it well ?

@haubourg
Copy link
Contributor Author

Same problem occurs with deleting from vw_element_subscriber

**ERROR:  update or delete on table "subscriber" violates foreign key constraint "subscriber_reference_fk_subscriber" on table "subscriber_reference"
DETAIL:  Key (id)=(38641) is still referenced from table "subscriber_reference".
CONTEXT:  SQL statement "DELETE FROM qwat_od.subscriber WHERE id = OLD.id"
PL/pgSQL function qwat_od.ft_element_subscriber_delete() line 3 at SQL statement
********** Erreur **********

ERROR: update or delete on table "subscriber" violates foreign key constraint "subscriber_reference_fk_subscriber" on table "subscriber_reference"
État SQL :23503
Détail :Key (id)=(38641) is still referenced from table "subscriber_reference".
Contexte : SQL statement "DELETE FROM qwat_od.subscriber WHERE id = OLD.id"
PL/pgSQL function qwat_od.ft_element_subscriber_delete() line 3 at SQL statement
**

I guess that we have a general issues with reference_* logic and trigger generation process

@3nids
Copy link
Member

3nids commented Feb 24, 2017

Yep exactly.
A delete cascade rule is the way to go.

@haubourg
Copy link
Contributor Author

Another one on pipes:
ERROR: update or delete on table "pipe" violates foreign key constraint "pipe_fk_parent" on table "pipe" DETAIL: Key (id)=(1106) is still referenced from table "pipe".

Deleting a pipe means first removing only fk_renference to it on other pipes, and then deleting it. Ther is no yet a delete trigger for pipes, should we add one?

@3nids
Copy link
Member

3nids commented Mar 22, 2017

PR in qwat/qwat-data-model#158

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants