activerecord-bitemporal 4.0.0 → 4.2.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 +4 -4
- data/.gitignore +2 -0
- data/CHANGELOG.md +36 -0
- data/lib/activerecord-bitemporal/bitemporal.rb +24 -18
- data/lib/activerecord-bitemporal/callbacks.rb +1 -1
- data/lib/activerecord-bitemporal/errors.rb +7 -0
- data/lib/activerecord-bitemporal/patches.rb +12 -0
- data/lib/activerecord-bitemporal/version.rb +1 -1
- data/lib/activerecord-bitemporal/visualizer.rb +11 -2
- data/lib/activerecord-bitemporal.rb +1 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 97a21996b6ff931bf324653432cd481eac86731ee3de16445c98627987683639
|
4
|
+
data.tar.gz: 34178dcfc6e5fe4cbd1f01554499f075d1be90208f05cc2d39a0039941d03607
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: da5f747f97ec3c16f14b65d592482b23cc8a0d8ba2d1c691dc98df8b5f84d5dfd8c92e8be67362f8b6be38b0bd584c2bfdd97f5169f9e4d91347a7286ad87770
|
7
|
+
data.tar.gz: 2a1b5d95ac36a751943a87adcb9231b81633f61139a6ca38ca3d34859a7e9a2f647ce204b549eda50efca9cc48245d7aff7c21499397d4ef673d1f4c02de84a4
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,41 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 4.2.0
|
4
|
+
|
5
|
+
### Added
|
6
|
+
|
7
|
+
- [Allow passing `operated_at` to destroy #138](https://github.com/kufu/activerecord-bitemporal/pull/138)
|
8
|
+
|
9
|
+
### Changed
|
10
|
+
|
11
|
+
- [Change not to create history when destroying with `force_update` #135](https://github.com/kufu/activerecord-bitemporal/pull/135)
|
12
|
+
- [Raise `ValidDatetimeRangeError` instead of `RecordInvalid` in `_update_row` #136](https://github.com/kufu/activerecord-bitemporal/pull/136)
|
13
|
+
|
14
|
+
### Deprecated
|
15
|
+
|
16
|
+
### Removed
|
17
|
+
|
18
|
+
### Fixed
|
19
|
+
|
20
|
+
### Chores
|
21
|
+
|
22
|
+
- [Fix for RSpec deprecated warning #132](https://github.com/kufu/activerecord-bitemporal/pull/132)
|
23
|
+
- [Add some files to .gitignore #134](https://github.com/kufu/activerecord-bitemporal/pull/134)
|
24
|
+
|
25
|
+
## 4.1.0
|
26
|
+
|
27
|
+
### Added
|
28
|
+
- [add label option #127](https://github.com/kufu/activerecord-bitemporal/pull/127)
|
29
|
+
|
30
|
+
### Changed
|
31
|
+
- [Support for inverse_of of Rails 6.1 or higher #130](https://github.com/kufu/activerecord-bitemporal/pull/130)
|
32
|
+
|
33
|
+
### Deprecated
|
34
|
+
|
35
|
+
### Removed
|
36
|
+
|
37
|
+
### Fixed
|
38
|
+
|
3
39
|
## 4.0.0
|
4
40
|
|
5
41
|
### Breaking Changed
|
@@ -334,30 +334,32 @@ module ActiveRecord
|
|
334
334
|
end || false
|
335
335
|
end
|
336
336
|
|
337
|
-
def destroy(force_delete: false)
|
337
|
+
def destroy(force_delete: false, operated_at: Time.current)
|
338
338
|
return super() if force_delete
|
339
339
|
|
340
|
-
|
341
|
-
target_datetime = valid_datetime || current_time
|
340
|
+
target_datetime = valid_datetime || operated_at
|
342
341
|
|
343
342
|
duplicated_instance = self.class.find_at_time(target_datetime, self.id).dup
|
344
343
|
|
345
344
|
ActiveRecord::Base.transaction(requires_new: true, joinable: false) do
|
346
345
|
@destroyed = false
|
347
346
|
_run_destroy_callbacks {
|
348
|
-
@destroyed = update_transaction_to(
|
349
|
-
|
350
|
-
#
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
@
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
347
|
+
@destroyed = update_transaction_to(operated_at)
|
348
|
+
|
349
|
+
# force_update の場合は削除時の状態の履歴を残さない
|
350
|
+
unless force_update?
|
351
|
+
# 削除時の状態を履歴レコードとして保存する
|
352
|
+
duplicated_instance.valid_to = target_datetime
|
353
|
+
duplicated_instance.transaction_from = operated_at
|
354
|
+
duplicated_instance.save_without_bitemporal_callbacks!(validate: false)
|
355
|
+
if @destroyed
|
356
|
+
@_swapped_id_previously_was = swapped_id
|
357
|
+
@_swapped_id = duplicated_instance.swapped_id
|
358
|
+
self.valid_from = duplicated_instance.valid_from
|
359
|
+
self.valid_to = duplicated_instance.valid_to
|
360
|
+
self.transaction_from = duplicated_instance.transaction_from
|
361
|
+
self.transaction_to = duplicated_instance.transaction_to
|
362
|
+
end
|
361
363
|
end
|
362
364
|
}
|
363
365
|
raise ActiveRecord::RecordInvalid unless @destroyed
|
@@ -499,13 +501,17 @@ module ActiveRecord
|
|
499
501
|
|
500
502
|
# 以前の履歴データは valid_to を詰めて保存
|
501
503
|
before_instance.valid_to = target_datetime
|
502
|
-
|
504
|
+
if before_instance.valid_from_cannot_be_greater_equal_than_valid_to
|
505
|
+
raise ValidDatetimeRangeError.new("valid_from #{before_instance.valid_from} can't be greater equal than valid_to #{before_instance.valid_to}")
|
506
|
+
end
|
503
507
|
before_instance.transaction_from = current_time
|
504
508
|
|
505
509
|
# 以降の履歴データは valid_from と valid_to を調整して保存する
|
506
510
|
after_instance.valid_from = target_datetime
|
507
511
|
after_instance.valid_to = current_valid_record.valid_to
|
508
|
-
|
512
|
+
if after_instance.valid_from_cannot_be_greater_equal_than_valid_to
|
513
|
+
raise ValidDatetimeRangeError.new("valid_from #{after_instance.valid_from} can't be greater equal than valid_to #{after_instance.valid_to}")
|
514
|
+
end
|
509
515
|
after_instance.transaction_from = current_time
|
510
516
|
|
511
517
|
# 有効なレコードがない場合
|
@@ -79,6 +79,18 @@ module ActiveRecord::Bitemporal
|
|
79
79
|
def bi_temporal_model?
|
80
80
|
owner.class.bi_temporal_model? && klass&.bi_temporal_model?
|
81
81
|
end
|
82
|
+
|
83
|
+
def matches_foreign_key?(record)
|
84
|
+
return super unless owner.class.bi_temporal_model?
|
85
|
+
|
86
|
+
begin
|
87
|
+
original_owner_id = owner.id
|
88
|
+
owner.id = owner.read_attribute(owner.class.bitemporal_id_key)
|
89
|
+
super
|
90
|
+
ensure
|
91
|
+
owner.id = original_owner_id
|
92
|
+
end
|
93
|
+
end
|
82
94
|
end
|
83
95
|
|
84
96
|
module ThroughAssociation
|
@@ -91,8 +91,17 @@ module ActiveRecord::Bitemporal
|
|
91
91
|
end
|
92
92
|
end
|
93
93
|
end
|
94
|
-
|
95
|
-
|
94
|
+
|
95
|
+
transaction_label = 'transaction_datetime'
|
96
|
+
right_margin = time_length + 1 - transaction_label.size
|
97
|
+
|
98
|
+
label = if right_margin >= 0
|
99
|
+
"#{transaction_label + ' ' * right_margin}| valid_datetime"
|
100
|
+
else
|
101
|
+
"#{transaction_label[0...right_margin]}| valid_datetime"
|
102
|
+
end
|
103
|
+
|
104
|
+
"#{label}\n#{headers.to_s}\n#{body.to_s}"
|
96
105
|
end
|
97
106
|
|
98
107
|
# Compute a dictionary of where each time should be plotted.
|
@@ -4,6 +4,7 @@ require "active_record"
|
|
4
4
|
require "active_support/core_ext/time/calculations"
|
5
5
|
require "activerecord-bitemporal/bitemporal"
|
6
6
|
require "activerecord-bitemporal/scope"
|
7
|
+
require "activerecord-bitemporal/errors"
|
7
8
|
require "activerecord-bitemporal/patches"
|
8
9
|
require "activerecord-bitemporal/version"
|
9
10
|
require "activerecord-bitemporal/visualizer"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-bitemporal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- SmartHR
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-07-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -166,6 +166,7 @@ files:
|
|
166
166
|
- lib/activerecord-bitemporal.rb
|
167
167
|
- lib/activerecord-bitemporal/bitemporal.rb
|
168
168
|
- lib/activerecord-bitemporal/callbacks.rb
|
169
|
+
- lib/activerecord-bitemporal/errors.rb
|
169
170
|
- lib/activerecord-bitemporal/patches.rb
|
170
171
|
- lib/activerecord-bitemporal/scope.rb
|
171
172
|
- lib/activerecord-bitemporal/version.rb
|
@@ -189,7 +190,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
189
190
|
- !ruby/object:Gem::Version
|
190
191
|
version: '0'
|
191
192
|
requirements: []
|
192
|
-
rubygems_version: 3.
|
193
|
+
rubygems_version: 3.3.26
|
193
194
|
signing_key:
|
194
195
|
specification_version: 4
|
195
196
|
summary: BiTemporal Data Model for ActiveRecord
|