You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/db/migrations/0326_enterprise_organization_search.sql
+25Lines changed: 25 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -384,6 +384,31 @@ CREATE INDEX CONCURRENTLY IF NOT EXISTS "credential_group_organization_id_idx" O
384
384
--> statement-breakpoint
385
385
CREATEUNIQUE INDEXCONCURRENTLY IF NOT EXISTS "credential_group_organization_unique"ON"credential_group" USING btree ("organization_id");
386
386
--> statement-breakpoint
387
+
-- A failed concurrent build leaves an INVALID index that IF NOT EXISTS skips.
388
+
-- Rename only that failed index so it can be dropped concurrently outside this block.
389
+
-- The recovery name also survives interruption between the rename and drop.
390
+
DO $$
391
+
BEGIN
392
+
IF EXISTS (
393
+
SELECT1FROM pg_index
394
+
WHERE indexrelid = to_regclass('"public"."credential_group_workspace_unique_failed_0326"')
395
+
AND (indisvalid OR indrelid <>'"public"."credential_group"'::regclass)
396
+
) THEN
397
+
RAISE EXCEPTION 'Refusing to drop unexpected index credential_group_workspace_unique_failed_0326';
398
+
END IF;
399
+
IF EXISTS (
400
+
SELECT1FROM pg_index
401
+
WHERE indexrelid = to_regclass('"public"."credential_group_workspace_unique"')
402
+
AND indrelid ='"public"."credential_group"'::regclass
403
+
AND NOT indisvalid
404
+
) THEN
405
+
ALTERINDEX"public"."credential_group_workspace_unique" RENAME TO "credential_group_workspace_unique_failed_0326";
406
+
END IF;
407
+
END $$;
408
+
--> statement-breakpoint
409
+
-- migration-safe: Only the invalid workspace index left by 0326 is renamed above. Valid indexes and legacy uniqueness remain intact; the following statement rebuilds the failed index without removing rows.
410
+
DROPINDEX CONCURRENTLY IF EXISTS "public"."credential_group_workspace_unique_failed_0326";
411
+
--> statement-breakpoint
387
412
CREATEUNIQUE INDEXCONCURRENTLY IF NOT EXISTS "credential_group_workspace_unique"ON"credential_group" USING btree ("workspace_id");
388
413
--> statement-breakpoint
389
414
CREATEINDEXCONCURRENTLY IF NOT EXISTS "doc_connector_source_lookup_idx"ON"document" USING btree ("connector_id","external_id");
0 commit comments