From f1598b46798adbb328d7e0536cbfc693b8adb17b Mon Sep 17 00:00:00 2001 From: Roman Rizzi Date: Tue, 14 Jan 2025 12:23:49 -0300 Subject: [PATCH] FIX: Use COPY to avoid migration statement timeout --- db/migrate/20241230153300_new_embeddings_tables.rb | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/db/migrate/20241230153300_new_embeddings_tables.rb b/db/migrate/20241230153300_new_embeddings_tables.rb index 59ee5e69..1bd2701b 100644 --- a/db/migrate/20241230153300_new_embeddings_tables.rb +++ b/db/migrate/20241230153300_new_embeddings_tables.rb @@ -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