FIX: Missing table check in post_migration (#1068)

This commit is contained in:
Roman Rizzi 2025-01-14 17:33:01 -03:00 committed by GitHub
parent 65456c8b30
commit cd03874b4d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,20 +1,22 @@
# frozen_string_literal: true # frozen_string_literal: true
class DropOldEmbeddingTables2 < ActiveRecord::Migration[7.2] class DropOldEmbeddingTables2 < ActiveRecord::Migration[7.2]
def up def up
# Copy rag embeddings created during deploy. if table_exists?(:ai_document_fragment_embeddings)
execute <<~SQL # Copy rag embeddings created during deploy.
INSERT INTO ai_document_fragments_embeddings (rag_document_fragment_id, model_id, model_version, strategy_id, strategy_version, digest, embeddings, created_at, updated_at) execute <<~SQL
( INSERT INTO ai_document_fragments_embeddings (rag_document_fragment_id, model_id, model_version, strategy_id, strategy_version, digest, embeddings, created_at, updated_at)
SELECT old_table.* (
FROM ai_document_fragment_embeddings old_table SELECT old_table.*
LEFT OUTER JOIN ai_document_fragments_embeddings target ON ( FROM ai_document_fragment_embeddings old_table
target.model_id = old_table.model_id AND LEFT OUTER JOIN ai_document_fragments_embeddings target ON (
target.strategy_id = old_table.strategy_id AND target.model_id = old_table.model_id AND
target.rag_document_fragment_id = old_table.rag_document_fragment_id target.strategy_id = old_table.strategy_id AND
target.rag_document_fragment_id = old_table.rag_document_fragment_id
)
WHERE target.rag_document_fragment_id IS NULL
) )
WHERE target.rag_document_fragment_id IS NULL SQL
) end
SQL
execute <<~SQL execute <<~SQL
DROP INDEX IF EXISTS ai_topic_embeddings_1_1_search_bit; DROP INDEX IF EXISTS ai_topic_embeddings_1_1_search_bit;