FIX: Use COPY to avoid migration statement timeout

This commit is contained in:
Roman Rizzi 2025-01-14 12:23:49 -03:00
parent 65bbcd71fc
commit f1598b4679
No known key found for this signature in database
GPG Key ID: 64024A71CE7330D3

View File

@ -68,14 +68,15 @@ class NewEmbeddingsTables < ActiveRecord::Migration[7.2]
# Copy data from old tables to new tables
execute <<-SQL
INSERT INTO ai_topics_embeddings (topic_id, model_id, model_version, strategy_id, strategy_version, digest, embeddings, created_at, updated_at)
SELECT * FROM ai_topic_embeddings;
COPY ai_topics_embeddings FROM (SELECT * FROM ai_topic_embeddings)
SQL
INSERT INTO ai_posts_embeddings (post_id, model_id, model_version, strategy_id, strategy_version, digest, embeddings, created_at, updated_at)
SELECT * FROM ai_post_embeddings;
execute <<~SQL
COPY ai_posts_embeddings FROM (SELECT * FROM ai_post_embeddings)
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 * FROM ai_document_fragment_embeddings;
execute <<~SQL
COPY ai_document_fragments_embeddings FROM (SELECT * FROM ai_document_fragment_embeddings)
SQL
end