From 0dcdd038b8b7766866db6a8b3a8f14ee1656bf00 Mon Sep 17 00:00:00 2001 From: imcompiling Date: Sat, 18 May 2024 23:08:01 -0400 Subject: [PATCH] Make the VoteType StrEnum and edit column in database to enforce only 3 values. --- database_setup/database.sql | 2 +- utils.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/database_setup/database.sql b/database_setup/database.sql index 3c0809e..03ad9cb 100644 --- a/database_setup/database.sql +++ b/database_setup/database.sql @@ -25,7 +25,7 @@ CREATE TABLE Votes( ElectionCycle varchar(30) not null, VoterId bigint unsigned not null, VotedForId bigint unsigned, - Type int unsigned not null, + Type varchar(14) not null DEFAULT 'council' check("Type" in ('council', 'discordmanager', 'clanleader')), FOREIGN KEY (ElectionCycle) REFERENCES ElectionInformation(ElectionCycle), PRIMARY KEY (ElectionCycle, VoterId, Type) ); diff --git a/utils.py b/utils.py index f852437..51f87f2 100644 --- a/utils.py +++ b/utils.py @@ -4,7 +4,7 @@ File contains util functions. import os from datetime import datetime -from enum import Enum +from enum import StrEnum from typing import Iterable import nextcord @@ -25,7 +25,7 @@ REPO_DIR = "./dakiny-messages" MESSAGES_DIR = f"{REPO_DIR}/messages" TEMPLATES_DIR = f"{REPO_DIR}/message_templates" -VoteType = Enum("VoteType", ["COUNCIL", "DISCORDMANAGER", "CLANLEADER"]) +VoteType = StrEnum("VoteType", ["COUNCIL", "DISCORDMANAGER", "CLANLEADER"]) def get_datetime(day: str) -> datetime: