From 621239c5a5b5ac01721f3855eb7d4c3f7f83341d Mon Sep 17 00:00:00 2001 From: Leander Furumo Date: Fri, 23 Oct 2026 02:36:58 +0200 Subject: [PATCH] store verification expiry as timestamptz Co-Authored-By: Claude Opus 5.5 --- bot/src/cogs/galtinn.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/bot/src/cogs/galtinn.py b/bot/src/cogs/galtinn.py index 98158db..f48dbbc 100644 --- a/bot/src/cogs/galtinn.py +++ b/bot/src/cogs/galtinn.py @@ -48,11 +48,30 @@ class Galtinn(commands.Cog): discord_id BIGINT PRIMARY KEY, challenge TEXT NOT NULL, state TEXT NOT NULL, - expires TIMESTAMP DEFAULT (NOW() AT TIME ZONE 'utc') + INTERVAL '2 minutes' + expires TIMESTAMPTZ DEFAULT NOW() + INTERVAL '2 minutes' ); """ ) + # Tables created before expires was timezone aware stored naive UTC timestamps + await self.bot.db.execute( + """ + DO $$ + BEGIN + IF EXISTS ( + SELECT 1 FROM information_schema.columns + WHERE table_name = 'galtinn_verification' + AND column_name = 'expires' + AND data_type = 'timestamp without time zone' + ) THEN + ALTER TABLE galtinn_verification + ALTER COLUMN expires TYPE TIMESTAMPTZ USING expires AT TIME ZONE 'utc', + ALTER COLUMN expires SET DEFAULT NOW() + INTERVAL '2 minutes'; + END IF; + END $$; + """ + ) + async def listen_db(self): """ Creates a listener for galitnn_auth_complete events from the database and processes them @@ -490,7 +509,7 @@ class Galtinn(commands.Cog): await self.bot.db.execute( """ DELETE FROM galtinn_verification - WHERE expires < NOW() AT TIME ZONE 'utc'; + WHERE expires < NOW(); """ )