89e884fae9
- Add migration 000004 for sessions table and performance indexes - Create session.sql queries for CRUD operations - Generate session repository code with sqlc - Create token auth middleware for Echo framework - Create token handler with create/delete/cleanup endpoints - Add /api/v1 router with token authentication infrastructure - Update dbHelper.go to use Up() instead of Migrate(2) - Update server.go to initialize token handler - Existing endpoints remain functional (to be deprecated) New endpoints: - POST /api/v1/token - Create new session token - DELETE /api/v1/token - Invalidate token - POST /api/v1/token/cleanup - Remove expired sessions Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
40 lines
1.6 KiB
SQL
40 lines
1.6 KiB
SQL
-- ============================================
|
|
-- PERFORMANCE INDEXES FOR EXISTING TABLES
|
|
-- ============================================
|
|
|
|
-- Game table indexes
|
|
CREATE INDEX IF NOT EXISTS idx_game_deleted ON game(deleted) WHERE deleted IS NULL;
|
|
CREATE INDEX IF NOT EXISTS idx_game_hash ON game(hash);
|
|
CREATE INDEX IF NOT EXISTS idx_game_path ON game(path);
|
|
CREATE INDEX IF NOT EXISTS idx_game_name ON game(game_name);
|
|
|
|
-- Song table indexes
|
|
CREATE INDEX IF NOT EXISTS idx_song_hash ON song(hash);
|
|
CREATE INDEX IF NOT EXISTS idx_song_path ON song(path);
|
|
CREATE INDEX IF NOT EXISTS idx_song_game_id ON song(game_id);
|
|
CREATE INDEX IF NOT EXISTS idx_song_game_id_song_name ON song(game_id, song_name);
|
|
|
|
-- Song_list table indexes
|
|
CREATE INDEX IF NOT EXISTS idx_song_list_match_date ON song_list(match_date);
|
|
CREATE INDEX IF NOT EXISTS idx_song_list_match_id ON song_list(match_id);
|
|
|
|
-- ============================================
|
|
-- SESSIONS TABLE FOR TOKEN MANAGEMENT
|
|
-- ============================================
|
|
|
|
-- Create sessions table for tracking client tokens
|
|
CREATE TABLE sessions (
|
|
token VARCHAR(64) PRIMARY KEY,
|
|
ip_address VARCHAR(45) NOT NULL,
|
|
user_agent TEXT NOT NULL,
|
|
client_type VARCHAR(20) DEFAULT 'web',
|
|
expires_at TIMESTAMP WITH TIME ZONE NOT NULL,
|
|
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
|
|
);
|
|
|
|
-- Indexes for fast lookup and cleanup
|
|
CREATE INDEX idx_sessions_expires ON sessions(expires_at);
|
|
CREATE INDEX idx_sessions_token ON sessions(token);
|
|
CREATE INDEX idx_sessions_ip ON sessions(ip_address);
|
|
CREATE INDEX idx_sessions_created ON sessions(created_at);
|