# HG changeset patch # User jbe # Date 1307475020 -7200 # Node ID 62ac82e55a5769bc6b43d6e27208bab79c44ec22 # Parent 368fe2299d0779925cf1c714aed165ff05947c64 Added constraints on table "initiative"; Added comment for column "initiative"."rank" diff -r 368fe2299d07 -r 62ac82e55a57 core.sql --- a/core.sql Tue Jun 07 20:56:42 2011 +0200 +++ b/core.sql Tue Jun 07 21:30:20 2011 +0200 @@ -588,6 +588,11 @@ "reverse_beat_path" ISNULL AND "multistage_majority" ISNULL AND "eligible" ISNULL AND "winner" ISNULL AND "rank" ISNULL ) ), CONSTRAINT "better_excludes_worse" CHECK (NOT ("better_than_status_quo" AND "worse_than_status_quo")), + CONSTRAINT "minimum_requirement_to_be_eligible" CHECK ( + "eligible" = FALSE OR + ("direct_majority" AND "indirect_majority" AND "better_than_status_quo") ), + CONSTRAINT "winner_must_be_eligible" CHECK ("winner"=FALSE OR "eligible"=TRUE), + CONSTRAINT "winner_must_have_first_rank" CHECK ("winner"=FALSE OR "rank"=1), CONSTRAINT "unique_rank_per_issue" UNIQUE ("issue_id", "rank") ); CREATE INDEX "initiative_created_idx" ON "initiative" ("created"); CREATE INDEX "initiative_revoked_idx" ON "initiative" ("revoked"); @@ -619,6 +624,7 @@ COMMENT ON COLUMN "initiative"."multistage_majority" IS 'TRUE, if either (a) this initiative has no better rank than the status quo, or (b) there exists a better ranked initiative X, which directly beats this initiative, and either more voters prefer X to this initiative than voters preferring X to the status quo or less voters prefer this initiative to X than voters preferring the status quo to X'; COMMENT ON COLUMN "initiative"."eligible" IS 'Initiative is "attainable" and depending on selected policy has no "reverse_beat_path" or "multistage_majority"'; COMMENT ON COLUMN "initiative"."winner" IS 'Winner is the "eligible" initiative with best "schulze_rank" and in case of ties with lowest "id"'; +COMMENT ON COLUMN "initiative"."rank" IS 'Unique ranking for all "admitted" initiatives per issue; lower rank is better; a winner always has rank 1, but rank 1 does not imply that an initiative is winner; initiatives with "direct_majority" AND "indirect_majority" always have a better (lower) rank than other initiatives'; CREATE TABLE "battle" (