activerecord-bitemporal 4.1.0 → 4.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/CHANGELOG.md +22 -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/version.rb +1 -1
- data/lib/activerecord-bitemporal.rb +1 -0
- metadata +3 -2
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,27 @@
|
|
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
|
+
|
3
25
|
## 4.1.0
|
4
26
|
|
5
27
|
### Added
|
@@ -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
|
# 有効なレコードがない場合
|
@@ -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
|