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