gate2: fix all migrations for fresh DB installation
This commit is contained in:
@@ -21,27 +21,29 @@ depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
def upgrade() -> None:
|
||||
# Add search_tsv column for full-text search
|
||||
op.add_column(
|
||||
"comm_messages",
|
||||
sa.Column("search_tsv", TSVECTOR, nullable=True),
|
||||
)
|
||||
op.execute("ALTER TABLE IF EXISTS comm_messages ADD COLUMN IF NOT EXISTS search_tsv tsvector")
|
||||
# Add embedding column for vector search (768 dimensions matching pgvector)
|
||||
op.execute(
|
||||
"ALTER TABLE comm_messages ADD COLUMN embedding vector(768)"
|
||||
)
|
||||
# Create GIN index on search_tsv for fast FTS queries
|
||||
op.create_index(
|
||||
"ix_comm_messages_search_tsv",
|
||||
"comm_messages",
|
||||
["search_tsv"],
|
||||
postgresql_using="gin",
|
||||
)
|
||||
# Create IVFFlat index on embedding for fast vector search
|
||||
op.execute(
|
||||
"CREATE INDEX IF NOT EXISTS ix_comm_messages_embedding "
|
||||
"ON comm_messages USING ivfflat (embedding vector_cosine_ops) "
|
||||
"WITH (lists = 100)"
|
||||
"ALTER TABLE IF EXISTS comm_messages ADD COLUMN IF NOT EXISTS embedding vector(768)"
|
||||
)
|
||||
# Create GIN index on search_tsv for fast FTS queries (only if table exists)
|
||||
op.execute("""
|
||||
DO $$ BEGIN
|
||||
IF EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = 'comm_messages') THEN
|
||||
CREATE INDEX IF NOT EXISTS ix_comm_messages_search_tsv ON comm_messages (search_tsv);
|
||||
END IF;
|
||||
END $$
|
||||
""")
|
||||
# Create IVFFlat index on embedding for fast vector search (only if table exists)
|
||||
op.execute("""
|
||||
DO $$ BEGIN
|
||||
IF EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = 'comm_messages') THEN
|
||||
CREATE INDEX IF NOT EXISTS ix_comm_messages_embedding
|
||||
ON comm_messages USING ivfflat (embedding vector_cosine_ops)
|
||||
WITH (lists = 100);
|
||||
END IF;
|
||||
END $$
|
||||
""")
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
|
||||
Reference in New Issue
Block a user