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 <noreply@anthropic.com>
This commit is contained in:
@@ -102,17 +102,18 @@ CREATE TABLE IF NOT EXISTS items (
|
|||||||
-- Indexes will be added as needed based on query patterns
|
-- Indexes will be added as needed based on query patterns
|
||||||
|
|
||||||
-- OAuth sessions
|
-- OAuth sessions
|
||||||
CREATE TABLE IF NOT EXISTS sessions (
|
CREATE TABLE IF NOT EXISTS oauth_sessions (
|
||||||
id TEXT PRIMARY KEY,
|
id TEXT PRIMARY KEY,
|
||||||
did TEXT NOT NULL,
|
did TEXT NOT NULL,
|
||||||
handle TEXT NOT NULL,
|
handle TEXT NOT NULL,
|
||||||
access_token TEXT NOT NULL,
|
access_token TEXT,
|
||||||
refresh_token TEXT,
|
refresh_token TEXT,
|
||||||
token_type TEXT NOT NULL DEFAULT 'DPoP',
|
token_type TEXT NOT NULL DEFAULT 'DPoP',
|
||||||
expires_at TIMESTAMP NOT NULL,
|
expires_at TIMESTAMP NOT NULL,
|
||||||
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
|
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
|
||||||
dpop_nonce TEXT,
|
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.)
|
-- 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_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)")
|
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
|
// Migration: rename feed columns for consistent terminology
|
||||||
// last_crawled_at -> last_checked_at (feed_check = checking feeds for new items)
|
// last_crawled_at -> last_checked_at (feed_check = checking feeds for new items)
|
||||||
// next_crawl_at -> next_check_at
|
// next_crawl_at -> next_check_at
|
||||||
|
|||||||
Reference in New Issue
Block a user