temporal_tables 0.7.1 → 0.8.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: 7a2a5e35b72b615ab7c9e690bcaab833583834b3fd440e762cab86ae545fc8fd
4
- data.tar.gz: 11429f65bbc062d283f85271811f2dbbe867d1b420906365490c51b783a53f54
3
+ metadata.gz: 99487832a04f3cf0a4d0936ed7054a084603a9cdc861d173af7321cf01a5f82c
4
+ data.tar.gz: 75344eb90c649477ff8df2fd49a7fdc6d47a49e8eb5d4b3fbde57334a5986726
5
5
  SHA512:
6
- metadata.gz: f764f397e1c647a3eeda69b133c230e03ce1df412d05ad2e3a3f5e851b2c86f524d3f692dc875ad0c03eeb433ca041390a91bf8b79065ebce0e9b7a98ad1c1ff
7
- data.tar.gz: cd93d55c4f1dd33b05f78a5a67fe30003c6dc16cfbb3f139c4ec7514544ab96846ed32edf128360c2077ce745c0c0238e3229c37a7bb4e5a795aed1770a644d8
6
+ metadata.gz: 0b7701e46c1188110f8cb6d4b8bedf311d6eea112a5304cfbddc7caef4e7b40c340a6a935b8dc111c531b9d4ad78fe98737d0db05562f4f067ab93c19a8ca8a6
7
+ data.tar.gz: c6403266a1982acc8e23ce6e529b5825cb5f01f0bb29602ec8d5faacf4f3ccc72d89f9bb734a2de7f08b6f386aa1c0c225b6b8f9b32d1671536717ae5cd7d71c
data/.travis.yml CHANGED
@@ -2,12 +2,10 @@ rvm:
2
2
  - 2.5.4
3
3
 
4
4
  gemfile:
5
- - gemfiles/Gemfile.5.0.pg
6
5
  - gemfiles/Gemfile.5.1.pg
7
6
  - gemfiles/Gemfile.5.2.pg
8
7
  - gemfiles/Gemfile.6.0.pg
9
8
 
10
- - gemfiles/Gemfile.5.0.mysql
11
9
  - gemfiles/Gemfile.5.1.mysql
12
10
  - gemfiles/Gemfile.5.2.mysql
13
11
  - gemfiles/Gemfile.6.0.mysql
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Easily recall what your data looked like at any point in the past! TemporalTables sets up and maintains history tables to track all temporal changes to to your data.
4
4
 
5
- Currently tested on Ruby 2.5.4, Rails 5.0 - 6.0, Postgres 11.3, MySQL 8.0.13
5
+ Currently tested on Ruby 2.5.4, Rails 5.1 - 6.1, Postgres 11.3, MySQL 8.0.13
6
6
 
7
7
  ## Installation
8
8
 
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- temporal_tables (0.7.0)
4
+ temporal_tables (0.8.0)
5
5
  rails (>= 5.0, < 6.1)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- temporal_tables (0.7.0)
4
+ temporal_tables (0.8.0)
5
5
  rails (>= 5.0, < 6.1)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- temporal_tables (0.7.0)
4
+ temporal_tables (0.8.0)
5
5
  rails (>= 5.0, < 6.1)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- temporal_tables (0.7.0)
4
+ temporal_tables (0.8.0)
5
5
  rails (>= 5.0, < 6.1)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- temporal_tables (0.7.0)
4
+ temporal_tables (0.8.0)
5
5
  rails (>= 5.0, < 6.1)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- temporal_tables (0.7.0)
4
+ temporal_tables (0.8.0)
5
5
  rails (>= 5.0, < 6.1)
6
6
 
7
7
  GEM
@@ -26,14 +26,16 @@ module TemporalTables
26
26
  end
27
27
 
28
28
  def add_temporal_table(table_name, options = {})
29
+ id = id_column(table_name)
30
+
29
31
  create_table temporal_name(table_name), options.merge(id: false, primary_key: "history_id", temporal_bypass: true) do |t|
30
- t.integer :id
31
- t.datetime :eff_from, :null => false, limit: 6
32
- t.datetime :eff_to, :null => false, limit: 6, :default => "9999-12-31"
32
+ t.column :id, id.type
33
+ t.datetime :eff_from, null: false, limit: 6
34
+ t.datetime :eff_to, null: false, limit: 6, default: "9999-12-31"
33
35
 
34
36
  for c in columns(table_name)
35
37
  next if c.name == "id"
36
- t.send c.type, c.name, :limit => c.limit
38
+ t.send c.type, c.name, limit: c.limit
37
39
  end
38
40
  end
39
41
 
@@ -184,5 +186,9 @@ module TemporalTables
184
186
  raise "Rails version not supported"
185
187
  end
186
188
  end
189
+
190
+ def id_column(table_name)
191
+ columns(table_name).detect { |c| c.name == "id" }
192
+ end
187
193
  end
188
194
  end
@@ -1,3 +1,3 @@
1
1
  module TemporalTables
2
- VERSION = "0.7.1"
2
+ VERSION = "0.8.0"
3
3
  end
@@ -139,4 +139,25 @@ describe Person do
139
139
  end
140
140
  end
141
141
  end
142
+
143
+ # The following only tests non-integer ids for postgres (see schema.rb)
144
+ describe "when spawning and aging a creature with a non-integer id" do
145
+ let!(:cat) { Cat.create name: "Mr. Mittens", color: "black" }
146
+
147
+ before do
148
+ cat.lives.create started_at: 3.years.ago
149
+ @init_time = Time.now
150
+ cat.update name: "Old Mr. Mittens"
151
+ cat.lives.first.update ended_at: Time.now, death_reason: "fell into cauldron"
152
+ cat.lives.create started_at: Time.now
153
+ end
154
+
155
+ it "shows one life at the beginning" do
156
+ expect(cat.history.at(@init_time).last.lives.size).to eq(1)
157
+ end
158
+
159
+ it "shows two lives at the end" do
160
+ expect(cat.history.last.lives.size).to eq(2)
161
+ end
162
+ end
142
163
  end
@@ -0,0 +1,3 @@
1
+ class Cat < ActiveRecord::Base
2
+ has_many :lives, class_name: "CatLife"
3
+ end
@@ -0,0 +1,3 @@
1
+ class CatLife < ActiveRecord::Base
2
+ belongs_to :cat
3
+ end
@@ -1,4 +1,10 @@
1
+ postgres = ActiveRecord::Base.connection.class.name == "ActiveRecord::ConnectionAdapters::PostgreSQLAdapter"
2
+
1
3
  ActiveRecord::Schema.define do
4
+ if postgres
5
+ enable_extension "pgcrypto"
6
+ end
7
+
2
8
  create_table :people, temporal: true, force: true do |t|
3
9
  t.belongs_to :coven
4
10
  t.string :name
@@ -19,4 +25,16 @@ ActiveRecord::Schema.define do
19
25
  t.string :type
20
26
  t.string :model
21
27
  end
28
+
29
+ create_table :cats, id: (postgres ? :uuid : :integer), temporal: true, force: true do |t|
30
+ t.string :name
31
+ t.string :color
32
+ end
33
+
34
+ create_table :cat_lives, id: (postgres ? :uuid : :integer), temporal: true do |t|
35
+ t.belongs_to :cat, type: (postgres ? :uuid : :integer)
36
+ t.timestamp :started_at
37
+ t.timestamp :ended_at
38
+ t.string :death_reason
39
+ end
22
40
  end
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: 0.7.1
4
+ version: 0.8.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: 2020-03-19 00:00:00.000000000 Z
11
+ date: 2020-03-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -90,10 +90,6 @@ files:
90
90
  - README.md
91
91
  - Rakefile
92
92
  - config.ru
93
- - gemfiles/Gemfile.5.0.mysql
94
- - gemfiles/Gemfile.5.0.mysql.lock
95
- - gemfiles/Gemfile.5.0.pg
96
- - gemfiles/Gemfile.5.0.pg.lock
97
93
  - gemfiles/Gemfile.5.1.mysql
98
94
  - gemfiles/Gemfile.5.1.mysql.lock
99
95
  - gemfiles/Gemfile.5.1.pg
@@ -125,6 +121,8 @@ files:
125
121
  - spec/basic_history_spec.rb
126
122
  - spec/extensions/combustion.rb
127
123
  - spec/internal/app/models/broom.rb
124
+ - spec/internal/app/models/cat.rb
125
+ - spec/internal/app/models/cat_life.rb
128
126
  - spec/internal/app/models/coven.rb
129
127
  - spec/internal/app/models/flying_machine.rb
130
128
  - spec/internal/app/models/person.rb
@@ -164,6 +162,8 @@ test_files:
164
162
  - spec/basic_history_spec.rb
165
163
  - spec/extensions/combustion.rb
166
164
  - spec/internal/app/models/broom.rb
165
+ - spec/internal/app/models/cat.rb
166
+ - spec/internal/app/models/cat_life.rb
167
167
  - spec/internal/app/models/coven.rb
168
168
  - spec/internal/app/models/flying_machine.rb
169
169
  - spec/internal/app/models/person.rb
@@ -1,16 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Runtime dependencies
4
- gem 'rails', '~> 5.0.0'
5
- gem 'mysql2', '~> 0.4.4'
6
-
7
- # Development dependencies
8
- gem 'rspec', '~> 3.4'
9
- gem 'rake'
10
- gem 'byebug'
11
- gem 'database_cleaner'
12
- gem 'combustion'
13
- gem 'gemika'
14
-
15
- # Gem under test
16
- gem 'temporal_tables', :path => '..'
@@ -1,147 +0,0 @@
1
- PATH
2
- remote: ..
3
- specs:
4
- temporal_tables (0.7.0)
5
- rails (>= 5.0, < 6.1)
6
-
7
- GEM
8
- remote: https://rubygems.org/
9
- specs:
10
- actioncable (5.0.7.1)
11
- actionpack (= 5.0.7.1)
12
- nio4r (>= 1.2, < 3.0)
13
- websocket-driver (~> 0.6.1)
14
- actionmailer (5.0.7.1)
15
- actionpack (= 5.0.7.1)
16
- actionview (= 5.0.7.1)
17
- activejob (= 5.0.7.1)
18
- mail (~> 2.5, >= 2.5.4)
19
- rails-dom-testing (~> 2.0)
20
- actionpack (5.0.7.1)
21
- actionview (= 5.0.7.1)
22
- activesupport (= 5.0.7.1)
23
- rack (~> 2.0)
24
- rack-test (~> 0.6.3)
25
- rails-dom-testing (~> 2.0)
26
- rails-html-sanitizer (~> 1.0, >= 1.0.2)
27
- actionview (5.0.7.1)
28
- activesupport (= 5.0.7.1)
29
- builder (~> 3.1)
30
- erubis (~> 2.7.0)
31
- rails-dom-testing (~> 2.0)
32
- rails-html-sanitizer (~> 1.0, >= 1.0.3)
33
- activejob (5.0.7.1)
34
- activesupport (= 5.0.7.1)
35
- globalid (>= 0.3.6)
36
- activemodel (5.0.7.1)
37
- activesupport (= 5.0.7.1)
38
- activerecord (5.0.7.1)
39
- activemodel (= 5.0.7.1)
40
- activesupport (= 5.0.7.1)
41
- arel (~> 7.0)
42
- activesupport (5.0.7.1)
43
- concurrent-ruby (~> 1.0, >= 1.0.2)
44
- i18n (>= 0.7, < 2)
45
- minitest (~> 5.1)
46
- tzinfo (~> 1.1)
47
- arel (7.1.4)
48
- builder (3.2.3)
49
- byebug (10.0.2)
50
- combustion (1.0.0)
51
- activesupport (>= 3.0.0)
52
- railties (>= 3.0.0)
53
- thor (>= 0.14.6)
54
- concurrent-ruby (1.1.4)
55
- crass (1.0.4)
56
- database_cleaner (1.7.0)
57
- diff-lcs (1.3)
58
- erubis (2.7.0)
59
- gemika (0.3.4)
60
- globalid (0.4.1)
61
- activesupport (>= 4.2.0)
62
- i18n (1.5.1)
63
- concurrent-ruby (~> 1.0)
64
- loofah (2.2.3)
65
- crass (~> 1.0.2)
66
- nokogiri (>= 1.5.9)
67
- mail (2.7.1)
68
- mini_mime (>= 0.1.1)
69
- method_source (0.9.2)
70
- mini_mime (1.0.1)
71
- mini_portile2 (2.4.0)
72
- minitest (5.11.3)
73
- mysql2 (0.4.10)
74
- nio4r (2.3.1)
75
- nokogiri (1.10.0)
76
- mini_portile2 (~> 2.4.0)
77
- rack (2.0.6)
78
- rack-test (0.6.3)
79
- rack (>= 1.0)
80
- rails (5.0.7.1)
81
- actioncable (= 5.0.7.1)
82
- actionmailer (= 5.0.7.1)
83
- actionpack (= 5.0.7.1)
84
- actionview (= 5.0.7.1)
85
- activejob (= 5.0.7.1)
86
- activemodel (= 5.0.7.1)
87
- activerecord (= 5.0.7.1)
88
- activesupport (= 5.0.7.1)
89
- bundler (>= 1.3.0)
90
- railties (= 5.0.7.1)
91
- sprockets-rails (>= 2.0.0)
92
- rails-dom-testing (2.0.3)
93
- activesupport (>= 4.2.0)
94
- nokogiri (>= 1.6)
95
- rails-html-sanitizer (1.0.4)
96
- loofah (~> 2.2, >= 2.2.2)
97
- railties (5.0.7.1)
98
- actionpack (= 5.0.7.1)
99
- activesupport (= 5.0.7.1)
100
- method_source
101
- rake (>= 0.8.7)
102
- thor (>= 0.18.1, < 2.0)
103
- rake (12.3.2)
104
- rspec (3.8.0)
105
- rspec-core (~> 3.8.0)
106
- rspec-expectations (~> 3.8.0)
107
- rspec-mocks (~> 3.8.0)
108
- rspec-core (3.8.0)
109
- rspec-support (~> 3.8.0)
110
- rspec-expectations (3.8.2)
111
- diff-lcs (>= 1.2.0, < 2.0)
112
- rspec-support (~> 3.8.0)
113
- rspec-mocks (3.8.0)
114
- diff-lcs (>= 1.2.0, < 2.0)
115
- rspec-support (~> 3.8.0)
116
- rspec-support (3.8.0)
117
- sprockets (3.7.2)
118
- concurrent-ruby (~> 1.0)
119
- rack (> 1, < 3)
120
- sprockets-rails (3.2.1)
121
- actionpack (>= 4.0)
122
- activesupport (>= 4.0)
123
- sprockets (>= 3.0.0)
124
- thor (0.20.3)
125
- thread_safe (0.3.6)
126
- tzinfo (1.2.5)
127
- thread_safe (~> 0.1)
128
- websocket-driver (0.6.5)
129
- websocket-extensions (>= 0.1.0)
130
- websocket-extensions (0.1.3)
131
-
132
- PLATFORMS
133
- ruby
134
-
135
- DEPENDENCIES
136
- byebug
137
- combustion
138
- database_cleaner
139
- gemika
140
- mysql2 (~> 0.4.4)
141
- rails (~> 5.0.0)
142
- rake
143
- rspec (~> 3.4)
144
- temporal_tables!
145
-
146
- BUNDLED WITH
147
- 1.17.3
@@ -1,16 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Runtime dependencies
4
- gem 'rails', '~> 5.0.0'
5
- gem 'pg', '>= 0.18', '< 2.0'
6
-
7
- # Development dependencies
8
- gem 'rspec', '~> 3.4'
9
- gem 'rake'
10
- gem 'byebug'
11
- gem 'database_cleaner'
12
- gem 'combustion'
13
- gem 'gemika'
14
-
15
- # Gem under test
16
- gem 'temporal_tables', :path => '..'
@@ -1,147 +0,0 @@
1
- PATH
2
- remote: ..
3
- specs:
4
- temporal_tables (0.7.0)
5
- rails (>= 5.0, < 6.1)
6
-
7
- GEM
8
- remote: https://rubygems.org/
9
- specs:
10
- actioncable (5.0.7.1)
11
- actionpack (= 5.0.7.1)
12
- nio4r (>= 1.2, < 3.0)
13
- websocket-driver (~> 0.6.1)
14
- actionmailer (5.0.7.1)
15
- actionpack (= 5.0.7.1)
16
- actionview (= 5.0.7.1)
17
- activejob (= 5.0.7.1)
18
- mail (~> 2.5, >= 2.5.4)
19
- rails-dom-testing (~> 2.0)
20
- actionpack (5.0.7.1)
21
- actionview (= 5.0.7.1)
22
- activesupport (= 5.0.7.1)
23
- rack (~> 2.0)
24
- rack-test (~> 0.6.3)
25
- rails-dom-testing (~> 2.0)
26
- rails-html-sanitizer (~> 1.0, >= 1.0.2)
27
- actionview (5.0.7.1)
28
- activesupport (= 5.0.7.1)
29
- builder (~> 3.1)
30
- erubis (~> 2.7.0)
31
- rails-dom-testing (~> 2.0)
32
- rails-html-sanitizer (~> 1.0, >= 1.0.3)
33
- activejob (5.0.7.1)
34
- activesupport (= 5.0.7.1)
35
- globalid (>= 0.3.6)
36
- activemodel (5.0.7.1)
37
- activesupport (= 5.0.7.1)
38
- activerecord (5.0.7.1)
39
- activemodel (= 5.0.7.1)
40
- activesupport (= 5.0.7.1)
41
- arel (~> 7.0)
42
- activesupport (5.0.7.1)
43
- concurrent-ruby (~> 1.0, >= 1.0.2)
44
- i18n (>= 0.7, < 2)
45
- minitest (~> 5.1)
46
- tzinfo (~> 1.1)
47
- arel (7.1.4)
48
- builder (3.2.3)
49
- byebug (10.0.2)
50
- combustion (1.0.0)
51
- activesupport (>= 3.0.0)
52
- railties (>= 3.0.0)
53
- thor (>= 0.14.6)
54
- concurrent-ruby (1.1.4)
55
- crass (1.0.4)
56
- database_cleaner (1.7.0)
57
- diff-lcs (1.3)
58
- erubis (2.7.0)
59
- gemika (0.3.4)
60
- globalid (0.4.1)
61
- activesupport (>= 4.2.0)
62
- i18n (1.5.1)
63
- concurrent-ruby (~> 1.0)
64
- loofah (2.2.3)
65
- crass (~> 1.0.2)
66
- nokogiri (>= 1.5.9)
67
- mail (2.7.1)
68
- mini_mime (>= 0.1.1)
69
- method_source (0.9.2)
70
- mini_mime (1.0.1)
71
- mini_portile2 (2.4.0)
72
- minitest (5.11.3)
73
- nio4r (2.3.1)
74
- nokogiri (1.10.0)
75
- mini_portile2 (~> 2.4.0)
76
- pg (1.1.3)
77
- rack (2.0.6)
78
- rack-test (0.6.3)
79
- rack (>= 1.0)
80
- rails (5.0.7.1)
81
- actioncable (= 5.0.7.1)
82
- actionmailer (= 5.0.7.1)
83
- actionpack (= 5.0.7.1)
84
- actionview (= 5.0.7.1)
85
- activejob (= 5.0.7.1)
86
- activemodel (= 5.0.7.1)
87
- activerecord (= 5.0.7.1)
88
- activesupport (= 5.0.7.1)
89
- bundler (>= 1.3.0)
90
- railties (= 5.0.7.1)
91
- sprockets-rails (>= 2.0.0)
92
- rails-dom-testing (2.0.3)
93
- activesupport (>= 4.2.0)
94
- nokogiri (>= 1.6)
95
- rails-html-sanitizer (1.0.4)
96
- loofah (~> 2.2, >= 2.2.2)
97
- railties (5.0.7.1)
98
- actionpack (= 5.0.7.1)
99
- activesupport (= 5.0.7.1)
100
- method_source
101
- rake (>= 0.8.7)
102
- thor (>= 0.18.1, < 2.0)
103
- rake (12.3.2)
104
- rspec (3.8.0)
105
- rspec-core (~> 3.8.0)
106
- rspec-expectations (~> 3.8.0)
107
- rspec-mocks (~> 3.8.0)
108
- rspec-core (3.8.0)
109
- rspec-support (~> 3.8.0)
110
- rspec-expectations (3.8.2)
111
- diff-lcs (>= 1.2.0, < 2.0)
112
- rspec-support (~> 3.8.0)
113
- rspec-mocks (3.8.0)
114
- diff-lcs (>= 1.2.0, < 2.0)
115
- rspec-support (~> 3.8.0)
116
- rspec-support (3.8.0)
117
- sprockets (3.7.2)
118
- concurrent-ruby (~> 1.0)
119
- rack (> 1, < 3)
120
- sprockets-rails (3.2.1)
121
- actionpack (>= 4.0)
122
- activesupport (>= 4.0)
123
- sprockets (>= 3.0.0)
124
- thor (0.20.3)
125
- thread_safe (0.3.6)
126
- tzinfo (1.2.5)
127
- thread_safe (~> 0.1)
128
- websocket-driver (0.6.5)
129
- websocket-extensions (>= 0.1.0)
130
- websocket-extensions (0.1.3)
131
-
132
- PLATFORMS
133
- ruby
134
-
135
- DEPENDENCIES
136
- byebug
137
- combustion
138
- database_cleaner
139
- gemika
140
- pg (>= 0.18, < 2.0)
141
- rails (~> 5.0.0)
142
- rake
143
- rspec (~> 3.4)
144
- temporal_tables!
145
-
146
- BUNDLED WITH
147
- 1.17.3