activerecord-bitemporal 6.1.0 → 7.0.1

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: 7676d93276c1c24acbb001b135c344b94d3b0b8084d2ef17423c238b5e06bfaf
4
- data.tar.gz: f07cc0d7a716c99d3d85f352588309351b3ed408e6ddec5ad153096dd2310786
3
+ metadata.gz: 553dc55266366a109d0f4275ed0e70229984d1fb139b858be2828c2d75e0c182
4
+ data.tar.gz: dccb0a53b560b6c3a8eebd29e46e30b816c15002eddfbf0cbf6355838167fd76
5
5
  SHA512:
6
- metadata.gz: 95b6ea9e934a5818d3fc3e0409faef14bde66aeafbd0a0a168a1649e3b88ed6a11a0e8174094f7527ae4ba47076449db17a17597b83587a8986815af458b6c19
7
- data.tar.gz: ece5cc5e3a8846f6495b63b30eb35eb4648e95b712e582b72fa67dafd1cfe9af1384737a11cf272d06cf73ed9e9121a674a6e0ea90434edb77d1715603cf7ffe
6
+ metadata.gz: fcb1d50c24df2103608ff407207145b84a87649f862db1625343ce0f5281dde85f5c2a43af10ab5b72b6b2f118ace4705137a28a774ed159c7472bde4b1b091b
7
+ data.tar.gz: 93fb11c615891a252b597678c4c53049460c093e80003f657e17a9c7ef2149592fd0ae91bc51f80da7619074e3de62f32e6207a7cbd281d48ea44ac23f6646b7
data/CHANGELOG.md CHANGED
@@ -1,8 +1,87 @@
1
1
  # Changelog
2
2
 
3
+ ## Unreleased
4
+
5
+ ### Breaking Changes
6
+
7
+ ### Added
8
+
9
+ ### Changed
10
+
11
+ ### Deprecated
12
+
13
+ ### Removed
14
+
15
+ ### Fixed
16
+
17
+ ### Chores
18
+
19
+ ## 7.0.1
20
+
21
+ ### Breaking Changes
22
+
23
+ ### Added
24
+
25
+ ### Changed
26
+
27
+ ### Deprecated
28
+
29
+ ### Removed
30
+
31
+ ### Fixed
32
+
33
+ - [Use bitemporal_id as primary key for Rails 8+ excluding/without #252](https://github.com/kufu/activerecord-bitemporal/pull/252)
34
+ - [Use bitemporal_id as primary key for Rails 8+ AR::Batches #251](https://github.com/kufu/activerecord-bitemporal/pull/251)
35
+
36
+ ### Chores
37
+
38
+ - [Bump ruby/setup-ruby from 1.299.0 to 1.300.0 #253](https://github.com/kufu/activerecord-bitemporal/pull/253)
39
+ - [Bump rubygems/release-gem from 1.1.2 to 1.2.0 #250](https://github.com/kufu/activerecord-bitemporal/pull/250)
40
+ - [Bump ruby/setup-ruby from 1.295.0 to 1.299.0 #249](https://github.com/kufu/activerecord-bitemporal/pull/249)
41
+ - [Bump ruby/setup-ruby from 1.288.0 to 1.295.0 #248](https://github.com/kufu/activerecord-bitemporal/pull/248)
42
+
43
+ ## 7.0.0
44
+
45
+ ### Breaking Changes
46
+
47
+ - [Drop support Rails 7.0 #230](https://github.com/kufu/activerecord-bitemporal/pull/230)
48
+
49
+ ### Added
50
+
51
+ - [Add Ruby 4.0 in CI #236](https://github.com/kufu/activerecord-bitemporal/pull/236)
52
+
53
+ ### Changed
54
+
55
+ ### Deprecated
56
+
57
+ ### Removed
58
+
59
+ ### Fixed
60
+
61
+ - [Localize patch for AR::Relation#primary_key in Rails 8.0+ #243](https://github.com/kufu/activerecord-bitemporal/pull/243)
62
+ - In Rails 8.0+, the global override of `ActiveRecord::Relation#primary_key` with `bitemporal_id_key` has been removed. As a result, the following methods now use `primary_key` (i.e., `id`) instead of `bitemporal_id_key`:
63
+ - `find_each`, `find_in_batches`, and `in_batches`: the default cursor column for ordering and keyset pagination changes (records are not missed or duplicated, but iteration order differs)
64
+ - [Fix finder methods ordering on Rails 8.0+ #237](https://github.com/kufu/activerecord-bitemporal/pull/237)
65
+
66
+ ### Chores
67
+
68
+ - [Manage development dependencies in gemfiles #240](https://github.com/kufu/activerecord-bitemporal/pull/240)
69
+ - [Randomize test execution order #239](https://github.com/kufu/activerecord-bitemporal/pull/239)
70
+ - [Update release GitHub Action #232](https://github.com/kufu/activerecord-bitemporal/pull/232)
71
+ - [Bump ruby/setup-ruby from 1.286.0 to 1.288.0 #244](https://github.com/kufu/activerecord-bitemporal/pull/244)
72
+ - [Bump actions/checkout from 6.0.1 to 6.0.2 #242](https://github.com/kufu/activerecord-bitemporal/pull/242)
73
+ - [Bump ruby/setup-ruby from 1.278.0 to 1.286.0 #241](https://github.com/kufu/activerecord-bitemporal/pull/241)
74
+ - [Bump ruby/setup-ruby from 1.268.0 to 1.278.0 #234](https://github.com/kufu/activerecord-bitemporal/pull/234)
75
+ - [Update reviewers #231](https://github.com/kufu/activerecord-bitemporal/pull/231)
76
+ - [Bump actions/checkout from 6.0.0 to 6.0.1 #229](https://github.com/kufu/activerecord-bitemporal/pull/229)
77
+ - [Bump ruby/setup-ruby from 1.267.0 to 1.268.0 #228](https://github.com/kufu/activerecord-bitemporal/pull/228)
78
+ - [Bump actions/checkout from 5.0.0 to 6.0.0 #227](https://github.com/kufu/activerecord-bitemporal/pull/227)
79
+ - [Bump codespell-project/actions-codespell from 2.1 to 2.2 #226](https://github.com/kufu/activerecord-bitemporal/pull/226)
80
+ - [Bump ruby/setup-ruby from 1.265.0 to 1.267.0 #225](https://github.com/kufu/activerecord-bitemporal/pull/225)
81
+
3
82
  ## 6.1.0
4
83
 
5
- ### Breaking Changed
84
+ ### Breaking Changes
6
85
 
7
86
  ### Added
8
87
 
@@ -39,7 +118,7 @@
39
118
 
40
119
  ## 6.0.0
41
120
 
42
- ### Breaking Changed
121
+ ### Breaking Changes
43
122
 
44
123
  - [Add Ruby 3.4 and remove Ruby 3.0 in CI #185](https://github.com/kufu/activerecord-bitemporal/pull/185)
45
124
  - [Drop support Rails 6.1 #192](https://github.com/kufu/activerecord-bitemporal/pull/192)
@@ -147,7 +226,7 @@
147
226
 
148
227
  ## 5.0.0
149
228
 
150
- ### Breaking Changed
229
+ ### Breaking Changes
151
230
 
152
231
  - [CI against Ruby 3.2, 3.3, Drop Ruby 2.7 and Rails 6.0 #150](https://github.com/kufu/activerecord-bitemporal/pull/150)
153
232
 
@@ -228,7 +307,7 @@
228
307
 
229
308
  ## 4.0.0
230
309
 
231
- ### Breaking Changed
310
+ ### Breaking Changes
232
311
 
233
312
  - [[proposal]When bitemporal_at exists inside the nest, the specified date was not prioritized, so the date of the inner bitemporal_at is now prioritized. #121](https://github.com/kufu/activerecord-bitemporal/pull/121)
234
313
  - [Drop support Rails 5.2 #122](https://github.com/kufu/activerecord-bitemporal/pull/122)
@@ -283,7 +362,7 @@
283
362
 
284
363
  ## 3.0.0
285
364
 
286
- ### Breaking Changed
365
+ ### Breaking Changes
287
366
  - [Assign updated bitemporal times to the receiver after update/destroy](https://github.com/kufu/activerecord-bitemporal/pull/118)
288
367
 
289
368
  ### Added
@@ -298,7 +377,7 @@
298
377
 
299
378
  ## 2.3.0
300
379
 
301
- ### Breaking Changed
380
+ ### Breaking Changes
302
381
 
303
382
  ### Added
304
383
  - [Add `InstanceMethods#swapped_id_previously_was`](https://github.com/kufu/activerecord-bitemporal/pull/114)
@@ -313,7 +392,7 @@
313
392
 
314
393
  ## 2.2.0
315
394
 
316
- ### Breaking Changed
395
+ ### Breaking Changes
317
396
 
318
397
  ### Added
319
398
  - [replace postgres docker image](https://github.com/kufu/activerecord-bitemporal/pull/103)
@@ -330,7 +409,7 @@
330
409
 
331
410
  ## 2.1.0
332
411
 
333
- ### Breaking Changed
412
+ ### Breaking Changes
334
413
 
335
414
  ### Added
336
415
  - [Update valid_to after #update](https://github.com/kufu/activerecord-bitemporal/pull/105)
@@ -347,7 +426,7 @@
347
426
 
348
427
  ## 2.0.0
349
428
 
350
- ### Breaking Changed
429
+ ### Breaking Changes
351
430
  - [[Proposal] Changed valid_in to exclude valid_from = to and valid_to = from. by osyo-manga · Pull Request #95](https://github.com/kufu/activerecord-bitemporal/pull/95)
352
431
 
353
432
  ### Added
data/README.md CHANGED
@@ -6,6 +6,12 @@ ActiveRecord::Bitemporal
6
6
  [![gem-download](https://img.shields.io/gem/dt/activerecord-bitemporal.svg)](https://rubygems.org/gems/activerecord-bitemporal)
7
7
  [![CircleCI](https://circleci.com/gh/kufu/activerecord-bitemporal.svg?style=svg)](https://circleci.com/gh/kufu/activerecord-bitemporal)
8
8
 
9
+ ## Requirements
10
+
11
+ - Ruby 3.1+
12
+ - Rails 7.1, 7.2, 8.0, or 8.1
13
+ - PostgreSQL
14
+
9
15
  ## Installation
10
16
 
11
17
  Add this line to your application's Gemfile:
@@ -112,15 +112,36 @@ module ActiveRecord
112
112
  end
113
113
 
114
114
  module Relation
115
- module Finder
116
- def find(*ids)
117
- return super if block_given?
118
- all.spawn.yield_self { |obj|
119
- def obj.primary_key
120
- "bitemporal_id"
115
+ module BitemporalIdAsPrimaryKey # :nodoc:
116
+ private
117
+
118
+ # Generate a method that temporarily changes the primary key to
119
+ # bitemporal_id for localizing the effect of the change to only the
120
+ # method specified by `name`.
121
+ #
122
+ # DO NOT use this method outside of this module.
123
+ def use_bitemporal_id_as_primary_key(name) # :nodoc:
124
+ module_eval <<~RUBY, __FILE__, __LINE__ + 1
125
+ def #{name}(...)
126
+ all.spawn.yield_self { |relation|
127
+ def relation.primary_key
128
+ bitemporal_id_key
129
+ end
130
+ relation.method(:#{name}).super_method.call(...)
131
+ }
121
132
  end
122
- obj.method(:find).super_method.call(*ids)
123
- }
133
+ RUBY
134
+ end
135
+ end
136
+ extend BitemporalIdAsPrimaryKey
137
+
138
+ module Finder
139
+ extend BitemporalIdAsPrimaryKey
140
+
141
+ use_bitemporal_id_as_primary_key :find
142
+
143
+ if ActiveRecord.version >= Gem::Version.new("8.0.0")
144
+ use_bitemporal_id_as_primary_key :exists?
124
145
  end
125
146
 
126
147
  def find_at_time!(datetime, *ids)
@@ -136,6 +157,23 @@ module ActiveRecord
136
157
  end
137
158
  include Finder
138
159
 
160
+ if ActiveRecord.version >= Gem::Version.new("8.0.0")
161
+ use_bitemporal_id_as_primary_key :ids
162
+
163
+ # Ensure that AR::Batches
164
+ # (https://github.com/rails/rails/blob/v8.0.5/activerecord/lib/active_record/relation/batches.rb)
165
+ # works with `bitemporal_id` as the primary key in Rails 8+.
166
+ use_bitemporal_id_as_primary_key :find_each
167
+ use_bitemporal_id_as_primary_key :find_in_batches
168
+ use_bitemporal_id_as_primary_key :in_batches
169
+
170
+ # Ensure that `#excluding` and `#without`
171
+ # (https://github.com/rails/rails/blob/v8.0.5/activerecord/lib/active_record/relation/query_methods.rb#L1548-L1591)
172
+ # work with `bitemporal_id` as the primary key in Rails 8+.
173
+ use_bitemporal_id_as_primary_key :excluding
174
+ use_bitemporal_id_as_primary_key :without
175
+ end
176
+
139
177
  def build_arel(*)
140
178
  ActiveRecord::Bitemporal.with_bitemporal_option(**bitemporal_option) {
141
179
  super
@@ -168,8 +206,12 @@ module ActiveRecord
168
206
  end
169
207
  end
170
208
 
171
- def primary_key
172
- bitemporal_id_key
209
+ # Use original primary_key for Active Record 8.0+ as much as possible
210
+ # to avoid issues with patching primary_key of AR::Relation globally.
211
+ if ActiveRecord.version < Gem::Version.new("8.0.0")
212
+ def primary_key
213
+ bitemporal_id_key
214
+ end
173
215
  end
174
216
  end
175
217
 
@@ -385,16 +427,14 @@ module ActiveRecord
385
427
  false
386
428
  end
387
429
 
388
- if Gem::Version.new("7.1.0") <= ActiveRecord.version
389
- # MEMO: Since Rails 7.1 #_find_record refers to a record with find_by!(@primary_key => id)
390
- # But if @primary_key is "id", it can't refer to the intended record, so we hack it to refer to the record based on self.class.bitemporal_id_key
391
- # see: https://github.com/rails/rails/blob/v7.1.0/activerecord/lib/active_record/persistence.rb#L1152-#L1171
392
- def _find_record(*)
393
- tmp_primary_key, @primary_key = @primary_key, self.class.bitemporal_id_key
394
- super
395
- ensure
396
- @primary_key = tmp_primary_key
397
- end
430
+ # MEMO: Since Rails 7.1 #_find_record refers to a record with find_by!(@primary_key => id)
431
+ # But if @primary_key is "id", it can't refer to the intended record, so we hack it to refer to the record based on self.class.bitemporal_id_key
432
+ # see: https://github.com/rails/rails/blob/v7.1.0/activerecord/lib/active_record/persistence.rb#L1152-#L1171
433
+ def _find_record(*)
434
+ tmp_primary_key, @primary_key = @primary_key, self.class.bitemporal_id_key
435
+ super
436
+ ensure
437
+ @primary_key = tmp_primary_key
398
438
  end
399
439
 
400
440
  module ::ActiveRecord::Persistence
@@ -128,6 +128,15 @@ module ActiveRecord::Bitemporal::Bitemporalize
128
128
  attribute :transaction_from, default: ActiveRecord::Bitemporal::DEFAULT_TRANSACTION_FROM
129
129
  attribute :transaction_to, default: ActiveRecord::Bitemporal::DEFAULT_TRANSACTION_TO
130
130
 
131
+ # Rails 8 support: ensure finder methods (.first, .last, etc.) use bitemporal_id ordering.
132
+ # Rails 8.0 changed _order_columns to use model.primary_key instead of Relation's primary_key.
133
+ # The nil-terminated format (Rails 8.1 feature, PR #54679) prevents automatic primary_key
134
+ # appending to the ORDER BY clause.
135
+ # See: https://github.com/rails/rails/pull/54679
136
+ if ActiveRecord.gem_version >= Gem::Version.new("8.0.0")
137
+ self.implicit_order_column ||= [bitemporal_id_key, nil]
138
+ end
139
+
131
140
  # Callback hook to `validates :xxx, uniqueness: true`
132
141
  const_set(:UniquenessValidator, Class.new(ActiveRecord::Validations::UniquenessValidator) {
133
142
  prepend ActiveRecord::Bitemporal::Uniqueness
@@ -160,7 +160,13 @@ module ActiveRecord::Bitemporal
160
160
  # @see https://github.com/rails/rails/blob/v7.1.3.4/activerecord/lib/active_record/relation/delegation.rb#L117
161
161
  delegate :bitemporal_value, :bitemporal_value=, :valid_datetime, :valid_date,
162
162
  :transaction_datetime, :bitemporal_option, :bitemporal_option_merge!,
163
- :build_arel, :primary_key, to: :scope
163
+ :build_arel, to: :scope
164
+
165
+ if ActiveRecord.version < Gem::Version.new("8.0.0")
166
+ delegate :primary_key, to: :scope
167
+ else
168
+ delegate :ids, :exists?, to: :scope
169
+ end
164
170
  end
165
171
 
166
172
  module Scope
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ActiveRecord
4
4
  module Bitemporal
5
- VERSION = "6.1.0"
5
+ VERSION = "7.0.1"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-bitemporal
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.1.0
4
+ version: 7.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - SmartHR
@@ -15,140 +15,28 @@ dependencies:
15
15
  requirements:
16
16
  - - ">="
17
17
  - !ruby/object:Gem::Version
18
- version: '7.0'
18
+ version: '7.1'
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: '7.0'
25
+ version: '7.1'
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: activesupport
28
28
  requirement: !ruby/object:Gem::Requirement
29
29
  requirements:
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
- version: '7.0'
32
+ version: '7.1'
33
33
  type: :runtime
34
34
  prerelease: false
35
35
  version_requirements: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - ">="
38
38
  - !ruby/object:Gem::Version
39
- version: '7.0'
40
- - !ruby/object:Gem::Dependency
41
- name: bundler
42
- requirement: !ruby/object:Gem::Requirement
43
- requirements:
44
- - - ">="
45
- - !ruby/object:Gem::Version
46
- version: '0'
47
- type: :development
48
- prerelease: false
49
- version_requirements: !ruby/object:Gem::Requirement
50
- requirements:
51
- - - ">="
52
- - !ruby/object:Gem::Version
53
- version: '0'
54
- - !ruby/object:Gem::Dependency
55
- name: globalid
56
- requirement: !ruby/object:Gem::Requirement
57
- requirements:
58
- - - ">="
59
- - !ruby/object:Gem::Version
60
- version: '0'
61
- type: :development
62
- prerelease: false
63
- version_requirements: !ruby/object:Gem::Requirement
64
- requirements:
65
- - - ">="
66
- - !ruby/object:Gem::Version
67
- version: '0'
68
- - !ruby/object:Gem::Dependency
69
- name: rake
70
- requirement: !ruby/object:Gem::Requirement
71
- requirements:
72
- - - "~>"
73
- - !ruby/object:Gem::Version
74
- version: '13.0'
75
- type: :development
76
- prerelease: false
77
- version_requirements: !ruby/object:Gem::Requirement
78
- requirements:
79
- - - "~>"
80
- - !ruby/object:Gem::Version
81
- version: '13.0'
82
- - !ruby/object:Gem::Dependency
83
- name: rspec
84
- requirement: !ruby/object:Gem::Requirement
85
- requirements:
86
- - - "~>"
87
- - !ruby/object:Gem::Version
88
- version: '3.0'
89
- type: :development
90
- prerelease: false
91
- version_requirements: !ruby/object:Gem::Requirement
92
- requirements:
93
- - - "~>"
94
- - !ruby/object:Gem::Version
95
- version: '3.0'
96
- - !ruby/object:Gem::Dependency
97
- name: pg
98
- requirement: !ruby/object:Gem::Requirement
99
- requirements:
100
- - - ">="
101
- - !ruby/object:Gem::Version
102
- version: '0'
103
- type: :development
104
- prerelease: false
105
- version_requirements: !ruby/object:Gem::Requirement
106
- requirements:
107
- - - ">="
108
- - !ruby/object:Gem::Version
109
- version: '0'
110
- - !ruby/object:Gem::Dependency
111
- name: pry
112
- requirement: !ruby/object:Gem::Requirement
113
- requirements:
114
- - - ">="
115
- - !ruby/object:Gem::Version
116
- version: '0'
117
- type: :development
118
- prerelease: false
119
- version_requirements: !ruby/object:Gem::Requirement
120
- requirements:
121
- - - ">="
122
- - !ruby/object:Gem::Version
123
- version: '0'
124
- - !ruby/object:Gem::Dependency
125
- name: pry-byebug
126
- requirement: !ruby/object:Gem::Requirement
127
- requirements:
128
- - - ">="
129
- - !ruby/object:Gem::Version
130
- version: '0'
131
- type: :development
132
- prerelease: false
133
- version_requirements: !ruby/object:Gem::Requirement
134
- requirements:
135
- - - ">="
136
- - !ruby/object:Gem::Version
137
- version: '0'
138
- - !ruby/object:Gem::Dependency
139
- name: timecop
140
- requirement: !ruby/object:Gem::Requirement
141
- requirements:
142
- - - ">="
143
- - !ruby/object:Gem::Version
144
- version: '0'
145
- type: :development
146
- prerelease: false
147
- version_requirements: !ruby/object:Gem::Requirement
148
- requirements:
149
- - - ">="
150
- - !ruby/object:Gem::Version
151
- version: '0'
39
+ version: '7.1'
152
40
  description: Enable ActiveRecord models to be handled as BiTemporal Data Model.
153
41
  email:
154
42
  - oss@smarthr.co.jp
@@ -188,7 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
188
76
  - !ruby/object:Gem::Version
189
77
  version: '0'
190
78
  requirements: []
191
- rubygems_version: 3.6.9
79
+ rubygems_version: 4.0.10
192
80
  specification_version: 4
193
81
  summary: BiTemporal Data Model for ActiveRecord
194
82
  test_files: []