From 265975c7c52c7bdb1376fbabf270a491009b2cdc Mon Sep 17 00:00:00 2001 From: primal Date: Mon, 2 Feb 2026 00:34:13 -0500 Subject: [PATCH] Rename sessions table to oauth_sessions for consistency - Update schema to create oauth_sessions instead of sessions - Add migration to rename existing sessions table - Add token_expiry column for OAuth library compatibility Co-Authored-By: Claude Opus 4.5 --- db.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/db.go b/db.go index 00b14f2..611afd0 100644 --- a/db.go +++ b/db.go @@ -102,17 +102,18 @@ CREATE TABLE IF NOT EXISTS items ( -- Indexes will be added as needed based on query patterns -- OAuth sessions -CREATE TABLE IF NOT EXISTS sessions ( +CREATE TABLE IF NOT EXISTS oauth_sessions ( id TEXT PRIMARY KEY, did TEXT NOT NULL, handle TEXT NOT NULL, - access_token TEXT NOT NULL, + access_token TEXT, refresh_token TEXT, token_type TEXT NOT NULL DEFAULT 'DPoP', expires_at TIMESTAMP NOT NULL, created_at TIMESTAMP NOT NULL DEFAULT NOW(), dpop_nonce TEXT, - dpop_private_jwk TEXT + dpop_private_jwk TEXT, + token_expiry TIMESTAMP ); -- Trigger to normalize feed URLs on insert/update (strips https://, http://, www.) @@ -215,6 +216,16 @@ func OpenDatabase(connString string) (*DB, error) { pool.Exec(ctx, "CREATE INDEX IF NOT EXISTS idx_domains_host_trgm ON domains USING gin (LOWER(host) gin_trgm_ops)") pool.Exec(ctx, "CREATE INDEX IF NOT EXISTS idx_feeds_domain_host_trgm ON feeds USING gin (LOWER(domain_host) gin_trgm_ops)") + // Migration: rename old 'sessions' table to 'oauth_sessions' + var oldSessionsExists, newSessionsExists bool + pool.QueryRow(ctx, "SELECT EXISTS(SELECT 1 FROM information_schema.tables WHERE table_name = 'sessions')").Scan(&oldSessionsExists) + pool.QueryRow(ctx, "SELECT EXISTS(SELECT 1 FROM information_schema.tables WHERE table_name = 'oauth_sessions')").Scan(&newSessionsExists) + if oldSessionsExists && !newSessionsExists { + pool.Exec(ctx, "ALTER TABLE sessions RENAME TO oauth_sessions") + } + // Add token_expiry column if missing (used by OAuth library) + pool.Exec(ctx, "ALTER TABLE oauth_sessions ADD COLUMN IF NOT EXISTS token_expiry TIMESTAMP") + // Migration: rename feed columns for consistent terminology // last_crawled_at -> last_checked_at (feed_check = checking feeds for new items) // next_crawl_at -> next_check_at