
jbe@50: BEGIN;
jbe@50: 
jbe@50: CREATE OR REPLACE VIEW "liquid_feedback_version" AS
jbe@50:   SELECT * FROM (VALUES ('1.0.2', 1, 0, 2))
jbe@50:   AS "subquery"("string", "major", "minor", "revision");
jbe@50:  
jbe@50: CREATE OR REPLACE FUNCTION "delete_member_data"("member_id_p" "member"."id"%TYPE)
jbe@50:   RETURNS VOID
jbe@50:   LANGUAGE 'plpgsql' VOLATILE AS $$
jbe@50:     BEGIN
jbe@50:       UPDATE "member" SET
jbe@50:         "login"                        = NULL,
jbe@50:         "password"                     = NULL,
jbe@50:         "notify_email"                 = NULL,
jbe@50:         "notify_email_unconfirmed"     = NULL,
jbe@50:         "notify_email_secret"          = NULL,
jbe@50:         "notify_email_secret_expiry"   = NULL,
jbe@50:         "password_reset_secret"        = NULL,
jbe@50:         "password_reset_secret_expiry" = NULL,
jbe@50:         "organizational_unit"          = NULL,
jbe@50:         "internal_posts"               = NULL,
jbe@50:         "realname"                     = NULL,
jbe@50:         "birthday"                     = NULL,
jbe@50:         "address"                      = NULL,
jbe@50:         "email"                        = NULL,
jbe@50:         "xmpp_address"                 = NULL,
jbe@50:         "website"                      = NULL,
jbe@50:         "phone"                        = NULL,
jbe@50:         "mobile_phone"                 = NULL,
jbe@50:         "profession"                   = NULL,
jbe@50:         "external_memberships"         = NULL,
jbe@50:         "external_posts"               = NULL,
jbe@50:         "statement"                    = NULL
jbe@50:         WHERE "id" = "member_id_p";
jbe@50:       -- "text_search_data" is updated by triggers
jbe@50:       UPDATE "member_history" SET "login" = NULL
jbe@50:         WHERE "member_id" = "member_id_p";
jbe@50:       DELETE FROM "setting"            WHERE "member_id" = "member_id_p";
jbe@50:       DELETE FROM "setting_map"        WHERE "member_id" = "member_id_p";
jbe@50:       DELETE FROM "member_relation_setting" WHERE "member_id" = "member_id_p";
jbe@50:       DELETE FROM "member_image"       WHERE "member_id" = "member_id_p";
jbe@50:       DELETE FROM "contact"            WHERE "member_id" = "member_id_p";
jbe@50:       DELETE FROM "delegation"         WHERE "truster_id" = "member_id_p";
jbe@50:       DELETE FROM "membership"         WHERE "member_id" = "member_id_p";
jbe@50:       DELETE FROM "area_setting"       WHERE "member_id" = "member_id_p";
jbe@50:       DELETE FROM "issue_setting"      WHERE "member_id" = "member_id_p";
jbe@50:       DELETE FROM "initiative_setting" WHERE "member_id" = "member_id_p";
jbe@50:       DELETE FROM "suggestion_setting" WHERE "member_id" = "member_id_p";
jbe@50:       RETURN;
jbe@50:     END;
jbe@50:   $$;
jbe@50: 
jbe@50: CREATE OR REPLACE FUNCTION "delete_private_data"()
jbe@50:   RETURNS VOID
jbe@50:   LANGUAGE 'plpgsql' VOLATILE AS $$
jbe@50:     BEGIN
jbe@50:       UPDATE "member" SET
jbe@50:         "login"                        = NULL,
jbe@50:         "password"                     = NULL,
jbe@50:         "notify_email"                 = NULL,
jbe@50:         "notify_email_unconfirmed"     = NULL,
jbe@50:         "notify_email_secret"          = NULL,
jbe@50:         "notify_email_secret_expiry"   = NULL,
jbe@50:         "password_reset_secret"        = NULL,
jbe@50:         "password_reset_secret_expiry" = NULL,
jbe@50:         "organizational_unit"          = NULL,
jbe@50:         "internal_posts"               = NULL,
jbe@50:         "realname"                     = NULL,
jbe@50:         "birthday"                     = NULL,
jbe@50:         "address"                      = NULL,
jbe@50:         "email"                        = NULL,
jbe@50:         "xmpp_address"                 = NULL,
jbe@50:         "website"                      = NULL,
jbe@50:         "phone"                        = NULL,
jbe@50:         "mobile_phone"                 = NULL,
jbe@50:         "profession"                   = NULL,
jbe@50:         "external_memberships"         = NULL,
jbe@50:         "external_posts"               = NULL,
jbe@50:         "statement"                    = NULL;
jbe@50:       -- "text_search_data" is updated by triggers
jbe@50:       UPDATE "member_history" SET "login" = NULL;
jbe@50:       DELETE FROM "setting";
jbe@50:       DELETE FROM "setting_map";
jbe@50:       DELETE FROM "member_relation_setting";
jbe@50:       DELETE FROM "member_image";
jbe@50:       DELETE FROM "contact";
jbe@50:       DELETE FROM "area_setting";
jbe@50:       DELETE FROM "issue_setting";
jbe@50:       DELETE FROM "initiative_setting";
jbe@50:       DELETE FROM "suggestion_setting";
jbe@50:       DELETE FROM "invite_code";
jbe@50:       DELETE FROM "session";
jbe@50:       DELETE FROM "direct_voter" USING "issue"
jbe@50:         WHERE "direct_voter"."issue_id" = "issue"."id"
jbe@50:         AND "issue"."closed" ISNULL;
jbe@50:       RETURN;
jbe@50:     END;
jbe@50:   $$;
jbe@50: 
jbe@50: COMMIT;




