diff --git a/.github/workflows/mariadb.yml b/.github/workflows/mariadb.yml index 565bda7e..d0cd2fa6 100644 --- a/.github/workflows/mariadb.yml +++ b/.github/workflows/mariadb.yml @@ -26,7 +26,7 @@ jobs: --health-timeout 5s --health-retries 5 env: - BUNDLE_WITHOUT: "db2 oracle sqlserver sqlite postgresql" + BUNDLE_WITHOUT: "db2 oracle sqlserver sqlite postgresql trilogy" BUNDLE_JOBS: 4 BUNDLE_PATH: vendor/bundle steps: diff --git a/.github/workflows/mysql.yml b/.github/workflows/mysql.yml index ccc58418..9e701f42 100644 --- a/.github/workflows/mysql.yml +++ b/.github/workflows/mysql.yml @@ -26,7 +26,7 @@ jobs: --health-timeout 5s --health-retries 5 env: - BUNDLE_WITHOUT: "db2 oracle sqlserver sqlite postgresql" + BUNDLE_WITHOUT: "db2 oracle sqlserver sqlite postgresql trilogy" BUNDLE_JOBS: 4 BUNDLE_PATH: vendor/bundle steps: diff --git a/.github/workflows/postgresql.yml b/.github/workflows/postgresql.yml index a1261dd8..90b963ff 100644 --- a/.github/workflows/postgresql.yml +++ b/.github/workflows/postgresql.yml @@ -24,7 +24,7 @@ jobs: --health-timeout 5s --health-retries 5 env: - BUNDLE_WITHOUT: "db2 oracle sqlserver mysql splite" + BUNDLE_WITHOUT: "db2 oracle sqlserver mysql sqlite trilogy" BUNDLE_JOBS: 4 BUNDLE_PATH: vendor/bundle steps: diff --git a/.github/workflows/sqlite.yml b/.github/workflows/sqlite.yml index bc02ad3e..24a39e8c 100644 --- a/.github/workflows/sqlite.yml +++ b/.github/workflows/sqlite.yml @@ -11,7 +11,7 @@ jobs: ruby: [2.7, "3.0", 3.1, 3.2] runs-on: ${{matrix.os}} env: - BUNDLE_WITHOUT: "db2 oracle sqlserver postgresql mysql" + BUNDLE_WITHOUT: "db2 oracle sqlserver postgresql mysql trilogy" BUNDLE_JOBS: 4 BUNDLE_PATH: vendor/bundle steps: diff --git a/Gemfile b/Gemfile index ac1ab013..327980df 100644 --- a/Gemfile +++ b/Gemfile @@ -28,6 +28,11 @@ group :sqlserver do gem 'activerecord-sqlserver-adapter' end +group :trilogy do + gem 'trilogy' + gem 'activerecord-trilogy-adapter' +end + group :test do gem 'minitest' end diff --git a/Rakefile b/Rakefile index 93fdb0b4..177a314f 100644 --- a/Rakefile +++ b/Rakefile @@ -23,7 +23,7 @@ Dir.glob('tasks/**/*.rake').each do |rake_file| end # Set up test tasks for each supported connection adapter -%w(mysql sqlite oracle oracle_enhanced postgresql ibm_db sqlserver).each do |adapter| +%w(mysql sqlite oracle oracle_enhanced postgresql ibm_db sqlserver trilogy).each do |adapter| namespace adapter do desc "Run tests using the #{adapter} adapter" task "test" do diff --git a/lib/composite_primary_keys.rb b/lib/composite_primary_keys.rb index 7fc83cae..1666770d 100644 --- a/lib/composite_primary_keys.rb +++ b/lib/composite_primary_keys.rb @@ -114,4 +114,4 @@ require_relative 'composite_primary_keys/arel/to_sql' require_relative 'composite_primary_keys/arel/sqlserver' -require_relative 'composite_primary_keys/table_metadata' \ No newline at end of file +require_relative 'composite_primary_keys/table_metadata' diff --git a/lib/composite_primary_keys/connection_adapters/abstract/database_statements.rb b/lib/composite_primary_keys/connection_adapters/abstract/database_statements.rb index 56795996..b01107fb 100644 --- a/lib/composite_primary_keys/connection_adapters/abstract/database_statements.rb +++ b/lib/composite_primary_keys/connection_adapters/abstract/database_statements.rb @@ -6,8 +6,7 @@ def insert(arel, name = nil, pk = nil, id_value = nil, sequence_name = nil, bind value = exec_insert(sql, name, binds, pk, sequence_name) return id_value if id_value - - if pk.is_a?(Array) && !value.empty? + if pk.is_a?(Array) && value.respond_to?(:empty?) && !value.empty? # This is a CPK model and the query result is not empty. Thus we can figure out the new ids for each # auto incremented field pk.map {|key| value.first[key]} diff --git a/lib/composite_primary_keys/relation.rb b/lib/composite_primary_keys/relation.rb index 8b19c548..14e23914 100644 --- a/lib/composite_primary_keys/relation.rb +++ b/lib/composite_primary_keys/relation.rb @@ -102,6 +102,8 @@ def cpk_subquery(stmt) # database adapter to decide how to proceed. if defined?(ActiveRecord::ConnectionAdapters::Mysql2Adapter) && connection.is_a?(ActiveRecord::ConnectionAdapters::Mysql2Adapter) cpk_mysql_subquery(stmt) + elsif defined?(ActiveRecord::ConnectionAdapters::TrilogyAdapter) && connection.is_a?(ActiveRecord::ConnectionAdapters::TrilogyAdapter) + cpk_mysql_subquery(stmt) elsif defined?(ActiveRecord::ConnectionAdapters::SQLServerAdapter) && connection.is_a?(ActiveRecord::ConnectionAdapters::SQLServerAdapter) cpk_exists_subquery(stmt) else diff --git a/scripts/console.rb b/scripts/console.rb index 27c69cfc..851c8e5e 100755 --- a/scripts/console.rb +++ b/scripts/console.rb @@ -1,7 +1,7 @@ #!/usr/bin/env ruby # -# if run as script, load the file as library while starting irb +# if run as script, load the file as library while starting irb # if __FILE__ == $0 irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb' @@ -12,7 +12,7 @@ # # check if the given adapter is supported (default: mysql) # -adapters = %w[mysql sqlite oracle oracle_enhanced postgresql ibm_db] +adapters = %w[mysql sqlite oracle oracle_enhanced postgresql ibm_db trilogy] adapter = ENV['ADAPTER'] || 'mysql' unless adapters.include? adapter puts "Usage: #{__FILE__} " diff --git a/tasks/databases/trilogy.rake b/tasks/databases/trilogy.rake new file mode 100644 index 00000000..d3e922da --- /dev/null +++ b/tasks/databases/trilogy.rake @@ -0,0 +1,23 @@ +namespace :trilogy do + task :setup do + require 'bundler' + Bundler.require(:default, :trilogy) + end + + task :create_database => :setup do + Rake::Task["mysql:create_database"].invoke + end + + desc 'Build the MySQL test database' + task :build_database => [:create_database] do + Rake::Task["mysql:build_database"].invoke + end + + desc 'Drop the MySQL test database' + task :drop_database => :setup do + Rake::Task["mysql:drop_database"].invoke + end + + desc 'Rebuild the MySQL test database' + task :rebuild_database => [:drop_database, :build_database] +end diff --git a/test/abstract_unit.rb b/test/abstract_unit.rb index cbb14f46..4645bf38 100644 --- a/test/abstract_unit.rb +++ b/test/abstract_unit.rb @@ -14,6 +14,12 @@ puts "Loaded #{spec_name}" # And now connect to the database +if spec_name == "trilogy" + require "activerecord-trilogy-adapter" + require "trilogy_adapter/connection" + ActiveRecord::Base.extend TrilogyAdapter::Connection +end + ActiveRecord::Base.establish_connection(spec) # Tell active record about the configuration diff --git a/test/connections/databases.ci.yml b/test/connections/databases.ci.yml index d7ba6c2a..09b63edc 100644 --- a/test/connections/databases.ci.yml +++ b/test/connections/databases.ci.yml @@ -20,3 +20,13 @@ sqlite: adapter: sqlite3 database: <%= File.join(project_root, 'db', 'composite_primary_keys_unittest.sqlite') %> +trilogy: + adapter: trilogy + username: github + password: github + host: 127.0.0.1 + port: 3306 + encoding: utf8mb4 + charset: utf8mb4 + collation: utf8mb4_bin + database: composite_primary_keys_unittest