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

[Feature] Add trilogy adapter support #825

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,20 @@ jobs:
--health-interval 10s
--health-timeout 5s
--health-retries 5
mysql:
image: mysql:5.7
ports:
- 3306:3306
env:
MYSQL_ROOT_PASSWORD: root
MYSQL_USER: github
MYSQL_PASSWORD: github
MYSQL_DATABASE: activerecord_import_test
options: >-
--health-cmd "mysqladmin ping -h localhost"
--health-interval 10s
--health-timeout 5s
--health-retries 5
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -81,6 +95,7 @@ jobs:
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
rubygems: latest
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added this because this error was raised. This should ensure this type of error doesn't happen again.

- name: Set up databases
run: |
sudo /etc/init.d/mysql start
Expand Down Expand Up @@ -110,6 +125,9 @@ jobs:
run: |
bundle exec rake test:spatialite
bundle exec rake test:sqlite3
- name: Run trilogy tests
if: ${{ matrix.env.AR_VERSION >= '7.0' && matrix.ruby != 'jruby' }}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not entirely sure where the trilogy gem stands with jruby, but I couldn't figure out a way to get it to successfully run.

run: bundle exec rake test:trilogy
lint:
runs-on: ubuntu-latest
env:
Expand Down
10 changes: 9 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ platforms :ruby do
gem "sqlite3", "~> #{sqlite3_version}"
# seamless_database_pool requires Ruby ~> 2.0
gem "seamless_database_pool", "~> 1.0.20" if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3.0.0')
gem "trilogy" if version >= 6.0
if version >= 6.0 && version <= 7.0
gem "activerecord-trilogy-adapter"
end
Comment on lines +29 to +32
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Regarding the integration of Trilogy, theoretically, it should seamlessly function with any framework equipped with the active record-trilogy-adapter. Notably, Rails 7.1 conveniently incorporates this adapter by default. You can explore the prerequisites for this gem here. However, a noteworthy discovery I made is the importance of the composite_primary_keys version. Compatibility issues arise with versions preceding AR 7 due to limitations intertwined with the ActiveRecord version.

end

platforms :jruby do
Expand All @@ -37,7 +41,11 @@ platforms :jruby do
end

# Support libs
gem "factory_bot"
if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.0.0")
gem "factory_bot"
else
gem "factory_bot", "~> 5", "< 6.4.5"
end
Comment on lines +44 to +48
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is required due to the newest version of factory_bot requiring Ruby 3.0.

gem "timecop"
gem "chronic"
gem "mocha", "~> 2.1.0"
Expand Down
1 change: 1 addition & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ ADAPTERS = %w(
sqlite3
spatialite
seamless_database_pool
trilogy
).freeze
ADAPTERS.each do |adapter|
namespace :test do
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

require "active_record/connection_adapters/trilogy_adapter"
require "activerecord-import/adapters/trilogy_adapter"

class ActiveRecord::ConnectionAdapters::TrilogyAdapter
include ActiveRecord::Import::TrilogyAdapter
end
7 changes: 7 additions & 0 deletions lib/activerecord-import/adapters/trilogy_adapter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

require "activerecord-import/adapters/mysql_adapter"

module ActiveRecord::Import::TrilogyAdapter
include ActiveRecord::Import::MysqlAdapter
end
9 changes: 9 additions & 0 deletions test/adapters/trilogy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

ENV["ARE_DB"] = "trilogy"

if ENV['AR_VERSION'].to_f <= 7.0
require "activerecord-trilogy-adapter"
require "trilogy_adapter/connection"
ActiveRecord::Base.extend TrilogyAdapter::Connection
end
5 changes: 5 additions & 0 deletions test/database.yml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,8 @@ sqlite3: &sqlite3

spatialite:
<<: *sqlite3

trilogy:
<<: *common
adapter: trilogy
host: mysql
4 changes: 4 additions & 0 deletions test/github/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,7 @@ sqlite3: &sqlite3

spatialite:
<<: *sqlite3

trilogy:
<<: *common
adapter: trilogy
7 changes: 7 additions & 0 deletions test/trilogy/import_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

require File.expand_path("#{File.dirname(__FILE__)}/../test_helper")
require File.expand_path("#{File.dirname(__FILE__)}/../support/assertions")
require File.expand_path("#{File.dirname(__FILE__)}/../support/mysql/import_examples")

should_support_mysql_import_functionality