liquid_feedback_core
diff core.sql @ 2:d45919d791ff
Version beta3
Minor bugfix: Autocreated entries in supporter table refer to the current draft of the initiative instead of throwing an error
Minor bugfix: Autocreated entries in supporter table refer to the current draft of the initiative instead of throwing an error
author | jbe |
---|---|
date | Sat Nov 07 12:00:00 2009 +0100 (2009-11-07) |
parents | 23092eb00e16 |
children | 3da35844c874 |
line diff
1.1 --- a/core.sql Tue Nov 03 12:00:00 2009 +0100 1.2 +++ b/core.sql Sat Nov 07 12:00:00 2009 +0100 1.3 @@ -259,7 +259,7 @@ 1.4 1.5 COMMENT ON TABLE "supporter" IS 'Members who support an initiative (conditionally)'; 1.6 1.7 -COMMENT ON COLUMN "supporter"."draft_id" IS 'Latest seen draft'; 1.8 +COMMENT ON COLUMN "supporter"."draft_id" IS 'Latest seen draft, defaults to current draft of the initiative (implemented by trigger "default_for_draft_id")'; 1.9 1.10 1.11 CREATE TABLE "opinion" ( 1.12 @@ -676,6 +676,25 @@ 1.13 COMMENT ON TRIGGER "copy_autoreject" ON "interest" IS 'If "autoreject" is NULL, then copy it from the area setting, or set to FALSE, if no membership existent'; 1.14 1.15 1.16 +CREATE FUNCTION "supporter_default_for_draft_id_trigger"() 1.17 + RETURNS TRIGGER 1.18 + LANGUAGE 'plpgsql' VOLATILE AS $$ 1.19 + BEGIN 1.20 + IF NEW."draft_id" ISNULL THEN 1.21 + SELECT "id" INTO NEW."draft_id" FROM "current_draft" 1.22 + WHERE "initiative_id" = NEW."initiative_id"; 1.23 + END IF; 1.24 + RETURN NEW; 1.25 + END; 1.26 + $$; 1.27 + 1.28 +CREATE TRIGGER "default_for_draft_id" BEFORE INSERT OR UPDATE ON "supporter" 1.29 + FOR EACH ROW EXECUTE PROCEDURE "supporter_default_for_draft_id_trigger"(); 1.30 + 1.31 +COMMENT ON FUNCTION "supporter_default_for_draft_id_trigger"() IS 'Implementation of trigger "default_for_draft" on table "supporter"'; 1.32 +COMMENT ON TRIGGER "default_for_draft_id" ON "supporter" IS 'If "draft_id" is NULL, then use the current draft of the initiative as default'; 1.33 + 1.34 + 1.35 1.36 ---------------------------------------- 1.37 -- Automatic creation of dependencies --