Fix ActivityLogs index creation - remove DO block for CONCURRENTLY support

This commit is contained in:
2026-03-07 12:37:46 -05:00
parent f47a544c7a
commit 5202d72999
2 changed files with 31 additions and 15 deletions
+4 -15
View File
@@ -62,21 +62,10 @@ ON library."ItemValuesMap" ("ItemValueId", "ItemId");
-- 5. Index for user-specific activity queries
-- Use case: "Show activity for user X"
-- Improves queries like: "SELECT * FROM ActivityLogs WHERE UserId='user-id' ORDER BY DateCreated DESC"
DO $$
BEGIN
IF EXISTS (
SELECT 1 FROM information_schema.tables
WHERE table_schema = 'activitylog'
AND table_name = 'ActivityLogs'
) THEN
RAISE NOTICE 'Creating activity log index...';
CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_activitylogs_userid_datecreated
ON activitylog."ActivityLogs" ("UserId", "DateCreated" DESC)
WHERE "UserId" IS NOT NULL;
ELSE
RAISE NOTICE 'ActivityLogs table does not exist. Skipping activity log index.';
END IF;
END $$;
-- Note: This will fail gracefully if the activitylog.ActivityLogs table doesn't exist
CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_activitylogs_userid_datecreated
ON activitylog."ActivityLogs" ("UserId", "DateCreated" DESC)
WHERE "UserId" IS NOT NULL;
-- 6. Index for episode deduplication by PresentationUniqueKey
-- Use case: Group and deduplicate episodes (used in GetItems queries)
+27
View File
@@ -0,0 +1,27 @@
-- ================================================
-- Fix for ActivityLogs Index
-- Run this separately to create the missing index
-- ================================================
--
-- This creates the ActivityLogs index that couldn't be created
-- from within the main migration script due to PostgreSQL
-- limitations with CONCURRENT operations in functions.
--
-- ================================================
-- Create the ActivityLogs index
-- This will error gracefully if the table doesn't exist
CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_activitylogs_userid_datecreated
ON activitylog."ActivityLogs" ("UserId", "DateCreated" DESC)
WHERE "UserId" IS NOT NULL;
-- Verify it was created
SELECT
schemaname AS "Schema",
tablename AS "Table",
indexname AS "Index Name",
indexdef AS "Definition"
FROM pg_indexes
WHERE indexname = 'idx_activitylogs_userid_datecreated';
-- Expected: 1 row showing the index on activitylog.ActivityLogs