
jbe@233: BEGIN;
jbe@233: 
jbe@233: CREATE OR REPLACE VIEW "liquid_feedback_version" AS
jbe@233:   SELECT * FROM (VALUES ('2.0.6', 2, 0, 6))
jbe@233:   AS "subquery"("string", "major", "minor", "revision");
jbe@233: 
jbe@233: -- add column "invite_code_expiry" to table "member":
jbe@233: ALTER TABLE "member" ADD COLUMN "invite_code_expiry" TIMESTAMPTZ;
jbe@233: COMMENT ON COLUMN "member"."invite_code_expiry" IS 'Expiry data/time for "invite_code"';
jbe@233: 
jbe@233: -- write member history only for activated accounts:
jbe@233: CREATE OR REPLACE FUNCTION "write_member_history_trigger"()
jbe@233:   RETURNS TRIGGER
jbe@233:   LANGUAGE 'plpgsql' VOLATILE AS $$
jbe@233:     BEGIN
jbe@233:       IF
jbe@233:         ( NEW."active" != OLD."active" OR
jbe@233:           NEW."name"   != OLD."name" ) AND
jbe@233:         OLD."activated" NOTNULL
jbe@233:       THEN
jbe@233:         INSERT INTO "member_history"
jbe@233:           ("member_id", "active", "name")
jbe@233:           VALUES (NEW."id", OLD."active", OLD."name");
jbe@233:       END IF;
jbe@233:       RETURN NULL;
jbe@233:     END;
jbe@233:   $$;
jbe@233: 
jbe@233: -- set "draft_id" in "event" table on event 'initiative_revoked':
jbe@233: CREATE OR REPLACE FUNCTION "write_event_initiative_revoked_trigger"()
jbe@233:   RETURNS TRIGGER
jbe@233:   LANGUAGE 'plpgsql' VOLATILE AS $$
jbe@233:     DECLARE
jbe@233:       "issue_row"  "issue"%ROWTYPE;
jbe@233:       "draft_id_v" "draft"."id"%TYPE;
jbe@233:     BEGIN
jbe@233:       IF OLD."revoked" ISNULL AND NEW."revoked" NOTNULL THEN
jbe@233:         SELECT * INTO "issue_row" FROM "issue"
jbe@233:           WHERE "id" = NEW."issue_id";
jbe@233:         SELECT "id" INTO "draft_id_v" FROM "current_draft"
jbe@233:           WHERE "initiative_id" = NEW."id";
jbe@233:         INSERT INTO "event" (
jbe@233:             "event", "member_id", "issue_id", "state", "initiative_id", "draft_id"
jbe@233:           ) VALUES (
jbe@233:             'initiative_revoked',
jbe@233:             NEW."revoked_by_member_id",
jbe@233:             NEW."issue_id",
jbe@233:             "issue_row"."state",
jbe@233:             NEW."id",
jbe@233:             "draft_id_v");
jbe@233:       END IF;
jbe@233:       RETURN NULL;
jbe@233:     END;
jbe@233:   $$;
jbe@233: 
jbe@233: -- delete column "invite_code_expiry" in function "delete_private_data":
jbe@233: CREATE OR REPLACE FUNCTION "delete_private_data"()
jbe@233:   RETURNS VOID
jbe@233:   LANGUAGE 'plpgsql' VOLATILE AS $$
jbe@233:     BEGIN
jbe@233:       DELETE FROM "member" WHERE "activated" ISNULL;
jbe@233:       UPDATE "member" SET
jbe@233:         "invite_code"                  = NULL,
jbe@233:         "invite_code_expiry"           = NULL,
jbe@233:         "admin_comment"                = NULL,
jbe@233:         "last_login"                   = NULL,
jbe@233:         "login"                        = NULL,
jbe@233:         "password"                     = NULL,
jbe@233:         "notify_email"                 = NULL,
jbe@233:         "notify_email_unconfirmed"     = NULL,
jbe@233:         "notify_email_secret"          = NULL,
jbe@233:         "notify_email_secret_expiry"   = NULL,
jbe@233:         "notify_email_lock_expiry"     = NULL,
jbe@233:         "password_reset_secret"        = NULL,
jbe@233:         "password_reset_secret_expiry" = NULL,
jbe@233:         "organizational_unit"          = NULL,
jbe@233:         "internal_posts"               = NULL,
jbe@233:         "realname"                     = NULL,
jbe@233:         "birthday"                     = NULL,
jbe@233:         "address"                      = NULL,
jbe@233:         "email"                        = NULL,
jbe@233:         "xmpp_address"                 = NULL,
jbe@233:         "website"                      = NULL,
jbe@233:         "phone"                        = NULL,
jbe@233:         "mobile_phone"                 = NULL,
jbe@233:         "profession"                   = NULL,
jbe@233:         "external_memberships"         = NULL,
jbe@233:         "external_posts"               = NULL,
jbe@233:         "statement"                    = NULL;
jbe@233:       -- "text_search_data" is updated by triggers
jbe@233:       DELETE FROM "setting";
jbe@233:       DELETE FROM "setting_map";
jbe@233:       DELETE FROM "member_relation_setting";
jbe@233:       DELETE FROM "member_image";
jbe@233:       DELETE FROM "contact";
jbe@233:       DELETE FROM "ignored_member";
jbe@233:       DELETE FROM "area_setting";
jbe@233:       DELETE FROM "issue_setting";
jbe@233:       DELETE FROM "ignored_initiative";
jbe@233:       DELETE FROM "initiative_setting";
jbe@233:       DELETE FROM "suggestion_setting";
jbe@233:       DELETE FROM "non_voter";
jbe@233:       DELETE FROM "direct_voter" USING "issue"
jbe@233:         WHERE "direct_voter"."issue_id" = "issue"."id"
jbe@233:         AND "issue"."closed" ISNULL;
jbe@233:       RETURN;
jbe@233:     END;
jbe@233:   $$;
jbe@233: 
jbe@233: COMMIT;




