-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First steps to extracting the search engine into it's own object.
- Loading branch information
Showing
19 changed files
with
432 additions
and
181 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# frozen_string_literal: true | ||
|
||
# == Schema Information | ||
# | ||
# Table name: search_endpoints | ||
# | ||
# id :bigint not null, primary key | ||
# api_method :string(255) | ||
# custom_headers :string(1000) | ||
# endpoint_url :string(500) | ||
# name :string(255) | ||
# search_engine :string(50) | ||
# created_at :datetime not null | ||
# updated_at :datetime not null | ||
# owner_id :integer | ||
# | ||
|
||
class SearchEndpoint < ApplicationRecord | ||
# Associations | ||
# too late now! | ||
# rubocop:disable Rails/HasAndBelongsToMany | ||
has_and_belongs_to_many :teams, | ||
join_table: 'teams_search_endpoints' | ||
# rubocop:enable Rails/HasAndBelongsToMany | ||
|
||
belongs_to :owner, | ||
class_name: 'User', optional: true | ||
|
||
has_many :tries, dependent: :nullify, inverse_of: :search_endpoint | ||
|
||
# Validations | ||
# validates :case_name, presence: true | ||
# validates_with ScorerExistsValidator | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
# frozen_string_literal: true | ||
|
||
json.args try.args | ||
json.custom_headers try.custom_headers | ||
json.custom_headers try.search_endpoint&.custom_headers | ||
json.curator_vars try.curator_vars_map | ||
json.escape_query try.escape_query | ||
json.api_method try.api_method | ||
json.api_method try.search_endpoint&.api_method | ||
json.field_spec try.field_spec | ||
json.name try.name | ||
json.number_of_rows try.number_of_rows | ||
json.query_params try.query_params | ||
json.search_engine try.search_engine | ||
json.search_url try.search_url | ||
json.search_engine try.search_endpoint&.search_engine | ||
json.search_url try.search_endpoint&.endpoint_url | ||
json.try_number try.try_number |
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,16 @@ | ||
class ExtractSearchEndpoint < ActiveRecord::Migration[7.0] | ||
def change | ||
|
||
create_table :search_endpoints do |t| | ||
t.string "name", limit: 255 | ||
t.integer "owner_id" | ||
t.string "search_engine", limit: 50 | ||
t.string "endpoint_url", limit: 500 | ||
t.string "api_method" | ||
t.string "custom_headers", limit: 1000 | ||
t.timestamps | ||
end | ||
|
||
add_column :tries, :search_endpoint_id, :bigint, foreign_key: true | ||
end | ||
end |
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,7 @@ | ||
class CreateJoinToTeams < ActiveRecord::Migration[7.0] | ||
def change | ||
create_join_table :search_endpoints, :teams, table_name: :teams_search_endpoints do |t| | ||
end | ||
|
||
end | ||
end |
22 changes: 22 additions & 0 deletions
22
db/migrate/20230816183004_create_search_endpoints_from_tries.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,22 @@ | ||
class CreateSearchEndpointsFromTries < ActiveRecord::Migration[7.0] | ||
def change | ||
Try.all.each do |try| | ||
|
||
# Go through and find each unique set of values from all the tries, | ||
# and create a single end point that is used by multiple tries where it | ||
# doesn't change. | ||
search_endpoint = SearchEndpoint.find_or_create_by search_engine: try.search_engine, | ||
endpoint_url: try.search_url, | ||
api_method: try.api_method, | ||
custom_headers: try.custom_headers, | ||
owner_id: try.case.owner_id, | ||
name: "#{try.search_engine} #{try.search_url}" | ||
|
||
try.search_endpoint = search_endpoint | ||
|
||
search_endpoint.save! | ||
try.save! | ||
|
||
end | ||
end | ||
end |
10 changes: 10 additions & 0 deletions
10
db/migrate/20230816195233_drop_search_endpoint_fields_from_try.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,10 @@ | ||
class DropSearchEndpointFieldsFromTry < ActiveRecord::Migration[7.0] | ||
def change | ||
# Now that we've moved all the fields over to SearchEndpoint, lets | ||
# clean up after ourselves. | ||
remove_column :tries, :search_engine | ||
remove_column :tries, :search_url | ||
remove_column :tries, :api_method | ||
remove_column :tries, :custom_headers | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Oops, something went wrong.