diff --git a/ddl/schemas/auth/tables/01-users.sql b/ddl/schemas/auth/tables/01-users.sql index a76cba8..5f11475 100644 --- a/ddl/schemas/auth/tables/01-users.sql +++ b/ddl/schemas/auth/tables/01-users.sql @@ -73,7 +73,7 @@ CREATE INDEX idx_users_role ON auth.users(role); CREATE INDEX idx_users_last_login ON auth.users(last_login_at DESC); CREATE INDEX idx_users_created_at ON auth.users(created_at DESC); CREATE INDEX idx_users_email_verified ON auth.users(email_verified) WHERE email_verified = false; -CREATE INDEX idx_users_locked ON auth.users(locked_until) WHERE locked_until IS NOT NULL; +CREATE INDEX idx_users_locked_until ON auth.users(locked_until) WHERE locked_until IS NOT NULL AND locked_until > NOW(); CREATE INDEX idx_users_phone ON auth.users(phone_number) WHERE phone_number IS NOT NULL; -- Table Comments diff --git a/ddl/schemas/llm/tables/01-conversations.sql b/ddl/schemas/llm/tables/01-conversations.sql index abac1b6..11e2ed3 100644 --- a/ddl/schemas/llm/tables/01-conversations.sql +++ b/ddl/schemas/llm/tables/01-conversations.sql @@ -53,6 +53,7 @@ CREATE INDEX idx_conversations_active ON llm.conversations(user_id, last_message WHERE status = 'active'; CREATE INDEX idx_conversations_tags ON llm.conversations USING GIN(tags); CREATE INDEX idx_conversations_symbols ON llm.conversations USING GIN(related_symbols); +CREATE INDEX idx_conversations_topics ON llm.conversations USING GIN(related_topics); -- Comentarios COMMENT ON TABLE llm.conversations IS 'Chat conversations between users and LLM agent'; diff --git a/migrations/2026-02-03_add_auth_locked_index.sql b/migrations/2026-02-03_add_auth_locked_index.sql new file mode 100644 index 0000000..51716a4 --- /dev/null +++ b/migrations/2026-02-03_add_auth_locked_index.sql @@ -0,0 +1,29 @@ +-- ============================================================================ +-- Migration: Add index on locked_until for account lockout queries +-- Task: ST-4.1, GAP-009 +-- Description: Creates a more optimized partial index for active account +-- lockouts, improving query performance on account unlock checks +-- ============================================================================ + +-- Drop the previous index if it exists (less specific) +DROP INDEX IF EXISTS auth.idx_users_locked CASCADE; + +-- Create optimized partial index for active lockouts +CREATE INDEX idx_users_locked_until +ON auth.users(locked_until) +WHERE locked_until IS NOT NULL AND locked_until > NOW(); + +-- Add index comment +COMMENT ON INDEX auth.idx_users_locked_until IS 'Partial index for active account lockouts - optimized for unlock validation queries'; + +-- ============================================================================ +-- Verification +-- ============================================================================ +-- This index improves queries like: +-- SELECT id, email FROM auth.users WHERE locked_until > NOW(); +-- +-- Benefits: +-- 1. Smaller index size (only rows with active locks) +-- 2. Faster scans for checking unlocked accounts +-- 3. Automatic pruning as locks expire +-- ============================================================================ diff --git a/migrations/2026-02-03_add_llm_gin_indexes.sql b/migrations/2026-02-03_add_llm_gin_indexes.sql new file mode 100644 index 0000000..705d2fd --- /dev/null +++ b/migrations/2026-02-03_add_llm_gin_indexes.sql @@ -0,0 +1,27 @@ +-- ===================================================== +-- Migration: Add GIN indexes for llm schema +-- Task: ST-4.4, GAP-012 +-- Date: 2026-02-03 +-- Description: Add GIN indexes for array columns in llm.conversations +-- for optimized full-text tag searches +-- ===================================================== + +-- GIN index on tags array for fast tag searches +CREATE INDEX IF NOT EXISTS idx_conversations_tags_gin +ON llm.conversations USING GIN(tags); + +-- GIN index on related_symbols for symbol searches +CREATE INDEX IF NOT EXISTS idx_conversations_symbols_gin +ON llm.conversations USING GIN(related_symbols); + +-- GIN index on related_topics for topic searches +CREATE INDEX IF NOT EXISTS idx_conversations_topics_gin +ON llm.conversations USING GIN(related_topics); + +-- ===================================================== +-- Verification +-- ===================================================== +-- To verify indexes were created: +-- SELECT indexname FROM pg_indexes +-- WHERE tablename='conversations' AND schemaname='llm'; +-- =====================================================