Skip to content
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

Test with multiple DB engines #35

Merged
merged 2 commits into from
Aug 26, 2023
Merged

Test with multiple DB engines #35

merged 2 commits into from
Aug 26, 2023

Conversation

dim
Copy link
Member

@dim dim commented Aug 26, 2023

Fixes #33

@dim dim force-pushed the ci/multi-db branch 14 times, most recently from 30f7c94 to d722897 Compare August 26, 2023 10:00
@dim dim merged commit c416113 into main Aug 26, 2023
@dim dim deleted the ci/multi-db branch August 26, 2023 12:51
@@ -15,7 +15,13 @@ def self.truncate!
scope :created_before, ->(date = 1.month.ago) { where(arel_table[:created_at].lt(date)) }

def self.namespaced(namespace)
where(arel_table[:key].matches("#{namespace}:%"))
case ActiveRecord::Base.connection.adapter_name
when 'PostgreSQL'
Copy link
Contributor

@skatkov skatkov Aug 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: In most cases, ActiveRecord::Base.connection.adapter_name will return 'PostgreSQL'. But there are cases where this might no be true, even if PostgreSQL is used.

There are so much factors, when this value could look different e.g. non pg database driver, wrapper for pg driver or even database adapter naming in database.yml could alter AR.adapter_name due to unspoken conventions of ActiveRecord.

And in general, even huge PG fans still can't agree on how to capitalize PostgreSQL name.

I would recommend to go with this as a method to detect PG adapters.
ActiveRecord::Base.connection.adapter_name =~ /postg/

case ActiveRecord::Base.connection.adapter_name
when 'PostgreSQL'
ifx = Arel::Nodes::InfixOperation.new('IN', Arel::Nodes.build_quoted(namespace), arel_table[:key])
where(Arel::Nodes::NamedFunction.new('POSITION', [ifx]).eq(1))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: I might be mistaken, I don't have big exposure with MySQL and MariaDB.

But this AREL query could be used for MariaDB/MySQL case as well.

Seems like IN/POSITION is supported by both. I couldn't find mentions about IN in documentation, but I found comments in various pages where people mention that it works.

Sqlite doesn't seem to support POSITION, though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CI: Testsuit should run against supported databases
2 participants