16648f543a
Check Cross-Plugin Imports / check (push) Has been cancelled
Fixes 3 issues found by API integration tests: 1. migration_runner.py: Add GLOBAL TABLE exemption for tables without tenant_id - New _extract_global_table_names() method parses -- GLOBAL TABLE: comments - marketplace_listings is intentionally global (no tenant_id) 2. unified_search/migrations/0002_embeddings.sql: Remove companies table (does not exist), add DO $$ BEGIN END $$ blocks to check table existence before ALTER 3. marketplace/migrations/0001_initial.sql: Add -- GLOBAL TABLE: marketplace_listings comment
46 lines
1.8 KiB
SQL
46 lines
1.8 KiB
SQL
-- Unified Search: Embedding columns and HNSW indexes
|
|
-- Note: These columns are also added by Alembic migration 0104.
|
|
-- This migration is idempotent (IF NOT EXISTS) and skips non-existent tables.
|
|
|
|
-- Ensure pgvector extension is installed
|
|
CREATE EXTENSION IF NOT EXISTS vector;
|
|
|
|
-- ─── Mails ───
|
|
DO $$ BEGIN
|
|
IF EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = 'mails') THEN
|
|
ALTER TABLE mails ADD COLUMN IF NOT EXISTS embedding vector(768);
|
|
CREATE INDEX IF NOT EXISTS ix_mails_embedding ON mails USING hnsw(embedding vector_cosine_ops);
|
|
END IF;
|
|
END $$;
|
|
|
|
-- ─── Contacts ───
|
|
DO $$ BEGIN
|
|
IF EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = 'contacts') THEN
|
|
ALTER TABLE contacts ADD COLUMN IF NOT EXISTS embedding vector(768);
|
|
CREATE INDEX IF NOT EXISTS ix_contacts_embedding ON contacts USING hnsw(embedding vector_cosine_ops);
|
|
END IF;
|
|
END $$;
|
|
|
|
-- ─── Files ───
|
|
DO $$ BEGIN
|
|
IF EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = 'files') THEN
|
|
ALTER TABLE files ADD COLUMN IF NOT EXISTS embedding vector(768);
|
|
CREATE INDEX IF NOT EXISTS ix_files_embedding ON files USING hnsw(embedding vector_cosine_ops);
|
|
END IF;
|
|
END $$;
|
|
|
|
-- ─── Calendar Entries ───
|
|
DO $$ BEGIN
|
|
IF EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = 'calendar_entries') THEN
|
|
ALTER TABLE calendar_entries ADD COLUMN IF NOT EXISTS embedding vector(768);
|
|
CREATE INDEX IF NOT EXISTS ix_cal_embedding ON calendar_entries USING hnsw(embedding vector_cosine_ops);
|
|
END IF;
|
|
END $$;
|
|
|
|
-- ─── Tags (shorter dimension for short text) ───
|
|
DO $$ BEGIN
|
|
IF EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = 'tags') THEN
|
|
ALTER TABLE tags ADD COLUMN IF NOT EXISTS embedding vector(384);
|
|
END IF;
|
|
END $$;
|