activerecord-bitemporal 6.1.0 → 7.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: 7676d93276c1c24acbb001b135c344b94d3b0b8084d2ef17423c238b5e06bfaf
4
- data.tar.gz: f07cc0d7a716c99d3d85f352588309351b3ed408e6ddec5ad153096dd2310786
3
+ metadata.gz: 9644dc51d17a2d86e13daa5982fab733cdab79fd1fda78fbe408412a90ccd337
4
+ data.tar.gz: f535c500ce4f4f738e6c09102d89a449476407956460c1e5b80d211adb4b66c9
5
5
  SHA512:
6
- metadata.gz: 95b6ea9e934a5818d3fc3e0409faef14bde66aeafbd0a0a168a1649e3b88ed6a11a0e8174094f7527ae4ba47076449db17a17597b83587a8986815af458b6c19
7
- data.tar.gz: ece5cc5e3a8846f6495b63b30eb35eb4648e95b712e582b72fa67dafd1cfe9af1384737a11cf272d06cf73ed9e9121a674a6e0ea90434edb77d1715603cf7ffe
6
+ metadata.gz: d0f7ac0703dd57cd8a837f24adc5c0598cbb5b083a20266c20bd35ae4014a28ee6488ed48e3b30119f01b78c40c063deb7bcbe0f8c61280ef6b7a6bc60d5b3eb
7
+ data.tar.gz: ad4faf9f2c337bcdcefd8f18a1dadaa191c327a82a5e7391d7b15f06b15bfeff631115466da7fb690062b35cf5174bf8ad991dd3041800abf6063c840bd241ac
data/CHANGELOG.md CHANGED
@@ -1,8 +1,63 @@
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.0
20
+
21
+ ### Breaking Changes
22
+
23
+ - [Drop support Rails 7.0 #230](https://github.com/kufu/activerecord-bitemporal/pull/230)
24
+
25
+ ### Added
26
+
27
+ - [Add Ruby 4.0 in CI #236](https://github.com/kufu/activerecord-bitemporal/pull/236)
28
+
29
+ ### Changed
30
+
31
+ ### Deprecated
32
+
33
+ ### Removed
34
+
35
+ ### Fixed
36
+
37
+ - [Localize patch for AR::Relation#primary_key in Rails 8.0+ #243](https://github.com/kufu/activerecord-bitemporal/pull/243)
38
+ - 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`:
39
+ - `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)
40
+ - [Fix finder methods ordering on Rails 8.0+ #237](https://github.com/kufu/activerecord-bitemporal/pull/237)
41
+
42
+ ### Chores
43
+
44
+ - [Manage development dependencies in gemfiles #240](https://github.com/kufu/activerecord-bitemporal/pull/240)
45
+ - [Randomize test execution order #239](https://github.com/kufu/activerecord-bitemporal/pull/239)
46
+ - [Update release GitHub Action #232](https://github.com/kufu/activerecord-bitemporal/pull/232)
47
+ - [Bump ruby/setup-ruby from 1.286.0 to 1.288.0 #244](https://github.com/kufu/activerecord-bitemporal/pull/244)
48
+ - [Bump actions/checkout from 6.0.1 to 6.0.2 #242](https://github.com/kufu/activerecord-bitemporal/pull/242)
49
+ - [Bump ruby/setup-ruby from 1.278.0 to 1.286.0 #241](https://github.com/kufu/activerecord-bitemporal/pull/241)
50
+ - [Bump ruby/setup-ruby from 1.268.0 to 1.278.0 #234](https://github.com/kufu/activerecord-bitemporal/pull/234)
51
+ - [Update reviewers #231](https://github.com/kufu/activerecord-bitemporal/pull/231)
52
+ - [Bump actions/checkout from 6.0.0 to 6.0.1 #229](https://github.com/kufu/activerecord-bitemporal/pull/229)
53
+ - [Bump ruby/setup-ruby from 1.267.0 to 1.268.0 #228](https://github.com/kufu/activerecord-bitemporal/pull/228)
54
+ - [Bump actions/checkout from 5.0.0 to 6.0.0 #227](https://github.com/kufu/activerecord-bitemporal/pull/227)
55
+ - [Bump codespell-project/actions-codespell from 2.1 to 2.2 #226](https://github.com/kufu/activerecord-bitemporal/pull/226)
56
+ - [Bump ruby/setup-ruby from 1.265.0 to 1.267.0 #225](https://github.com/kufu/activerecord-bitemporal/pull/225)
57
+
3
58
  ## 6.1.0
4
59
 
5
- ### Breaking Changed
60
+ ### Breaking Changes
6
61
 
7
62
  ### Added
8
63
 
@@ -39,7 +94,7 @@
39
94
 
40
95
  ## 6.0.0
41
96
 
42
- ### Breaking Changed
97
+ ### Breaking Changes
43
98
 
44
99
  - [Add Ruby 3.4 and remove Ruby 3.0 in CI #185](https://github.com/kufu/activerecord-bitemporal/pull/185)
45
100
  - [Drop support Rails 6.1 #192](https://github.com/kufu/activerecord-bitemporal/pull/192)
@@ -147,7 +202,7 @@
147
202
 
148
203
  ## 5.0.0
149
204
 
150
- ### Breaking Changed
205
+ ### Breaking Changes
151
206
 
152
207
  - [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
208
 
@@ -228,7 +283,7 @@
228
283
 
229
284
  ## 4.0.0
230
285
 
231
- ### Breaking Changed
286
+ ### Breaking Changes
232
287
 
233
288
  - [[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
289
  - [Drop support Rails 5.2 #122](https://github.com/kufu/activerecord-bitemporal/pull/122)
@@ -283,7 +338,7 @@
283
338
 
284
339
  ## 3.0.0
285
340
 
286
- ### Breaking Changed
341
+ ### Breaking Changes
287
342
  - [Assign updated bitemporal times to the receiver after update/destroy](https://github.com/kufu/activerecord-bitemporal/pull/118)
288
343
 
289
344
  ### Added
@@ -298,7 +353,7 @@
298
353
 
299
354
  ## 2.3.0
300
355
 
301
- ### Breaking Changed
356
+ ### Breaking Changes
302
357
 
303
358
  ### Added
304
359
  - [Add `InstanceMethods#swapped_id_previously_was`](https://github.com/kufu/activerecord-bitemporal/pull/114)
@@ -313,7 +368,7 @@
313
368
 
314
369
  ## 2.2.0
315
370
 
316
- ### Breaking Changed
371
+ ### Breaking Changes
317
372
 
318
373
  ### Added
319
374
  - [replace postgres docker image](https://github.com/kufu/activerecord-bitemporal/pull/103)
@@ -330,7 +385,7 @@
330
385
 
331
386
  ## 2.1.0
332
387
 
333
- ### Breaking Changed
388
+ ### Breaking Changes
334
389
 
335
390
  ### Added
336
391
  - [Update valid_to after #update](https://github.com/kufu/activerecord-bitemporal/pull/105)
@@ -347,7 +402,7 @@
347
402
 
348
403
  ## 2.0.0
349
404
 
350
- ### Breaking Changed
405
+ ### Breaking Changes
351
406
  - [[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
407
 
353
408
  ### 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,10 @@ 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
+ end
163
+
139
164
  def build_arel(*)
140
165
  ActiveRecord::Bitemporal.with_bitemporal_option(**bitemporal_option) {
141
166
  super
@@ -168,8 +193,12 @@ module ActiveRecord
168
193
  end
169
194
  end
170
195
 
171
- def primary_key
172
- bitemporal_id_key
196
+ # Use original primary_key for Active Record 8.0+ as much as possible
197
+ # to avoid issues with patching primary_key of AR::Relation globally.
198
+ if ActiveRecord.version < Gem::Version.new("8.0.0")
199
+ def primary_key
200
+ bitemporal_id_key
201
+ end
173
202
  end
174
203
  end
175
204
 
@@ -385,16 +414,14 @@ module ActiveRecord
385
414
  false
386
415
  end
387
416
 
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
417
+ # MEMO: Since Rails 7.1 #_find_record refers to a record with find_by!(@primary_key => id)
418
+ # 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
419
+ # see: https://github.com/rails/rails/blob/v7.1.0/activerecord/lib/active_record/persistence.rb#L1152-#L1171
420
+ def _find_record(*)
421
+ tmp_primary_key, @primary_key = @primary_key, self.class.bitemporal_id_key
422
+ super
423
+ ensure
424
+ @primary_key = tmp_primary_key
398
425
  end
399
426
 
400
427
  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.0"
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.0
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.7
192
80
  specification_version: 4
193
81
  summary: BiTemporal Data Model for ActiveRecord
194
82
  test_files: []