2025-01-14 13:30:52 -03:00
|
|
|
# frozen_string_literal: true
|
|
|
|
class BackfillRagEmbeddings < ActiveRecord::Migration[7.2]
|
|
|
|
def up
|
2025-01-14 17:13:34 -03:00
|
|
|
if table_exists?(:ai_document_fragment_embeddings)
|
|
|
|
not_backfilled =
|
|
|
|
DB.query_single("SELECT COUNT(*) FROM ai_document_fragments_embeddings").first.to_i == 0
|
2025-01-14 13:30:52 -03:00
|
|
|
|
2025-01-14 17:13:34 -03:00
|
|
|
if not_backfilled
|
|
|
|
# Copy data from old tables to new tables
|
|
|
|
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 * FROM ai_document_fragment_embeddings;
|
|
|
|
SQL
|
|
|
|
end
|
2025-01-14 13:30:52 -03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def down
|
|
|
|
raise ActiveRecord::IrreversibleMigration
|
|
|
|
end
|
|
|
|
end
|