temporal_tables 1.1.0 → 2.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 +4 -4
- data/lib/temporal_tables/arel_table.rb +1 -1
- data/lib/temporal_tables/connection_adapters/mysql_adapter.rb +2 -2
- data/lib/temporal_tables/connection_adapters/postgresql_adapter.rb +2 -2
- data/lib/temporal_tables/constants.rb +5 -0
- data/lib/temporal_tables/temporal_adapter.rb +1 -1
- data/lib/temporal_tables/temporal_adapter_six_oh.rb +1 -1
- data/lib/temporal_tables/temporal_class.rb +3 -1
- data/lib/temporal_tables/version.rb +1 -1
- data/lib/temporal_tables.rb +1 -0
- data/spec/basic_history_spec.rb +8 -2
- 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: 457aecc9f2b96e0a7ef98f6e7e2d4c30fc0aa091ddeb3abc9a3c684cae67768c
|
4
|
+
data.tar.gz: 1bf1f9bd6e98b063b73c3bdafb9f5d31bba6e75a2e605838c466915c85231317
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9b9baeefc81aadfe5f23db7fc5790321cf2550812a6818a9b3d2d3f96af4f12efb8672bea34e9b7981f6e577c9c43574378d72894684a866c762aaf94d17d5f2
|
7
|
+
data.tar.gz: 9ae4da3db11583308195eca7c1965c0a91242ab61711794bb8b0f3264e25df39b2453a6dcafd3ae7dad119f7f5d31d3a5d681b18bd711422c12d0965e8b184fb
|
@@ -34,7 +34,7 @@ module TemporalTables
|
|
34
34
|
|
35
35
|
update #{temporal_name(table_name)} set eff_to = @current_time
|
36
36
|
where #{primary_key} = new.#{primary_key}
|
37
|
-
and eff_to = '
|
37
|
+
and eff_to = '#{TemporalTables::END_OF_TIME}';
|
38
38
|
|
39
39
|
insert into #{temporal_name(table_name)} (#{column_names.join(', ')}, eff_from)
|
40
40
|
values (#{column_names.collect { |c| "new.#{c}" }.join(', ')}, @current_time);
|
@@ -51,7 +51,7 @@ module TemporalTables
|
|
51
51
|
|
52
52
|
update #{temporal_name(table_name)} set eff_to = @current_time
|
53
53
|
where #{primary_key} = old.#{primary_key}
|
54
|
-
and eff_to = '
|
54
|
+
and eff_to = '#{TemporalTables::END_OF_TIME}';
|
55
55
|
|
56
56
|
end
|
57
57
|
}
|
@@ -40,7 +40,7 @@ module TemporalTables
|
|
40
40
|
|
41
41
|
update #{temporal_name(table_name)} set eff_to = cur_time
|
42
42
|
where #{primary_key} = new.#{primary_key}
|
43
|
-
and eff_to = '
|
43
|
+
and eff_to = '#{TemporalTables::END_OF_TIME}';
|
44
44
|
|
45
45
|
insert into #{temporal_name(table_name)} (#{column_list(column_names)}, eff_from)
|
46
46
|
values (#{column_names.collect { |c| "new.#{c}" }.join(', ')}, cur_time);
|
@@ -63,7 +63,7 @@ module TemporalTables
|
|
63
63
|
|
64
64
|
update #{temporal_name(table_name)} set eff_to = cur_time
|
65
65
|
where #{primary_key} = old.#{primary_key}
|
66
|
-
and eff_to = '
|
66
|
+
and eff_to = '#{TemporalTables::END_OF_TIME}';
|
67
67
|
|
68
68
|
return null;
|
69
69
|
end
|
@@ -35,7 +35,7 @@ module TemporalTables
|
|
35
35
|
**options.merge(id: false, primary_key: 'history_id', temporal_bypass: true)
|
36
36
|
) do |t|
|
37
37
|
t.datetime :eff_from, null: false, limit: 6
|
38
|
-
t.datetime :eff_to, null: false, limit: 6, default:
|
38
|
+
t.datetime :eff_to, null: false, limit: 6, default: TemporalTables::END_OF_TIME
|
39
39
|
|
40
40
|
columns(table_name).each do |c|
|
41
41
|
column_options = { limit: c.limit }
|
@@ -37,7 +37,7 @@ module TemporalTables
|
|
37
37
|
**options.merge(id: false, primary_key: 'history_id', temporal_bypass: true)
|
38
38
|
) do |t|
|
39
39
|
t.datetime :eff_from, null: false, limit: 6
|
40
|
-
t.datetime :eff_to, null: false, limit: 6, default:
|
40
|
+
t.datetime :eff_to, null: false, limit: 6, default: TemporalTables::END_OF_TIME
|
41
41
|
|
42
42
|
columns(table_name).each do |c|
|
43
43
|
column_type = c.type == :enum ? c.sql_type_metadata.sql_type : c.type
|
@@ -74,8 +74,10 @@ module TemporalTables
|
|
74
74
|
|
75
75
|
delegate :descends_from_active_record?, to: :superclass
|
76
76
|
|
77
|
+
# An object at a given time should fall within the range, excluding the effective end date.
|
78
|
+
# However, when using '9999-12-31', this is effectively infinity and should not be excluded.
|
77
79
|
def build_temporal_constraint(at_value)
|
78
|
-
arel_table[:eff_to].
|
80
|
+
(arel_table[:eff_to].gt(at_value).or(arel_table[:eff_to].eq(TemporalTables::END_OF_TIME))).and(
|
79
81
|
arel_table[:eff_from].lteq(at_value)
|
80
82
|
)
|
81
83
|
end
|
data/lib/temporal_tables.rb
CHANGED
@@ -12,6 +12,7 @@ require 'temporal_tables/association_extensions'
|
|
12
12
|
require 'temporal_tables/preloader_extensions'
|
13
13
|
require 'temporal_tables/reflection_extensions'
|
14
14
|
require 'temporal_tables/arel_table'
|
15
|
+
require 'temporal_tables/constants'
|
15
16
|
require 'temporal_tables/version'
|
16
17
|
|
17
18
|
module TemporalTables
|
data/spec/basic_history_spec.rb
CHANGED
@@ -90,10 +90,10 @@ describe Person do
|
|
90
90
|
where = sql[4]
|
91
91
|
|
92
92
|
expect(from.scan(/.warts_h.\..eff_from./i).count).to eq(1)
|
93
|
-
expect(from.scan(/.warts_h.\..eff_to./i).count).to eq(
|
93
|
+
expect(from.scan(/.warts_h.\..eff_to./i).count).to eq(2)
|
94
94
|
|
95
95
|
expect(where.scan(/.people_h.\..eff_from./i).count).to eq(1)
|
96
|
-
expect(where.scan(/.people_h.\..eff_to./i).count).to eq(
|
96
|
+
expect(where.scan(/.people_h.\..eff_to./i).count).to eq(2)
|
97
97
|
expect(where.scan(/.warts_h.\..eff_from./i).count).to eq(0)
|
98
98
|
expect(where.scan(/.warts_h.\..eff_to./i).count).to eq(0)
|
99
99
|
end
|
@@ -195,6 +195,12 @@ describe Person do
|
|
195
195
|
expect(fido.orig_obj.name).to eq('Max')
|
196
196
|
end
|
197
197
|
|
198
|
+
it 'at the exact time of the name change, the dog should not be both Max and Fido' do
|
199
|
+
dog_at_moment_of_name_change = dog.history.at(dog.history.last.eff_from)
|
200
|
+
expect(dog_at_moment_of_name_change.count).to eq(1)
|
201
|
+
expect(dog_at_moment_of_name_change.first.name).to eq('Max')
|
202
|
+
end
|
203
|
+
|
198
204
|
context 'Max is rehomed' do
|
199
205
|
before do
|
200
206
|
dog.destroy!
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: temporal_tables
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brent Kroeker
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-11-
|
11
|
+
date: 2022-11-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -179,6 +179,7 @@ files:
|
|
179
179
|
- lib/temporal_tables/association_extensions.rb
|
180
180
|
- lib/temporal_tables/connection_adapters/mysql_adapter.rb
|
181
181
|
- lib/temporal_tables/connection_adapters/postgresql_adapter.rb
|
182
|
+
- lib/temporal_tables/constants.rb
|
182
183
|
- lib/temporal_tables/history_hook.rb
|
183
184
|
- lib/temporal_tables/preloader_extensions.rb
|
184
185
|
- lib/temporal_tables/reflection_extensions.rb
|