Skip to content

Commit b290d17

Browse files
committed
Voting
Fixes #150
1 parent e962c9f commit b290d17

1 file changed

Lines changed: 70 additions & 0 deletions

File tree

migrations/V51__voting.sql

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
CREATE TABLE voting_subject (
2+
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
3+
`subject_key` VARCHAR(255) NOT NULL
4+
COMMENT 'With this key the ''subject'' can be loaded from the messages table',
5+
`begin_of_vote_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
6+
`end_of_vote_time` DATETIME NOT NULL,
7+
`min_games_to_vote` INT UNSIGNED NOT NULL DEFAULT 0
8+
COMMENT 'The number of games a player must have to in order to vote',
9+
`description_key` VARCHAR(255)
10+
COMMENT 'The ''description-key'' of the voting subject with it additional information (HTML) can be loaded from the messages table',
11+
`topic_url` TEXT
12+
COMMENT 'An URL to a page with additional information, e.g. a forum post.',
13+
`create_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
14+
`update_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
15+
);
16+
17+
CREATE TABLE voting_question (
18+
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
19+
`max_answers` INT UNSIGNED NOT NULL DEFAULT 1,
20+
`question_key` VARCHAR(255) NOT NULL
21+
COMMENT 'With this key the ''question'' can be loaded from the messages table',
22+
`voting_subject_id` INT UNSIGNED NOT NULL,
23+
CONSTRAINT voting_subject_of_voting_question FOREIGN KEY (`voting_subject_id`) REFERENCES voting_subject (id),
24+
`description_key` VARCHAR(255)
25+
COMMENT 'The ''description-key'' of the voting question, with it additional information (HTML) can be loaded from the messages table',
26+
`ordinal` INT UNSIGNED NOT NULL DEFAULT 0
27+
COMMENT 'The ''ordinal'' of the voting question, in the client questions are shown according to their ordinal value',
28+
`alternative_voting` TINYINT UNSIGNED NOT NULL DEFAULT 0
29+
COMMENT 'Defines whether alternative voting applies to this question',
30+
`create_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
31+
`update_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
32+
);
33+
34+
CREATE TABLE voting_choice (
35+
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
36+
`choice_text_key` VARCHAR(255) NOT NULL
37+
COMMENT 'With this key the ''choice_text'' can be loaded from the messages table',
38+
`voting_question_id` INT UNSIGNED NOT NULL,
39+
CONSTRAINT voting_question_of_voting_choice FOREIGN KEY (`voting_question_id`) REFERENCES voting_question (id),
40+
`description_key` VARCHAR(255) NOT NULL
41+
COMMENT 'The ''description-key'' of the voting choice, with it additional information (HTML) can be loaded from the messages table',
42+
`ordinal` INT UNSIGNED NOT NULL DEFAULT 0
43+
COMMENT 'The ''ordinal'' of the voting choice, in the client choices are shown according to their ordinal value',
44+
`create_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
45+
`update_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
46+
);
47+
48+
CREATE TABLE vote (
49+
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
50+
`player_id` MEDIUMINT UNSIGNED NOT NULL,
51+
CONSTRAINT player_of_vote FOREIGN KEY (`player_id`) REFERENCES login (id),
52+
`voting_subject_id` INT UNSIGNED NOT NULL,
53+
CONSTRAINT voting_subject_of_vote FOREIGN KEY (`voting_subject_id`) REFERENCES voting_subject (id),
54+
`create_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
55+
`update_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
56+
UNIQUE KEY `one_vote_only` (`player_id`, `voting_subject_id`)
57+
);
58+
59+
CREATE TABLE voting_answer (
60+
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
61+
`vote_id` INT UNSIGNED NOT NULL,
62+
CONSTRAINT vote_of_voting_answer FOREIGN KEY (`vote_id`) REFERENCES vote (id),
63+
`voting_choice_id` INT UNSIGNED NOT NULL,
64+
CONSTRAINT voting_choice_of_voting_answer FOREIGN KEY (`voting_choice_id`) REFERENCES voting_choice (id),
65+
`alternative_ordinal` TINYINT UNSIGNED
66+
COMMENT 'Defines what preference for alternative voting this answer is',
67+
`create_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
68+
`update_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
69+
UNIQUE KEY `one_answer_only` (`vote_id`, `voting_choice_id`)
70+
);

0 commit comments

Comments
 (0)