From 6200b061f23b3656da0cb3a406b9ab5f19d5bc2c Mon Sep 17 00:00:00 2001 From: patrickzerhusen Date: Fri, 24 Apr 2026 17:47:00 +0200 Subject: [PATCH] added migration for anonymous user identification by browser ID --- migrations/005_browser_id.sql | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 migrations/005_browser_id.sql diff --git a/migrations/005_browser_id.sql b/migrations/005_browser_id.sql new file mode 100644 index 0000000..7338902 --- /dev/null +++ b/migrations/005_browser_id.sql @@ -0,0 +1,27 @@ +-- ===================================================================== +-- Migration 005: Adds Browser ID for anonymous User Identification +-- ===================================================================== + +-- Adds browser_id Column to Contributions +ALTER TABLE contributions + ADD COLUMN browser_id VARCHAR(36) DEFAULT NULL; + +-- Adds browser_id Column to Votes +-- Replaces voter_name for Identification +ALTER TABLE votes + ADD COLUMN browser_id VARCHAR(36) DEFAULT NULL; + +-- Index for fast Vote Lookup by Browser +CREATE INDEX idx_votes_browser ON votes(browser_id); + + +-- New UNIQUE Constraint: One Vote per Browser per Contribution + +-- Drops old Constraint voter_name based +ALTER TABLE votes + DROP CONSTRAINT IF EXISTS votes_contribution_id_voter_name_key; + +-- Creates new Constraint browser_id based +ALTER TABLE votes + ADD CONSTRAINT votes_contribution_browser_unique + UNIQUE (contribution_id, browser_id); \ No newline at end of file