AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
fix(db): Remove redundant migration and fix pgvector schema handling (#11822)
Zamil Majdyf9f984a8f4b6
diff --git a/autogpt_platform/backend/migrations/20260109181714_add_docs_embedding/migration.sql b/autogpt_platform/backend/migrations/20260109181714_add_docs_embedding/migration.sqlindex 855fe36933..a839070a28 100644--- a/autogpt_platform/backend/migrations/20260109181714_add_docs_embedding/migration.sql+++ b/autogpt_platform/backend/migrations/20260109181714_add_docs_embedding/migration.sql@@ -1,12 +1,37 @@-- CreateExtension-- Supabase: pgvector must be enabled via Dashboard → Database → Extensions first--- Creates extension in current schema (determined by search_path from DATABASE_URL ?schema= param)+-- Ensures vector extension is in the current schema (from DATABASE_URL ?schema= param)+-- If it exists in a different schema (e.g., public), we drop and recreate it in the current schema-- This ensures vector type is in the same schema as tables, making ::vector work without explicit qualificationDO $$+DECLARE+ current_schema_name text;+ vector_schema text;BEGIN- CREATE EXTENSION IF NOT EXISTS "vector";-EXCEPTION WHEN OTHERS THEN- RAISE NOTICE 'vector extension not available or already exists, skipping';+ -- Get the current schema from search_path+ SELECT current_schema() INTO current_schema_name;++ -- Check if vector extension exists and which schema it's in+ SELECT n.nspname INTO vector_schema+ FROM pg_extension e+ JOIN pg_namespace n ON e.extnamespace = n.oid+ WHERE e.extname = 'vector';++ -- Handle removal if in wrong schema+ IF vector_schema IS NOT NULL AND vector_schema != current_schema_name THEN+ BEGIN+ -- Vector exists in a different schema, drop it first+ RAISE WARNING 'pgvector found in schema "%" but need it in "%". Dropping and reinstalling...',+ vector_schema, current_schema_name;+ EXECUTE 'DROP EXTENSION IF EXISTS vector CASCADE';+ EXCEPTION WHEN OTHERS THEN+ RAISE EXCEPTION 'Failed to drop pgvector from schema "%": %. You may need to drop it manually.',+ vector_schema, SQLERRM;+ END;+ END IF;++ -- Create extension in current schema (let it fail naturally if not available)+ EXECUTE format('CREATE EXTENSION IF NOT EXISTS vector SCHEMA %I', current_schema_name);END $$;-- CreateEnumdiff --git a/autogpt_platform/backend/migrations/20260112173500_add_supabase_extensions_to_platform_schema/migration.sql b/autogpt_platform/backend/migrations/20260112173500_add_supabase_extensions_to_platform_schema/migration.sqldeleted file mode 100644index ca91bc5cab..0000000000--- a/autogpt_platform/backend/migrations/20260112173500_add_supabase_extensions_to_platform_schema/migration.sql+++ /dev/null@@ -1,71 +0,0 @@--- Acknowledge Supabase-managed extensions to prevent drift warnings--- These extensions are pre-installed by Supabase in specific schemas--- This migration ensures they exist where available (Supabase) or skips gracefully (CI)---- Create schemas (safe in both CI and Supabase)-CREATE SCHEMA IF NOT EXISTS "extensions";---- Extensions that exist in both CI and Supabase-DO $$-BEGIN- CREATE EXTENSION IF NOT EXISTS "pgcrypto" WITH SCHEMA "extensions";-EXCEPTION WHEN OTHERS THEN- RAISE NOTICE 'pgcrypto extension not available, skipping';-END $$;--DO $$-BEGIN- CREATE EXTENSION IF NOT EXISTS "uuid-ossp" WITH SCHEMA "extensions";-EXCEPTION WHEN OTHERS THEN- RAISE NOTICE 'uuid-ossp extension not available, skipping';-END $$;---- Supabase-specific extensions (skip gracefully in CI)-DO $$-BEGIN- CREATE EXTENSION IF NOT EXISTS "pg_stat_statements" WITH SCHEMA "extensions";-EXCEPTION WHEN OTHERS THEN- RAISE NOTICE 'pg_stat_statements extension not available, skipping';-END $$;--DO $$-BEGIN- CREATE EXTENSION IF NOT EXISTS "pg_net" WITH SCHEMA "extensions";-EXCEPTION WHEN OTHERS THEN- RAISE NOTICE 'pg_net extension not available, skipping';-END $$;--DO $$-BEGIN- CREATE EXTENSION IF NOT EXISTS "pgjwt" WITH SCHEMA "extensions";-EXCEPTION WHEN OTHERS THEN- RAISE NOTICE 'pgjwt extension not available, skipping';-END $$;--DO $$-BEGIN- CREATE SCHEMA IF NOT EXISTS "graphql";- CREATE EXTENSION IF NOT EXISTS "pg_graphql" WITH SCHEMA "graphql";-EXCEPTION WHEN OTHERS THEN- RAISE NOTICE 'pg_graphql extension not available, skipping';-END $$;--DO $$-BEGIN- CREATE SCHEMA IF NOT EXISTS "pgsodium";- CREATE EXTENSION IF NOT EXISTS "pgsodium" WITH SCHEMA "pgsodium";-EXCEPTION WHEN OTHERS THEN- RAISE NOTICE 'pgsodium extension not available, skipping';-END $$;--DO $$-BEGIN- CREATE SCHEMA IF NOT EXISTS "vault";- CREATE EXTENSION IF NOT EXISTS "supabase_vault" WITH SCHEMA "vault";-EXCEPTION WHEN OTHERS THEN- RAISE NOTICE 'supabase_vault extension not available, skipping';-END $$;----- Return to platform-CREATE SCHEMA IF NOT EXISTS "platform";\ No newline at end of file