temporal_tables 2.0.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml DELETED
@@ -1,11 +0,0 @@
1
- rvm:
2
- - 3.0.0
3
-
4
- gemfile:
5
- - gemfiles/Gemfile.6.0.pg
6
- - gemfiles/Gemfile.6.1.pg
7
- - gemfiles/Gemfile.7.0.pg
8
-
9
- - gemfiles/Gemfile.6.0.mysql
10
- - gemfiles/Gemfile.6.1.mysql
11
- - gemfiles/Gemfile.7.0.mysql
@@ -1,171 +0,0 @@
1
- PATH
2
- remote: ..
3
- specs:
4
- temporal_tables (1.0.3)
5
- rails (>= 6.0, < 7.1)
6
-
7
- GEM
8
- remote: https://rubygems.org/
9
- specs:
10
- actioncable (6.0.4.4)
11
- actionpack (= 6.0.4.4)
12
- nio4r (~> 2.0)
13
- websocket-driver (>= 0.6.1)
14
- actionmailbox (6.0.4.4)
15
- actionpack (= 6.0.4.4)
16
- activejob (= 6.0.4.4)
17
- activerecord (= 6.0.4.4)
18
- activestorage (= 6.0.4.4)
19
- activesupport (= 6.0.4.4)
20
- mail (>= 2.7.1)
21
- actionmailer (6.0.4.4)
22
- actionpack (= 6.0.4.4)
23
- actionview (= 6.0.4.4)
24
- activejob (= 6.0.4.4)
25
- mail (~> 2.5, >= 2.5.4)
26
- rails-dom-testing (~> 2.0)
27
- actionpack (6.0.4.4)
28
- actionview (= 6.0.4.4)
29
- activesupport (= 6.0.4.4)
30
- rack (~> 2.0, >= 2.0.8)
31
- rack-test (>= 0.6.3)
32
- rails-dom-testing (~> 2.0)
33
- rails-html-sanitizer (~> 1.0, >= 1.2.0)
34
- actiontext (6.0.4.4)
35
- actionpack (= 6.0.4.4)
36
- activerecord (= 6.0.4.4)
37
- activestorage (= 6.0.4.4)
38
- activesupport (= 6.0.4.4)
39
- nokogiri (>= 1.8.5)
40
- actionview (6.0.4.4)
41
- activesupport (= 6.0.4.4)
42
- builder (~> 3.1)
43
- erubi (~> 1.4)
44
- rails-dom-testing (~> 2.0)
45
- rails-html-sanitizer (~> 1.1, >= 1.2.0)
46
- activejob (6.0.4.4)
47
- activesupport (= 6.0.4.4)
48
- globalid (>= 0.3.6)
49
- activemodel (6.0.4.4)
50
- activesupport (= 6.0.4.4)
51
- activerecord (6.0.4.4)
52
- activemodel (= 6.0.4.4)
53
- activesupport (= 6.0.4.4)
54
- activestorage (6.0.4.4)
55
- actionpack (= 6.0.4.4)
56
- activejob (= 6.0.4.4)
57
- activerecord (= 6.0.4.4)
58
- marcel (~> 1.0.0)
59
- activesupport (6.0.4.4)
60
- concurrent-ruby (~> 1.0, >= 1.0.2)
61
- i18n (>= 0.7, < 2)
62
- minitest (~> 5.1)
63
- tzinfo (~> 1.1)
64
- zeitwerk (~> 2.2, >= 2.2.2)
65
- builder (3.2.4)
66
- byebug (11.1.1)
67
- combustion (1.3.5)
68
- activesupport (>= 3.0.0)
69
- railties (>= 3.0.0)
70
- thor (>= 0.14.6)
71
- concurrent-ruby (1.1.9)
72
- crass (1.0.6)
73
- database_cleaner (1.8.3)
74
- diff-lcs (1.3)
75
- erubi (1.10.0)
76
- gemika (0.6.1)
77
- globalid (1.0.0)
78
- activesupport (>= 5.0)
79
- i18n (1.8.11)
80
- concurrent-ruby (~> 1.0)
81
- loofah (2.13.0)
82
- crass (~> 1.0.2)
83
- nokogiri (>= 1.5.9)
84
- mail (2.7.1)
85
- mini_mime (>= 0.1.1)
86
- marcel (1.0.2)
87
- method_source (1.0.0)
88
- mini_mime (1.1.2)
89
- mini_portile2 (2.6.1)
90
- minitest (5.15.0)
91
- mysql2 (0.5.3)
92
- nio4r (2.5.8)
93
- nokogiri (1.12.5)
94
- mini_portile2 (~> 2.6.1)
95
- racc (~> 1.4)
96
- racc (1.6.0)
97
- rack (2.2.3)
98
- rack-test (1.1.0)
99
- rack (>= 1.0, < 3)
100
- rails (6.0.4.4)
101
- actioncable (= 6.0.4.4)
102
- actionmailbox (= 6.0.4.4)
103
- actionmailer (= 6.0.4.4)
104
- actionpack (= 6.0.4.4)
105
- actiontext (= 6.0.4.4)
106
- actionview (= 6.0.4.4)
107
- activejob (= 6.0.4.4)
108
- activemodel (= 6.0.4.4)
109
- activerecord (= 6.0.4.4)
110
- activestorage (= 6.0.4.4)
111
- activesupport (= 6.0.4.4)
112
- bundler (>= 1.3.0)
113
- railties (= 6.0.4.4)
114
- sprockets-rails (>= 2.0.0)
115
- rails-dom-testing (2.0.3)
116
- activesupport (>= 4.2.0)
117
- nokogiri (>= 1.6)
118
- rails-html-sanitizer (1.4.2)
119
- loofah (~> 2.3)
120
- railties (6.0.4.4)
121
- actionpack (= 6.0.4.4)
122
- activesupport (= 6.0.4.4)
123
- method_source
124
- rake (>= 0.8.7)
125
- thor (>= 0.20.3, < 2.0)
126
- rake (13.0.6)
127
- rspec (3.9.0)
128
- rspec-core (~> 3.9.0)
129
- rspec-expectations (~> 3.9.0)
130
- rspec-mocks (~> 3.9.0)
131
- rspec-core (3.9.1)
132
- rspec-support (~> 3.9.1)
133
- rspec-expectations (3.9.1)
134
- diff-lcs (>= 1.2.0, < 2.0)
135
- rspec-support (~> 3.9.0)
136
- rspec-mocks (3.9.1)
137
- diff-lcs (>= 1.2.0, < 2.0)
138
- rspec-support (~> 3.9.0)
139
- rspec-support (3.9.2)
140
- sprockets (4.0.2)
141
- concurrent-ruby (~> 1.0)
142
- rack (> 1, < 3)
143
- sprockets-rails (3.4.2)
144
- actionpack (>= 5.2)
145
- activesupport (>= 5.2)
146
- sprockets (>= 3.0.0)
147
- thor (1.1.0)
148
- thread_safe (0.3.6)
149
- tzinfo (1.2.9)
150
- thread_safe (~> 0.1)
151
- websocket-driver (0.7.5)
152
- websocket-extensions (>= 0.1.0)
153
- websocket-extensions (0.1.5)
154
- zeitwerk (2.5.3)
155
-
156
- PLATFORMS
157
- ruby
158
-
159
- DEPENDENCIES
160
- byebug
161
- combustion
162
- database_cleaner
163
- gemika
164
- mysql2
165
- rails (~> 6.0.2)
166
- rake
167
- rspec (~> 3.4)
168
- temporal_tables!
169
-
170
- BUNDLED WITH
171
- 2.3.4
@@ -1,176 +0,0 @@
1
- PATH
2
- remote: ..
3
- specs:
4
- temporal_tables (1.0.3)
5
- rails (>= 6.0, < 7.1)
6
-
7
- GEM
8
- remote: https://rubygems.org/
9
- specs:
10
- actioncable (6.0.4.4)
11
- actionpack (= 6.0.4.4)
12
- nio4r (~> 2.0)
13
- websocket-driver (>= 0.6.1)
14
- actionmailbox (6.0.4.4)
15
- actionpack (= 6.0.4.4)
16
- activejob (= 6.0.4.4)
17
- activerecord (= 6.0.4.4)
18
- activestorage (= 6.0.4.4)
19
- activesupport (= 6.0.4.4)
20
- mail (>= 2.7.1)
21
- actionmailer (6.0.4.4)
22
- actionpack (= 6.0.4.4)
23
- actionview (= 6.0.4.4)
24
- activejob (= 6.0.4.4)
25
- mail (~> 2.5, >= 2.5.4)
26
- rails-dom-testing (~> 2.0)
27
- actionpack (6.0.4.4)
28
- actionview (= 6.0.4.4)
29
- activesupport (= 6.0.4.4)
30
- rack (~> 2.0, >= 2.0.8)
31
- rack-test (>= 0.6.3)
32
- rails-dom-testing (~> 2.0)
33
- rails-html-sanitizer (~> 1.0, >= 1.2.0)
34
- actiontext (6.0.4.4)
35
- actionpack (= 6.0.4.4)
36
- activerecord (= 6.0.4.4)
37
- activestorage (= 6.0.4.4)
38
- activesupport (= 6.0.4.4)
39
- nokogiri (>= 1.8.5)
40
- actionview (6.0.4.4)
41
- activesupport (= 6.0.4.4)
42
- builder (~> 3.1)
43
- erubi (~> 1.4)
44
- rails-dom-testing (~> 2.0)
45
- rails-html-sanitizer (~> 1.1, >= 1.2.0)
46
- activejob (6.0.4.4)
47
- activesupport (= 6.0.4.4)
48
- globalid (>= 0.3.6)
49
- activemodel (6.0.4.4)
50
- activesupport (= 6.0.4.4)
51
- activerecord (6.0.4.4)
52
- activemodel (= 6.0.4.4)
53
- activesupport (= 6.0.4.4)
54
- activestorage (6.0.4.4)
55
- actionpack (= 6.0.4.4)
56
- activejob (= 6.0.4.4)
57
- activerecord (= 6.0.4.4)
58
- marcel (~> 1.0.0)
59
- activesupport (6.0.4.4)
60
- concurrent-ruby (~> 1.0, >= 1.0.2)
61
- i18n (>= 0.7, < 2)
62
- minitest (~> 5.1)
63
- tzinfo (~> 1.1)
64
- zeitwerk (~> 2.2, >= 2.2.2)
65
- builder (3.2.4)
66
- byebug (11.1.3)
67
- combustion (1.3.5)
68
- activesupport (>= 3.0.0)
69
- railties (>= 3.0.0)
70
- thor (>= 0.14.6)
71
- concurrent-ruby (1.1.9)
72
- crass (1.0.6)
73
- database_cleaner (2.0.1)
74
- database_cleaner-active_record (~> 2.0.0)
75
- database_cleaner-active_record (2.0.1)
76
- activerecord (>= 5.a)
77
- database_cleaner-core (~> 2.0.0)
78
- database_cleaner-core (2.0.1)
79
- diff-lcs (1.5.0)
80
- erubi (1.10.0)
81
- gemika (0.6.1)
82
- globalid (1.0.0)
83
- activesupport (>= 5.0)
84
- i18n (1.8.11)
85
- concurrent-ruby (~> 1.0)
86
- loofah (2.13.0)
87
- crass (~> 1.0.2)
88
- nokogiri (>= 1.5.9)
89
- mail (2.7.1)
90
- mini_mime (>= 0.1.1)
91
- marcel (1.0.2)
92
- method_source (1.0.0)
93
- mini_mime (1.1.2)
94
- mini_portile2 (2.6.1)
95
- minitest (5.15.0)
96
- nio4r (2.5.8)
97
- nokogiri (1.12.5)
98
- mini_portile2 (~> 2.6.1)
99
- racc (~> 1.4)
100
- pg (1.2.3)
101
- racc (1.6.0)
102
- rack (2.2.3)
103
- rack-test (1.1.0)
104
- rack (>= 1.0, < 3)
105
- rails (6.0.4.4)
106
- actioncable (= 6.0.4.4)
107
- actionmailbox (= 6.0.4.4)
108
- actionmailer (= 6.0.4.4)
109
- actionpack (= 6.0.4.4)
110
- actiontext (= 6.0.4.4)
111
- actionview (= 6.0.4.4)
112
- activejob (= 6.0.4.4)
113
- activemodel (= 6.0.4.4)
114
- activerecord (= 6.0.4.4)
115
- activestorage (= 6.0.4.4)
116
- activesupport (= 6.0.4.4)
117
- bundler (>= 1.3.0)
118
- railties (= 6.0.4.4)
119
- sprockets-rails (>= 2.0.0)
120
- rails-dom-testing (2.0.3)
121
- activesupport (>= 4.2.0)
122
- nokogiri (>= 1.6)
123
- rails-html-sanitizer (1.4.2)
124
- loofah (~> 2.3)
125
- railties (6.0.4.4)
126
- actionpack (= 6.0.4.4)
127
- activesupport (= 6.0.4.4)
128
- method_source
129
- rake (>= 0.8.7)
130
- thor (>= 0.20.3, < 2.0)
131
- rake (13.0.6)
132
- rspec (3.10.0)
133
- rspec-core (~> 3.10.0)
134
- rspec-expectations (~> 3.10.0)
135
- rspec-mocks (~> 3.10.0)
136
- rspec-core (3.10.1)
137
- rspec-support (~> 3.10.0)
138
- rspec-expectations (3.10.1)
139
- diff-lcs (>= 1.2.0, < 2.0)
140
- rspec-support (~> 3.10.0)
141
- rspec-mocks (3.10.2)
142
- diff-lcs (>= 1.2.0, < 2.0)
143
- rspec-support (~> 3.10.0)
144
- rspec-support (3.10.3)
145
- sprockets (4.0.2)
146
- concurrent-ruby (~> 1.0)
147
- rack (> 1, < 3)
148
- sprockets-rails (3.4.2)
149
- actionpack (>= 5.2)
150
- activesupport (>= 5.2)
151
- sprockets (>= 3.0.0)
152
- thor (1.1.0)
153
- thread_safe (0.3.6)
154
- tzinfo (1.2.9)
155
- thread_safe (~> 0.1)
156
- websocket-driver (0.7.5)
157
- websocket-extensions (>= 0.1.0)
158
- websocket-extensions (0.1.5)
159
- zeitwerk (2.5.3)
160
-
161
- PLATFORMS
162
- ruby
163
-
164
- DEPENDENCIES
165
- byebug
166
- combustion
167
- database_cleaner
168
- gemika
169
- pg (>= 0.18, < 2.0)
170
- rails (~> 6.0.2)
171
- rake
172
- rspec (~> 3.4)
173
- temporal_tables!
174
-
175
- BUNDLED WITH
176
- 2.3.4
@@ -1,207 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'digest'
4
-
5
- module TemporalTables
6
- # The main difference here is the add_index method, which still uses
7
- # the old options={} syntax
8
- module TemporalAdapterSixOh # rubocop:disable Metrics/ModuleLength
9
- def create_table(table_name, **options, &block) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity
10
- if options[:temporal_bypass]
11
- super(table_name, **options, &block)
12
- else
13
- skip_table = TemporalTables.skipped_temporal_tables.include?(table_name.to_sym) || table_name.to_s =~ /_h$/
14
-
15
- super(table_name, **options) do |t|
16
- block.call t
17
-
18
- if TemporalTables.add_updated_by_field && !skip_table
19
- updated_by_already_exists = t.columns.any? { |c| c.name == 'updated_by' }
20
- if updated_by_already_exists
21
- puts "consider adding #{table_name} to TemporalTables skip_table" # rubocop:disable Rails/Output
22
- else
23
- t.column(:updated_by, TemporalTables.updated_by_type)
24
- end
25
- end
26
- end
27
-
28
- if options[:temporal] || (TemporalTables.create_by_default && !skip_table)
29
- add_temporal_table table_name, **options
30
- end
31
- end
32
- end
33
-
34
- def add_temporal_table(table_name, **options) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
35
- create_table(
36
- temporal_name(table_name),
37
- **options.merge(id: false, primary_key: 'history_id', temporal_bypass: true)
38
- ) do |t|
39
- t.datetime :eff_from, null: false, limit: 6
40
- t.datetime :eff_to, null: false, limit: 6, default: TemporalTables::END_OF_TIME
41
-
42
- columns(table_name).each do |c|
43
- column_type = c.type == :enum ? c.sql_type_metadata.sql_type : c.type
44
- t.column c.name, column_type, limit: c.limit
45
- end
46
- end
47
-
48
- if TemporalTables.add_updated_by_field && !column_exists?(table_name, :updated_by)
49
- change_table table_name do |t|
50
- t.column :updated_by, TemporalTables.updated_by_type
51
- end
52
- end
53
-
54
- original_primary_key = original_primary_key(table_name)
55
- temporal_table_index_name = index_name(temporal_name(table_name), [original_primary_key, :eff_to])
56
- if temporal_table_index_name.length > index_name_length
57
- temporal_table_index_name = truncated_index_name(temporal_table_index_name)
58
- end
59
- add_index temporal_name(table_name), [original_primary_key, :eff_to], { name: temporal_table_index_name }
60
- create_temporal_triggers table_name, original_primary_key
61
- create_temporal_indexes table_name
62
- end
63
-
64
- def remove_temporal_table(table_name)
65
- return unless table_exists?(temporal_name(table_name))
66
-
67
- drop_temporal_triggers table_name
68
- drop_table_without_temporal temporal_name(table_name)
69
- end
70
-
71
- def drop_table(table_name, **options)
72
- super(table_name, **options)
73
-
74
- super(temporal_name(table_name), **options) if table_exists?(temporal_name(table_name))
75
- end
76
-
77
- def rename_table(name, new_name)
78
- drop_temporal_triggers name if table_exists?(temporal_name(name))
79
-
80
- super name, new_name
81
-
82
- return unless table_exists?(temporal_name(name))
83
-
84
- super(temporal_name(name), temporal_name(new_name))
85
- create_temporal_triggers new_name, original_primary_key(table_name)
86
- end
87
-
88
- def add_column(table_name, column_name, type, **options)
89
- super(table_name, column_name, type, **options)
90
-
91
- return unless table_exists?(temporal_name(table_name))
92
-
93
- super temporal_name(table_name), column_name, type, **options
94
- create_temporal_triggers table_name, original_primary_key(table_name)
95
- end
96
-
97
- def remove_columns(table_name, *column_names, **options)
98
- super(table_name, *column_names, **options)
99
-
100
- return unless table_exists?(temporal_name(table_name))
101
-
102
- super temporal_name(table_name), *column_names, **options
103
- create_temporal_triggers table_name, original_primary_key(table_name)
104
- end
105
-
106
- def remove_column(table_name, column_name, type = nil, **options)
107
- super(table_name, column_name, type, **options)
108
-
109
- return unless table_exists?(temporal_name(table_name))
110
-
111
- super temporal_name(table_name), column_name, type, **options
112
- create_temporal_triggers table_name, original_primary_key(table_name)
113
- end
114
-
115
- def change_column(table_name, column_name, type, **options)
116
- super(table_name, column_name, type, **options)
117
-
118
- return unless table_exists?(temporal_name(table_name))
119
-
120
- super temporal_name(table_name), column_name, type, **options
121
- # Don't need to update triggers here...
122
- end
123
-
124
- def rename_column(table_name, column_name, new_column_name)
125
- super(table_name, column_name, new_column_name)
126
-
127
- return unless table_exists?(temporal_name(table_name))
128
-
129
- super temporal_name(table_name), column_name, new_column_name
130
- create_temporal_triggers table_name, original_primary_key(table_name)
131
- end
132
-
133
- def add_index(table_name, column_name, options = {})
134
- super(table_name, column_name, options)
135
-
136
- return unless table_exists?(temporal_name(table_name))
137
-
138
- column_names = Array.wrap(column_name)
139
- idx_name = temporal_index_name(options[:name] || index_name(table_name, column: column_names))
140
- super temporal_name(table_name), column_name, options.except(:unique).merge(name: idx_name)
141
- end
142
-
143
- def remove_index(table_name, options = {})
144
- original_index_name = index_name_for_remove(table_name, options)
145
- super(table_name, options)
146
-
147
- return unless table_exists?(temporal_name(table_name))
148
-
149
- idx_name = temporal_index_name(original_index_name)
150
- super temporal_name(table_name), name: idx_name
151
- end
152
-
153
- def create_temporal_indexes(table_name) # rubocop:disable Metrics/MethodLength
154
- indexes = ActiveRecord::Base.connection.indexes(table_name)
155
-
156
- indexes.each do |index|
157
- index_name = temporal_index_name(index.name)
158
-
159
- next if temporal_index_exists?(table_name, index_name)
160
-
161
- add_index(
162
- temporal_name(table_name),
163
- index.columns,
164
- # exclude unique constraints for temporal tables
165
- name: index_name,
166
- length: index.lengths,
167
- order: index.orders
168
- )
169
- end
170
- end
171
-
172
- def temporal_name(table_name)
173
- "#{table_name}_h"
174
- end
175
-
176
- def create_temporal_triggers(_table_name)
177
- raise NotImplementedError, 'create_temporal_triggers is not implemented'
178
- end
179
-
180
- def drop_temporal_triggers(_table_name)
181
- raise NotImplementedError, 'drop_temporal_triggers is not implemented'
182
- end
183
-
184
- # Index names max out at 63 characters. If appending _h to the index name would surpass that limit,
185
- # we can trim the index name and append a deterministically generated 5 character hash as well as _h.
186
- def temporal_index_name(index_name)
187
- "#{index_name.length < 62 ? index_name : truncated_index_name(index_name, 2)}_h"
188
- end
189
-
190
- def truncated_index_name(index_name, required_padding = 0)
191
- max_length = index_name_length - required_padding
192
- index_name_hash = Digest::SHA1.base64digest(index_name.to_s)[0, 5]
193
- "#{index_name[0, max_length - 6]}_#{index_name_hash}"
194
- end
195
-
196
- def temporal_index_exists?(table_name, index_name)
197
- index_name_exists?(temporal_name(table_name), index_name)
198
- end
199
-
200
- def original_primary_key(table_name)
201
- original_primary_key = primary_key(table_name)
202
- raise 'temporal_adapter requires that the table has a single primary key' unless original_primary_key.is_a? String
203
-
204
- original_primary_key
205
- end
206
- end
207
- end