Skip to content

Commit 40f9e7e

Browse files
committed
[MODEL] Added, that add_index for ActiveRecord models is only called when it doesn't exist already
1 parent c9c4d2f commit 40f9e7e

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

elasticsearch-model/examples/activerecord_associations.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@
5656
t.references :article
5757
t.timestamps
5858
end
59-
add_index(:comments, :article_id)
59+
60+
add_index(:comments, :article_id) unless index_exists?(:comments, :article_id)
6061
end
6162

6263
# ----- Elasticsearch client setup ----------------------------------------------------------------

elasticsearch-model/test/integration/active_record_associations_parent_child.rb

+4-1
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,15 @@ class ActiveRecordAssociationsParentChildIntegrationTest < Elasticsearch::Test::
7171
t.string :author
7272
t.timestamps
7373
end
74+
7475
create_table :answers do |t|
7576
t.text :text
7677
t.string :author
7778
t.references :question
7879
t.timestamps
79-
end and add_index(:answers, :question_id)
80+
end
81+
82+
add_index(:answers, :question_id) unless index_exists?(:answers, :question_id)
8083
end
8184

8285
Question.delete_all

0 commit comments

Comments
 (0)