|
| 1 | +# frozen_string_literal: true |
| 2 | +class DropOldEmbeddingTables2 < ActiveRecord::Migration[7.2] |
| 3 | + def up |
| 4 | + # Copy rag embeddings created during deploy. |
| 5 | + execute <<~SQL |
| 6 | + INSERT INTO ai_document_fragments_embeddings (rag_document_fragment_id, model_id, model_version, strategy_id, strategy_version, digest, embeddings, created_at, updated_at) |
| 7 | + ( |
| 8 | + SELECT old_table.* |
| 9 | + FROM ai_document_fragment_embeddings old_table |
| 10 | + LEFT OUTER JOIN ai_document_fragments_embeddings target ON ( |
| 11 | + target.model_id = old_table.model_id AND |
| 12 | + target.strategy_id = old_table.strategy_id AND |
| 13 | + target.rag_document_fragment_id = old_table.rag_document_fragment_id |
| 14 | + ) |
| 15 | + WHERE target.rag_document_fragment_id IS NULL |
| 16 | + ) |
| 17 | + SQL |
| 18 | + |
| 19 | + execute <<~SQL |
| 20 | + DROP INDEX IF EXISTS ai_topic_embeddings_1_1_search_bit; |
| 21 | + DROP INDEX IF EXISTS ai_topic_embeddings_2_1_search_bit; |
| 22 | + DROP INDEX IF EXISTS ai_topic_embeddings_3_1_search_bit; |
| 23 | + DROP INDEX IF EXISTS ai_topic_embeddings_4_1_search_bit; |
| 24 | + DROP INDEX IF EXISTS ai_topic_embeddings_5_1_search_bit; |
| 25 | + DROP INDEX IF EXISTS ai_topic_embeddings_6_1_search_bit; |
| 26 | + DROP INDEX IF EXISTS ai_topic_embeddings_7_1_search_bit; |
| 27 | + DROP INDEX IF EXISTS ai_topic_embeddings_8_1_search_bit; |
| 28 | + DROP INDEX IF EXISTS ai_post_embeddings_1_1_search_bit; |
| 29 | + DROP INDEX IF EXISTS ai_post_embeddings_2_1_search_bit; |
| 30 | + DROP INDEX IF EXISTS ai_post_embeddings_3_1_search_bit; |
| 31 | + DROP INDEX IF EXISTS ai_post_embeddings_4_1_search_bit; |
| 32 | + DROP INDEX IF EXISTS ai_post_embeddings_5_1_search_bit; |
| 33 | + DROP INDEX IF EXISTS ai_post_embeddings_6_1_search_bit; |
| 34 | + DROP INDEX IF EXISTS ai_post_embeddings_7_1_search_bit; |
| 35 | + DROP INDEX IF EXISTS ai_post_embeddings_8_1_search_bit; |
| 36 | + DROP INDEX IF EXISTS ai_document_fragment_embeddings_1_1_search_bit; |
| 37 | + DROP INDEX IF EXISTS ai_document_fragment_embeddings_2_1_search_bit; |
| 38 | + DROP INDEX IF EXISTS ai_document_fragment_embeddings_3_1_search_bit; |
| 39 | + DROP INDEX IF EXISTS ai_document_fragment_embeddings_4_1_search_bit; |
| 40 | + DROP INDEX IF EXISTS ai_document_fragment_embeddings_5_1_search_bit; |
| 41 | + DROP INDEX IF EXISTS ai_document_fragment_embeddings_6_1_search_bit; |
| 42 | + DROP INDEX IF EXISTS ai_document_fragment_embeddings_7_1_search_bit; |
| 43 | + DROP INDEX IF EXISTS ai_document_fragment_embeddings_8_1_search_bit; |
| 44 | + SQL |
| 45 | + drop_table :ai_topic_embeddings |
| 46 | + drop_table :ai_post_embeddings |
| 47 | + drop_table :ai_document_fragment_embeddings |
| 48 | + end |
| 49 | + |
| 50 | + def down |
| 51 | + end |
| 52 | +end |
0 commit comments