-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: mysql support #43
Conversation
Breaking change: The gem no longer depends directly on the `pg_search` gem. This means models using `pg_search_scope` must be updated to explicitly `include PgSearch::Model`.
it "can search ignoring diacritics" do | ||
all_items = BasicFilterableTestModel.where(nil) | ||
expected_items = [all_items.first.name] | ||
|
||
filtered = BasicFilterableTestModel.filter(params: ActionController::Parameters.new({ filter: { search: target_user.name.split(//).join("").tr("aeiouylszcn", "àèîôûÿłšżçñ") } })) | ||
|
||
expect(filtered.items.map(&:name)).to eq(expected_items) | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this test had a dependency on pg_search
and seems pretty specific to pg_search
so I removed it
if ActiveRecord::Base.connection_db_config.adapter == "mysql2" | ||
"LEFT OUTER JOIN `#{first_model_table}` ON `#{first_model_table}`.id = `#{base_model_table}`.`#{polymorphic_association_id}` AND `#{base_model_table}`.`#{polymorphic_association_type}` = '#{first_model_name}'" | ||
else | ||
"LEFT OUTER JOIN \"#{first_model_table}\" ON \"#{first_model_table}\".id = \"#{base_model_table}\".\"#{polymorphic_association_id}\" AND \"#{base_model_table}\".\"#{polymorphic_association_type}\" = '#{first_model_name}'" | ||
end | ||
end | ||
end | ||
|
||
describe ".coalesce" do | ||
it "creates a valid function" do | ||
actual_output = described_class.coalesce([DummyModel], "some_column") | ||
|
||
expect(actual_output).to eq("coalesce(\"dummy_models\".\"some_column\")") | ||
if ActiveRecord::Base.connection_db_config.adapter == "mysql2" | ||
expect(actual_output).to eq("coalesce(`dummy_models`.`some_column`)") | ||
else | ||
expect(actual_output).to eq("coalesce(\"dummy_models\".\"some_column\")") | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there were only two tests that were expecting postgres syntax
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This PR adds support for mysql with the
mysql2
adapter.It is a major version bump
2.0.0 -> 3.0.0
because thepg
andpg_search
dependencies are now development dependencies. See theBreaking Change
section for more details.The rspec test suite now runs on both Postgres and MySQL databases during the test github action.
Breaking Change
The gem no longer depends directly on the
pg_search
gem. This meansmodels using
pg_search_scope
must be updated to explicitlyinclude PgSearch::Model
.When upgrading from 2.x to 3.x, follow these steps:
pg
andpg_search
gems are present ifpg_search_scope
is usedinclude SnFilterable::Filterable
that also usespg_search_scope
include PgSearch::Model
for results from step 2