Skip to content

Commit 183094b

Browse files
authored
Merge pull request #1087 from noplanman/1086-fix_poll_foreign_key
Add `user_id` to the primary key of the `poll_answer` table
2 parents a3ef2f4 + 4643832 commit 183094b

File tree

3 files changed

+4
-1
lines changed

3 files changed

+4
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c
1313
### Deprecated
1414
### Removed
1515
### Fixed
16+
- Primary key for `poll_answer` also requires the `user_id`.
1617
### Security
1718

1819
## [0.62.0] - 2020-04-08

structure.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ CREATE TABLE IF NOT EXISTS `poll_answer` (
231231
`option_ids` text NOT NULL COMMENT '0-based identifiers of answer options, chosen by the user. May be empty if the user retracted their vote.',
232232
`created_at` timestamp NULL DEFAULT NULL COMMENT 'Entry date creation',
233233

234-
PRIMARY KEY (`poll_id`),
234+
PRIMARY KEY (`poll_id`, `user_id`),
235235
FOREIGN KEY (`poll_id`) REFERENCES `poll` (`id`)
236236
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
237237

utils/db-schema-update/0.62.0-unreleased.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ ALTER TABLE `poll` ADD COLUMN `explanation` varchar(255) DEFAULT NULL COMMENT 'T
22
ALTER TABLE `poll` ADD COLUMN `explanation_entities` text DEFAULT NULL COMMENT 'Special entities like usernames, URLs, bot commands, etc. that appear in the explanation' AFTER `explanation`;
33
ALTER TABLE `poll` ADD COLUMN `open_period` int UNSIGNED DEFAULT NULL COMMENT 'Amount of time in seconds the poll will be active after creation' AFTER `explanation_entities`;
44
ALTER TABLE `poll` ADD COLUMN `close_date` timestamp NULL DEFAULT NULL COMMENT 'Point in time (Unix timestamp) when the poll will be automatically closed' AFTER `open_period`;
5+
6+
ALTER TABLE `poll_answer` DROP PRIMARY KEY, ADD PRIMARY KEY (`poll_id`, `user_id`);

0 commit comments

Comments
 (0)