<commit_before>BEGIN;


-- update version number

CREATE OR REPLACE VIEW "liquid_feedback_version" AS
  SELECT * FROM (VALUES ('2.1.0', 2, 1, 0))
  AS "subquery"("string", "major", "minor", "revision");


-- old API tables are now deprecated

COMMENT ON TYPE "application_access_level" IS 'DEPRECATED, WILL BE REMOVED! Access privileges for applications using the API';
COMMENT ON TABLE "member_application" IS 'DEPRECATED, WILL BE REMOVED! Registered application being allowed to use the API';


-- new polling mode and changed privileges

ALTER TABLE "policy" ADD COLUMN "polling" BOOLEAN NOT NULL DEFAULT FALSE;
ALTER TABLE "policy" ALTER COLUMN "admission_time"    DROP NOT NULL;
ALTER TABLE "policy" ALTER COLUMN "discussion_time"   DROP NOT NULL;
ALTER TABLE "policy" ALTER COLUMN "verification_time" DROP NOT NULL;
ALTER TABLE "policy" ALTER COLUMN "voting_time"       DROP NOT NULL;
ALTER TABLE "policy" ALTER COLUMN "issue_quorum_num"  DROP NOT NULL;
ALTER TABLE "policy" ALTER COLUMN "issue_quorum_den"  DROP NOT NULL;
ALTER TABLE "policy" ADD CONSTRAINT "timing" CHECK (
          ( "polling" = FALSE AND
            "admission_time" NOTNULL AND "discussion_time" NOTNULL AND
            "verification_time" NOTNULL AND "voting_time" NOTNULL ) OR
          ( "polling" = TRUE AND
            "admission_time" ISNULL AND "discussion_time" NOTNULL AND
            "verification_time" NOTNULL AND "voting_time" NOTNULL ) OR
          ( "polling" = TRUE AND
            "admission_time" ISNULL AND "discussion_time" ISNULL AND
            "verification_time" ISNULL AND "voting_time" ISNULL ) );
ALTER TABLE "policy" ADD CONSTRAINT "issue_quorum_if_and_only_if_not_polling" CHECK (
          "polling" = "issue_quorum_num" ISNULL AND
          "polling" = "issue_quorum_den" ISNULL );
COMMENT ON COLUMN "policy"."polling" IS 'TRUE = special policy for non-user-generated issues without issue quorum, where certain initiatives (those having the "polling" flag set) do not need to pass the initiative quorum; "admission_time" MUST be set to NULL, the other timings may be set to NULL altogether, allowing individual timing for those issues';

ALTER TABLE "issue" ALTER COLUMN "admission_time" DROP NOT NULL;
ALTER TABLE "issue" ADD CONSTRAINT "admission_time_not_null_unless_instantly_accepted" CHECK (
  "admission_time" NOTNULL OR ("accepted" NOTNULL AND "accepted" = "created") );

ALTER TABLE "initiative" ADD COLUMN "polling" BOOLEAN NOT NULL DEFAULT FALSE;
COMMENT ON COLUMN "initiative"."polling" IS 'Initiative does not need to pass the initiative quorum (see "policy"."polling")';

ALTER TABLE "privilege" RENAME COLUMN "voting_right_manager" TO "member_manager";
ALTER TABLE "privilege" ADD COLUMN "initiative_right" BOOLEAN NOT NULL DEFAULT TRUE;
ALTER TABLE "privilege" ADD COLUMN "polling_right"    BOOLEAN NOT NULL DEFAULT FALSE;
UPDATE "privilege" SET "initiative_right" = "voting_right";
COMMENT ON COLUMN "privilege"."admin_manager"    IS 'Grant/revoke any privileges to/from other members';
COMMENT ON COLUMN "privilege"."member_manager"   IS 'Adding/removing members from the unit, granting or revoking "initiative_right" and "voting_right"';
COMMENT ON COLUMN "privilege"."initiative_right" IS 'Right to create an initiative';
COMMENT ON COLUMN "privilege"."voting_right"     IS 'Right to support initiatives, create and rate suggestions, and to vote';
COMMENT ON COLUMN "privilege"."polling_right"    IS 'Right to create issues with policies having the "policy"."polling" flag set, and to add initiatives having the "initiative"."polling" flag set to those issues';

DROP VIEW "member_contingent_left";
DROP VIEW "member_contingent";
ALTER TABLE "contingent" DROP CONSTRAINT "contingent_pkey";
ALTER TABLE "contingent" ALTER COLUMN "time_frame" DROP NOT NULL;
ALTER TABLE "contingent" ADD COLUMN "polling" BOOLEAN;
ALTER TABLE "contingent" ADD PRIMARY KEY ("polling", "time_frame");
COMMENT ON COLUMN "contingent"."polling" IS 'Determines if settings are for creating initiatives and new drafts of initiatives with "polling" flag set';
<commit_msg>Correctly transform existing "contingent" entries when updating to v2.1.0<commit_after>BEGIN;


-- update version number

CREATE OR REPLACE VIEW "liquid_feedback_version" AS
  SELECT * FROM (VALUES ('2.1.0', 2, 1, 0))
  AS "subquery"("string", "major", "minor", "revision");


-- old API tables are now deprecated

COMMENT ON TYPE "application_access_level" IS 'DEPRECATED, WILL BE REMOVED! Access privileges for applications using the API';
COMMENT ON TABLE "member_application" IS 'DEPRECATED, WILL BE REMOVED! Registered application being allowed to use the API';


-- new polling mode and changed privileges

ALTER TABLE "policy" ADD COLUMN "polling" BOOLEAN NOT NULL DEFAULT FALSE;
ALTER TABLE "policy" ALTER COLUMN "admission_time"    DROP NOT NULL;
ALTER TABLE "policy" ALTER COLUMN "discussion_time"   DROP NOT NULL;
ALTER TABLE "policy" ALTER COLUMN "verification_time" DROP NOT NULL;
ALTER TABLE "policy" ALTER COLUMN "voting_time"       DROP NOT NULL;
ALTER TABLE "policy" ALTER COLUMN "issue_quorum_num"  DROP NOT NULL;
ALTER TABLE "policy" ALTER COLUMN "issue_quorum_den"  DROP NOT NULL;
ALTER TABLE "policy" ADD CONSTRAINT "timing" CHECK (
          ( "polling" = FALSE AND
            "admission_time" NOTNULL AND "discussion_time" NOTNULL AND
            "verification_time" NOTNULL AND "voting_time" NOTNULL ) OR
          ( "polling" = TRUE AND
            "admission_time" ISNULL AND "discussion_time" NOTNULL AND
            "verification_time" NOTNULL AND "voting_time" NOTNULL ) OR
          ( "polling" = TRUE AND
            "admission_time" ISNULL AND "discussion_time" ISNULL AND
            "verification_time" ISNULL AND "voting_time" ISNULL ) );
ALTER TABLE "policy" ADD CONSTRAINT "issue_quorum_if_and_only_if_not_polling" CHECK (
          "polling" = "issue_quorum_num" ISNULL AND
          "polling" = "issue_quorum_den" ISNULL );
COMMENT ON COLUMN "policy"."polling" IS 'TRUE = special policy for non-user-generated issues without issue quorum, where certain initiatives (those having the "polling" flag set) do not need to pass the initiative quorum; "admission_time" MUST be set to NULL, the other timings may be set to NULL altogether, allowing individual timing for those issues';

ALTER TABLE "issue" ALTER COLUMN "admission_time" DROP NOT NULL;
ALTER TABLE "issue" ADD CONSTRAINT "admission_time_not_null_unless_instantly_accepted" CHECK (
  "admission_time" NOTNULL OR ("accepted" NOTNULL AND "accepted" = "created") );

ALTER TABLE "initiative" ADD COLUMN "polling" BOOLEAN NOT NULL DEFAULT FALSE;
COMMENT ON COLUMN "initiative"."polling" IS 'Initiative does not need to pass the initiative quorum (see "policy"."polling")';

ALTER TABLE "privilege" RENAME COLUMN "voting_right_manager" TO "member_manager";
ALTER TABLE "privilege" ADD COLUMN "initiative_right" BOOLEAN NOT NULL DEFAULT TRUE;
ALTER TABLE "privilege" ADD COLUMN "polling_right"    BOOLEAN NOT NULL DEFAULT FALSE;
UPDATE "privilege" SET "initiative_right" = "voting_right";
COMMENT ON COLUMN "privilege"."admin_manager"    IS 'Grant/revoke any privileges to/from other members';
COMMENT ON COLUMN "privilege"."member_manager"   IS 'Adding/removing members from the unit, granting or revoking "initiative_right" and "voting_right"';
COMMENT ON COLUMN "privilege"."initiative_right" IS 'Right to create an initiative';
COMMENT ON COLUMN "privilege"."voting_right"     IS 'Right to support initiatives, create and rate suggestions, and to vote';
COMMENT ON COLUMN "privilege"."polling_right"    IS 'Right to create issues with policies having the "policy"."polling" flag set, and to add initiatives having the "initiative"."polling" flag set to those issues';

DROP VIEW "member_contingent_left";
DROP VIEW "member_contingent";
ALTER TABLE "contingent" DROP CONSTRAINT "contingent_pkey";
ALTER TABLE "contingent" ALTER COLUMN "time_frame" DROP NOT NULL;
ALTER TABLE "contingent" ADD COLUMN "polling" BOOLEAN DEFAULT FALSE;
ALTER TABLE "contingent" ADD PRIMARY KEY ("polling", "time_frame");
ALTER TABLE "contingent" ALTER COLUMN "polling" DROP DEFAULT;
COMMENT ON COLUMN "contingent"."polling" IS 'Determines if settings are for creating initiatives and new drafts of initiatives with "polling" flag set';

{'fraction_non_alphanumeric': 0.08389666827619507, 'fraction_numerical': 0.0018107194591984548, 'mean_word_length': 4.913633119200571, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5201142', 'n_tokens_mistral': 2583, 'n_tokens_neox': 2540, 'n_words': 964}