Skip to content

Commit 4567963

Browse files
authored
Merge branch 'master' into podman_docker
2 parents 8f6f320 + 0bc6dda commit 4567963

16 files changed

Lines changed: 61 additions & 29 deletions

.github/workflows/run_test_suite.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,3 +147,9 @@ jobs:
147147
ANCESTRY_COLUMN_TYPE: binary
148148
run: |
149149
bundle exec rake
150+
- name: run trilogy tests
151+
if: matrix.mysql
152+
env:
153+
DB: trilogy
154+
run: |
155+
bundle exec rake

Appraisals

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
appraise "gemfile-#{ar_version.split('.').first(2).join}" do
88
gem 'activerecord', "~> #{ar_version}"
99
# so we are targeting the ruby version indirectly through active record
10+
# trilogy adapter is built into Rails 7.1+; older versions need the gem
11+
if ar_version < "7.1"
12+
gem "activerecord-trilogy-adapter"
13+
end
1014
if ar_version < "7.0"
1115
gem "sqlite3", "~> 1.6.9"
1216
elsif ar_version < "8.0"

Gemfile

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,19 @@ gemspec
66

77
gem "activerecord", "~> 7.2"
88

9-
if ENV["BUNDLE_INSTALL_SQLITE3"] == "1"
9+
if ENV["BUNDLE_INSTALL_SQLITE3"] == "1" || File.basename($PROGRAM_NAME) == "appraisal"
1010
gem "sqlite3", "~> 1.6.9"
1111
end
1212

13-
if ENV["BUNDLE_INSTALL_MYSQL"] == "1"
13+
if ENV["BUNDLE_INSTALL_MYSQL"] == "1" || File.basename($PROGRAM_NAME) == "appraisal"
1414
gem "mysql2"
1515
end
1616

17-
if ENV["BUNDLE_INSTALL_POSTGRES"] == "1"
17+
if ENV["BUNDLE_INSTALL_TRILOGY"] == "1" || File.basename($PROGRAM_NAME) == "appraisal"
18+
gem "trilogy"
19+
end
20+
21+
if ENV["BUNDLE_INSTALL_POSTGRES"] == "1" || File.basename($PROGRAM_NAME) == "appraisal"
1822
gem "pg"
1923
end
2024

gemfiles/gemfile_72.gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ source "https://rubygems.org"
55

66
gem "activerecord", "~> 7.2.1"
77
gem "mysql2"
8+
gem "trilogy"
89
gem "pg"
910
gem "sqlite3", "< 2.0"
1011

lib/ancestry/class_methods.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ def self._rebuild_counter_cache!(klass, column, counter_col, verbose: false)
275275
).count
276276
end
277277

278-
if %w(mysql mysql2).include?(klass.connection.adapter_name.downcase)
278+
if %w(mysql mysql2 trilogy).include?(klass.connection.adapter_name.downcase)
279279
klass.connection.execute %{
280280
UPDATE #{tbl} AS dest
281281
LEFT JOIN (

lib/ancestry/instance_methods_builder.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ def ordered_by_ancestry_and(order)
494494
end
495495

496496
def child_ancestry_sql
497-
#{format_module}.child_ancestry_sql(table_name, #{column.inspect}, :#{pk}, connection.adapter_name.downcase)
497+
#{format_module}.child_ancestry_sql(table_name, #{column.inspect}, :#{pk}, connection.adapter_name.downcase, integer_pk: #{integer_pk.inspect})
498498
end
499499

500500
def ancestry_depth_sql

lib/ancestry/ltree.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def self.replace_ancestry_sql(column, old_ancestry, new_ancestry, _klass)
7474
end
7575
end
7676

77-
def self.child_ancestry_sql(table_name, ancestry_column, primary_key, adapter)
77+
def self.child_ancestry_sql(table_name, ancestry_column, primary_key, adapter, integer_pk: true)
7878
col = "#{table_name}.#{ancestry_column}"
7979
pk = "#{table_name}.#{primary_key}"
8080
"CASE WHEN #{col} = '' THEN #{pk}::text::ltree ELSE #{col} || #{pk}::text::ltree END"

lib/ancestry/materialized_path.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def self.replace_ancestry_sql(column, old_ancestry, new_ancestry, klass)
6464
Arel.sql(replace_sql)
6565
end
6666

67-
def self.child_ancestry_sql(table_name, ancestry_column, primary_key, adapter)
67+
def self.child_ancestry_sql(table_name, ancestry_column, primary_key, adapter, integer_pk: true)
6868
pk_sql = concat(adapter, "#{table_name}.#{primary_key}")
6969
full_sql = concat(adapter, "#{table_name}.#{ancestry_column}", "'#{DELIMITER}'", "#{table_name}.#{primary_key}")
7070
%{
@@ -79,7 +79,7 @@ def self.child_ancestry_sql(table_name, ancestry_column, primary_key, adapter)
7979
def self.construct_root_id_sql(table_name, ancestry_column, primary_key, adapter)
8080
col = table_name ? "#{table_name}.#{ancestry_column}" : ancestry_column.to_s
8181
pk = table_name ? "#{table_name}.#{primary_key}" : primary_key.to_s
82-
if %w(mysql mysql2).include?(adapter)
82+
if %w(mysql mysql2 trilogy).include?(adapter)
8383
"CASE WHEN #{col} IS NULL THEN #{pk} ELSE CAST(SUBSTRING_INDEX(#{col}, '/', 1) AS UNSIGNED) END"
8484
elsif %w(pg postgresql postgis).include?(adapter)
8585
"CASE WHEN #{col} IS NULL THEN #{pk} ELSE CAST(SUBSTR(#{col}, 1, STRPOS(#{col}||'/', '/')-1) AS INTEGER) END"
@@ -92,7 +92,7 @@ def self.construct_root_id_sql(table_name, ancestry_column, primary_key, adapter
9292
# MP1: ancestry is NULL (root) or "1/2/3" (parent_id=3)
9393
def self.construct_parent_id_sql(table_name, ancestry_column, adapter)
9494
col = table_name ? "#{table_name}.#{ancestry_column}" : ancestry_column.to_s
95-
if %w(mysql mysql2).include?(adapter)
95+
if %w(mysql mysql2 trilogy).include?(adapter)
9696
"CASE WHEN #{col} IS NULL THEN NULL ELSE CAST(SUBSTRING_INDEX(#{col}, '/', -1) AS UNSIGNED) END"
9797
else
9898
"CASE WHEN #{col} IS NULL THEN NULL ELSE CAST(SUBSTR(#{col}, LENGTH(RTRIM(#{col}, REPLACE(#{col}, '/', ''))) + 1) AS INTEGER) END"
@@ -106,7 +106,7 @@ def self.construct_depth_sql(table_name, ancestry_column)
106106

107107
# mp1 roots are NULL — need NULLS FIRST or COALESCE to sort roots before children
108108
def self.ordered_by_ancestry(arel_column, adapter)
109-
if %w(mysql mysql2 sqlite sqlite3).include?(adapter)
109+
if %w(mysql mysql2 trilogy sqlite sqlite3).include?(adapter)
110110
Arel::Nodes::Ascending.new(arel_column)
111111
elsif ActiveRecord::VERSION::STRING >= "6.1"
112112
Arel::Nodes::Ascending.new(arel_column).nulls_first

lib/ancestry/materialized_path2.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def self.child_ancestry_value(ancestry_value, id)
3838
end
3939

4040
# trailing delimiter: col || pk || '/'
41-
def self.child_ancestry_sql(table_name, ancestry_column, primary_key, adapter)
41+
def self.child_ancestry_sql(table_name, ancestry_column, primary_key, adapter, integer_pk: true)
4242
concat(adapter, "#{table_name}.#{ancestry_column}", "#{table_name}.#{primary_key}", "'/'")
4343
end
4444

@@ -57,7 +57,7 @@ def self.indirects_condition(attr, child_ancestry)
5757
def self.construct_root_id_sql(table_name, ancestry_column, primary_key, adapter)
5858
col = table_name ? "#{table_name}.#{ancestry_column}" : ancestry_column.to_s
5959
pk = table_name ? "#{table_name}.#{primary_key}" : primary_key.to_s
60-
if %w(mysql mysql2).include?(adapter)
60+
if %w(mysql mysql2 trilogy).include?(adapter)
6161
"CASE WHEN #{col} = '/' THEN #{pk} ELSE CAST(SUBSTRING_INDEX(SUBSTRING(#{col}, 2), '/', 1) AS UNSIGNED) END"
6262
elsif %w(pg postgresql postgis).include?(adapter)
6363
"CASE WHEN #{col} = '/' THEN #{pk} ELSE CAST(SUBSTR(#{col}, 2, STRPOS(SUBSTR(#{col},2), '/')-1) AS INTEGER) END"
@@ -70,7 +70,7 @@ def self.construct_root_id_sql(table_name, ancestry_column, primary_key, adapter
7070
# MP2: ancestry is "/" (root) or "/1/2/3/" (parent_id=3)
7171
def self.construct_parent_id_sql(table_name, ancestry_column, adapter)
7272
col = table_name ? "#{table_name}.#{ancestry_column}" : ancestry_column.to_s
73-
if %w(mysql mysql2).include?(adapter)
73+
if %w(mysql mysql2 trilogy).include?(adapter)
7474
"CASE WHEN #{col} = '/' THEN NULL ELSE CAST(SUBSTRING_INDEX(SUBSTRING_INDEX(#{col}, '/', -2), '/', 1) AS UNSIGNED) END"
7575
else
7676
trimmed = "RTRIM(#{col},'/')"

lib/ancestry/materialized_path3.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def self.generate(ancestor_ids)
3636
def self.construct_root_id_sql(table_name, ancestry_column, primary_key, adapter)
3737
col = table_name ? "#{table_name}.#{ancestry_column}" : ancestry_column.to_s
3838
pk = table_name ? "#{table_name}.#{primary_key}" : primary_key.to_s
39-
if %w(mysql mysql2).include?(adapter)
39+
if %w(mysql mysql2 trilogy).include?(adapter)
4040
"CASE WHEN #{col} = '' THEN #{pk} ELSE CAST(SUBSTRING_INDEX(#{col}, '/', 1) AS UNSIGNED) END"
4141
elsif %w(pg postgresql postgis).include?(adapter)
4242
"CASE WHEN #{col} = '' THEN #{pk} ELSE CAST(SUBSTR(#{col}, 1, STRPOS(#{col}, '/')-1) AS INTEGER) END"
@@ -49,7 +49,7 @@ def self.construct_root_id_sql(table_name, ancestry_column, primary_key, adapter
4949
# MP3: ancestry is "" (root) or "1/2/3/" (parent_id=3)
5050
def self.construct_parent_id_sql(table_name, ancestry_column, adapter)
5151
col = table_name ? "#{table_name}.#{ancestry_column}" : ancestry_column.to_s
52-
if %w(mysql mysql2).include?(adapter)
52+
if %w(mysql mysql2 trilogy).include?(adapter)
5353
"CASE WHEN #{col} = '' THEN NULL ELSE CAST(SUBSTRING_INDEX(SUBSTRING_INDEX(#{col}, '/', -2), '/', 1) AS UNSIGNED) END"
5454
else
5555
trimmed = "RTRIM(#{col},'/')"

0 commit comments

Comments
 (0)