elasticsearch_record 4.0.0 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b3d4d1dd73be19114191e80cba0ec2844ab3049e380998f8ba48fed78f5c5837
4
- data.tar.gz: 252d5abb68af3199c73850337aac6d6ce2c6e379a9fd5f2bea1656447da29995
3
+ metadata.gz: a4f850e5600056256b188825cc8ca7067b4928014a09b05bb18ed37fb648478f
4
+ data.tar.gz: 19cec69e3a5a67752f8c94a2b22968e29dd5edf7166e4e205903164387e8606f
5
5
  SHA512:
6
- metadata.gz: 635066f96fb6713a4719ac6fc2a4338dd967b7ca990c9d2c1e644ca05a749be4932f9a07277a42da5340530f0291d7a2bd06edcfdaf89cdcda844339ede6b4fa
7
- data.tar.gz: 324d987c404a4dd0069d48c30866c6b854719eec91e3051321396ecf457b160dd16dfc29d47427c4e4a7193fc5d82e721f89013ae692ca9cc4642bb005503cb8
6
+ metadata.gz: 076f2df28822bba0a2148d2e3043cb403cb04d388c5034056eb7e298004694707b2e2b8c003257f8da4dc5d1bea80ae5bce8b851244cd146232b381ecc35543e
7
+ data.tar.gz: 91a406efac0912da2f2427120b0cf1fdbf1ae78166b9853c3af6099b6e19fd4aa09aebf962840f01345d4b32a523a1fd74706f827f86b0804a0f8ffef2199392
data/README.md CHANGED
@@ -16,8 +16,8 @@ _ElasticsearchRecord is a ActiveRecord adapter and provides similar functionalit
16
16
 
17
17
  **PLEASE NOTE:**
18
18
 
19
- - This is the `main`-branch, which supports rails **8.0** _(see section 'Rails_Versions' for supported versions)_
20
- - supports ActiveRecord ~> 7.2 + Elasticsearch >= 7.17
19
+ - This is the `main`-branch, which supports rails **8.1** _(see section 'Rails_Versions' for supported versions)_
20
+ - supports ActiveRecord ~> 8.1 + Elasticsearch >= 7.17
21
21
  - added features up to Elasticsearch `8.17.1` _(tested against `8.19.14`)_
22
22
  - _ES|QL_ queries _(`TYPE_ESQL` / the `esql.query` gate)_ require **Elasticsearch >= 8.11**, where the feature became
23
23
  generally available. All other features remain available from Elasticsearch `7.17`.
@@ -28,6 +28,13 @@ _ElasticsearchRecord is a ActiveRecord adapter and provides similar functionalit
28
28
 
29
29
  Supported rails versions:
30
30
 
31
+ ### Rails 8.1:
32
+ _(since gem version 5.0)_
33
+
34
+ https://github.com/ruby-smart/elasticsearch_record/tree/rails-8-1-stable
35
+
36
+ [![rails-7-1-stable](https://img.shields.io/badge/rails-8.1.stable-orange.svg)](https://github.com/ruby-smart/elasticsearch_record/tree/rails-8-1-stable)
37
+
31
38
  ### Rails 8.0:
32
39
  _(since gem version 4.0)_
33
40
 
data/docs/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # ElasticsearchRecord - CHANGELOG
2
2
 
3
+ ## [5.0.0] - 2026-09-10
4
+ * [add] **BREAKING**: requires `activerecord ~> 8.1.0`
5
+ * [add] `Relation::ValueMethods#limit!` - keeps the `'__max__'` & `Float::INFINITY` limits, which rails now casts through `Integer()`
6
+ * [add] specs for `SchemaStatements#new_column_from_field` resolving the cast type upfront
7
+ * [ref] `Elasticsearch::Column#initialize` takes `cast_type` as 2nd positional argument
8
+ * [ref] `SchemaStatements#lookup_cast_type_from_column` -> `#lookup_multicast_cast_type` - resolves from a `sql_type` and is called upfront
9
+ * [ref] `DatabaseStatements#internal_execute` guards writes through `#write_query?` & `#ensure_writes_are_allowed`
10
+ * [ref] `StatementCache::PartialQuery#initialize` takes the `retryable:` flag
11
+
3
12
  ## [4.0.0] - 2026-09-08
4
13
  * [add] **BREAKING**: requires `activerecord ~> 8.0.0`
5
14
  * [add] `ElasticsearchRecord::Result#indexed_rows` - rails 8.0 instantiates records through this method instead of iterating the result set itself.
@@ -14,7 +14,7 @@ DESC
14
14
 
15
15
  spec.homepage = "https://github.com/ruby-smart/elasticsearch_record"
16
16
  spec.license = "MIT"
17
- spec.required_ruby_version = ">= 3.1.0"
17
+ spec.required_ruby_version = ">= 3.2.0"
18
18
 
19
19
  spec.metadata["allowed_push_host"] = "https://rubygems.org"
20
20
  spec.metadata["homepage_uri"] = spec.homepage
@@ -32,7 +32,7 @@ DESC
32
32
 
33
33
  spec.require_paths = ["lib"]
34
34
 
35
- spec.add_dependency 'activerecord', '~> 8.0.0'
35
+ spec.add_dependency 'activerecord', '~> 8.1.0'
36
36
  spec.add_dependency 'elasticsearch', '>= 7.17'
37
37
 
38
38
  spec.add_development_dependency 'coveralls_reborn', '~> 0.25'
@@ -7,14 +7,14 @@ module ActiveRecord
7
7
 
8
8
  attr_reader :virtual, :fields, :properties, :meta, :enabled
9
9
 
10
- def initialize(name, default, sql_type_metadata = nil, virtual: false, fields: nil, properties: nil, meta: nil, enabled: nil, **kwargs)
10
+ def initialize(name, cast_type, default, sql_type_metadata = nil, virtual: false, fields: nil, properties: nil, meta: nil, enabled: nil, **kwargs)
11
11
  @virtual = virtual
12
12
  @fields = fields.presence || []
13
13
  @properties = properties.presence || []
14
14
  @meta = meta.presence || {}
15
15
  @enabled = enabled.nil? ? true : enabled
16
16
 
17
- super(name, default, sql_type_metadata, true, nil, **kwargs)
17
+ super(name, cast_type, default, sql_type_metadata, true, nil, **kwargs)
18
18
  end
19
19
 
20
20
  # returns comment from meta
@@ -160,7 +160,7 @@ module ActiveRecord
160
160
  raise ActiveRecord::StatementInvalid, 'Unable to execute! Provided query is invalid.' unless query.valid?
161
161
 
162
162
  # checks for write query - raises an exception if connection is locked to readonly ...
163
- check_if_write_query(query)
163
+ ensure_writes_are_allowed(query) if write_query?(query)
164
164
 
165
165
  api(query.gate, query.query_arguments, name, async: async, allow_retry: allow_retry, materialize_transactions: materialize_transactions)
166
166
  end
@@ -226,6 +226,8 @@ module ActiveRecord
226
226
  def new_column_from_field(_table_name, field, _definitions)
227
227
  ActiveRecord::ConnectionAdapters::Elasticsearch::Column.new(
228
228
  field["name"],
229
+ # the cast type is resolved upfront and stored on the column
230
+ lookup_multicast_cast_type(field["type"]),
229
231
  field["null_value"],
230
232
  fetch_type_metadata(field["type"]),
231
233
  meta: field['meta'],
@@ -236,13 +238,13 @@ module ActiveRecord
236
238
  )
237
239
  end
238
240
 
239
- # lookups from building the @columns_hash.
241
+ # resolves the cast type of the provided +sql_type+ and wraps it into a +MulticastValue+.
240
242
  # since Elasticsearch has the "feature" to provide multicast values on any type, we need to fetch them ...
241
243
  # you know, ES can return an integer or an array of integers for any column ...
242
- # @param [ActiveRecord::ConnectionAdapters::Elasticsearch::Column] column
244
+ # @param [String] sql_type
243
245
  # @return [ActiveRecord::ConnectionAdapters::Elasticsearch::Type::MulticastValue]
244
- def lookup_cast_type_from_column(column)
245
- type_map.lookup(:multicast_value, super)
246
+ def lookup_multicast_cast_type(sql_type)
247
+ type_map.lookup(:multicast_value, lookup_cast_type(sql_type))
246
248
  end
247
249
 
248
250
  # Returns a array of tables primary keys.
@@ -114,8 +114,8 @@ module ActiveRecord # :nodoc:
114
114
  # this special Type is required to parse a ES-value into the +nested_type+, array or hash.
115
115
  # For arrays & hashes it tries to cast the values with the provided +nested_type+
116
116
  # but falls back to provided value if cast fails.
117
- # This type cannot be accessed through the mapping and is only called @ #lookup_cast_type_from_column
118
- # @see ActiveRecord::ConnectionAdapters::Elasticsearch::SchemaStatements#lookup_cast_type_from_column
117
+ # This type cannot be accessed through the mapping and is only called @ #lookup_multicast_cast_type
118
+ # @see ActiveRecord::ConnectionAdapters::Elasticsearch::SchemaStatements#lookup_multicast_cast_type
119
119
  m.register_type :multicast_value do |_type, nested_type|
120
120
  ActiveRecord::ConnectionAdapters::Elasticsearch::Type::MulticastValue.new(nested_type: nested_type)
121
121
  end
File without changes
@@ -7,7 +7,7 @@ module ElasticsearchRecord
7
7
  end
8
8
 
9
9
  module VERSION
10
- MAJOR = 4
10
+ MAJOR = 5
11
11
  MINOR = 0
12
12
  TINY = 0
13
13
  PRE = nil
@@ -43,6 +43,14 @@ module ElasticsearchRecord
43
43
  @values[:aggs] = value
44
44
  end
45
45
 
46
+ # overwrite the +limit!+ method, since the default implementation casts the provided value
47
+ # through +Integer()+ before it reaches the +limit_value=+ setter - which would raise
48
+ # for our special values ('__max__' & +Float::INFINITY+).
49
+ def limit!(value)
50
+ self.limit_value = value
51
+ self
52
+ end
53
+
46
54
  # overwrite the limit_value setter, to provide a special behaviour of auto-setting the +max_result_window+.
47
55
  def limit_value=(limit)
48
56
  if limit == '__max__' || limit == Float::INFINITY || (limit.nil? && delegate_query_nil_limit?)
@@ -4,8 +4,9 @@ module ElasticsearchRecord
4
4
  class StatementCache < ActiveRecord::StatementCache
5
5
 
6
6
  class PartialQuery < ActiveRecord::StatementCache::PartialQuery # :nodoc:
7
- def initialize(values)
8
- @values = values
7
+ def initialize(values, retryable:)
8
+ @values = values
9
+ @retryable = retryable
9
10
  # no need to create indexes
10
11
  end
11
12
 
@@ -77,8 +78,8 @@ module ElasticsearchRecord
77
78
  end
78
79
  end
79
80
 
80
- def self.partial_query(values)
81
- PartialQuery.new(values)
81
+ def self.partial_query(...)
82
+ PartialQuery.new(...)
82
83
  end
83
84
 
84
85
  def self.partial_query_collector
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elasticsearch_record
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0
4
+ version: 5.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Gonsior
@@ -15,14 +15,14 @@ dependencies:
15
15
  requirements:
16
16
  - - "~>"
17
17
  - !ruby/object:Gem::Version
18
- version: 8.0.0
18
+ version: 8.1.0
19
19
  type: :runtime
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
23
  - - "~>"
24
24
  - !ruby/object:Gem::Version
25
- version: 8.0.0
25
+ version: 8.1.0
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: elasticsearch
28
28
  requirement: !ruby/object:Gem::Requirement
@@ -228,7 +228,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
228
228
  requirements:
229
229
  - - ">="
230
230
  - !ruby/object:Gem::Version
231
- version: 3.1.0
231
+ version: 3.2.0
232
232
  required_rubygems_version: !ruby/object:Gem::Requirement
233
233
  requirements:
234
234
  - - ">="