generated from discourse/discourse-plugin-skeleton
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DEV: Migration to remove old embeddings tables~ (#1067)
* DEV: Migration to remove old embeddings tables~ * Check for table existence
- Loading branch information
1 parent
c4d2b7d
commit 65456c8
Showing
4 changed files
with
102 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
db/post_migrate/20250114184356_drop_old_embedding_tables2.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# frozen_string_literal: true | ||
class DropOldEmbeddingTables2 < ActiveRecord::Migration[7.2] | ||
def up | ||
# Copy rag embeddings created during deploy. | ||
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 | ||
LEFT OUTER JOIN ai_document_fragments_embeddings target ON ( | ||
target.model_id = old_table.model_id AND | ||
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 | ||
) | ||
SQL | ||
|
||
execute <<~SQL | ||
DROP INDEX IF EXISTS ai_topic_embeddings_1_1_search_bit; | ||
DROP INDEX IF EXISTS ai_topic_embeddings_2_1_search_bit; | ||
DROP INDEX IF EXISTS ai_topic_embeddings_3_1_search_bit; | ||
DROP INDEX IF EXISTS ai_topic_embeddings_4_1_search_bit; | ||
DROP INDEX IF EXISTS ai_topic_embeddings_5_1_search_bit; | ||
DROP INDEX IF EXISTS ai_topic_embeddings_6_1_search_bit; | ||
DROP INDEX IF EXISTS ai_topic_embeddings_7_1_search_bit; | ||
DROP INDEX IF EXISTS ai_topic_embeddings_8_1_search_bit; | ||
DROP INDEX IF EXISTS ai_post_embeddings_1_1_search_bit; | ||
DROP INDEX IF EXISTS ai_post_embeddings_2_1_search_bit; | ||
DROP INDEX IF EXISTS ai_post_embeddings_3_1_search_bit; | ||
DROP INDEX IF EXISTS ai_post_embeddings_4_1_search_bit; | ||
DROP INDEX IF EXISTS ai_post_embeddings_5_1_search_bit; | ||
DROP INDEX IF EXISTS ai_post_embeddings_6_1_search_bit; | ||
DROP INDEX IF EXISTS ai_post_embeddings_7_1_search_bit; | ||
DROP INDEX IF EXISTS ai_post_embeddings_8_1_search_bit; | ||
DROP INDEX IF EXISTS ai_document_fragment_embeddings_1_1_search_bit; | ||
DROP INDEX IF EXISTS ai_document_fragment_embeddings_2_1_search_bit; | ||
DROP INDEX IF EXISTS ai_document_fragment_embeddings_3_1_search_bit; | ||
DROP INDEX IF EXISTS ai_document_fragment_embeddings_4_1_search_bit; | ||
DROP INDEX IF EXISTS ai_document_fragment_embeddings_5_1_search_bit; | ||
DROP INDEX IF EXISTS ai_document_fragment_embeddings_6_1_search_bit; | ||
DROP INDEX IF EXISTS ai_document_fragment_embeddings_7_1_search_bit; | ||
DROP INDEX IF EXISTS ai_document_fragment_embeddings_8_1_search_bit; | ||
SQL | ||
|
||
drop_table :ai_topic_embeddings, if_exists: true | ||
drop_table :ai_post_embeddings, if_exists: true | ||
drop_table :ai_document_fragment_embeddings, if_exists: true | ||
end | ||
|
||
def down | ||
end | ||
end |