historiographer 1.4.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -2
- data/Gemfile.lock +113 -103
- data/README.md +10 -1
- data/VERSION +1 -1
- data/historiographer.gemspec +22 -37
- data/lib/historiographer/history_migration_mysql.rb +6 -5
- data/lib/historiographer/safe.rb +0 -1
- data/lib/historiographer.rb +11 -5
- data/spec/db/database.yml +3 -4
- data/spec/db/schema.rb +5 -5
- data/spec/examples.txt +29 -21
- data/spec/historiographer_spec.rb +25 -0
- metadata +12 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cde507fc3738878242d8f3f9c6fe7c86e6c5346077da3d63882a04fc92f0ba94
|
4
|
+
data.tar.gz: 0d8afa8b8d24dd870a4e4c26e322c3d64cd2c7a58e04651382a20e7da0d7b1c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0d139a03f5f2ff866de63981475804033dffb3ec5b67e4af7ed24241fc177bca89af8cc48806913094091478b22c2f64b88e85ad93c2692e7afec02c261e7977
|
7
|
+
data.tar.gz: d398de437246001483d25630aac20dfcf0652fec518b2345d22eedb2f3956a7b17125f8a8803b1337075e0097e72057e8619329d93a3a2c144121d7bca180347
|
data/Gemfile
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
source "https://rubygems.org"
|
2
2
|
ruby "2.6.3"
|
3
3
|
|
4
|
-
gem "activerecord", "
|
4
|
+
gem "activerecord", ">= 5"
|
5
5
|
gem "activesupport"
|
6
6
|
gem "rollbar"
|
7
7
|
gem "activerecord-import"
|
@@ -9,7 +9,7 @@ gem "activerecord-import"
|
|
9
9
|
group :development, :test do
|
10
10
|
gem "pg"
|
11
11
|
gem "pry"
|
12
|
-
gem "mysql2", "0.
|
12
|
+
gem "mysql2", "0.5"
|
13
13
|
gem "standalone_migrations"
|
14
14
|
gem "timecop"
|
15
15
|
gem "paranoia"
|
data/Gemfile.lock
CHANGED
@@ -18,54 +18,59 @@ GIT
|
|
18
18
|
GEM
|
19
19
|
remote: https://rubygems.org/
|
20
20
|
specs:
|
21
|
-
actionpack (
|
22
|
-
actionview (=
|
23
|
-
activesupport (=
|
24
|
-
rack (~> 2.0)
|
21
|
+
actionpack (6.1.4.4)
|
22
|
+
actionview (= 6.1.4.4)
|
23
|
+
activesupport (= 6.1.4.4)
|
24
|
+
rack (~> 2.0, >= 2.0.9)
|
25
25
|
rack-test (>= 0.6.3)
|
26
26
|
rails-dom-testing (~> 2.0)
|
27
|
-
rails-html-sanitizer (~> 1.0, >= 1.0
|
28
|
-
actionview (
|
29
|
-
activesupport (=
|
27
|
+
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
28
|
+
actionview (6.1.4.4)
|
29
|
+
activesupport (= 6.1.4.4)
|
30
30
|
builder (~> 3.1)
|
31
31
|
erubi (~> 1.4)
|
32
32
|
rails-dom-testing (~> 2.0)
|
33
|
-
rails-html-sanitizer (~> 1.
|
34
|
-
activemodel (
|
35
|
-
activesupport (=
|
36
|
-
activerecord (
|
37
|
-
activemodel (=
|
38
|
-
activesupport (=
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
activesupport (5.2.3)
|
33
|
+
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
34
|
+
activemodel (6.1.4.4)
|
35
|
+
activesupport (= 6.1.4.4)
|
36
|
+
activerecord (6.1.4.4)
|
37
|
+
activemodel (= 6.1.4.4)
|
38
|
+
activesupport (= 6.1.4.4)
|
39
|
+
activerecord-import (1.3.0)
|
40
|
+
activerecord (>= 4.2)
|
41
|
+
activesupport (6.1.4.4)
|
43
42
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
44
|
-
i18n (>=
|
45
|
-
minitest (
|
46
|
-
tzinfo (~>
|
43
|
+
i18n (>= 1.6, < 2)
|
44
|
+
minitest (>= 5.1)
|
45
|
+
tzinfo (~> 2.0)
|
46
|
+
zeitwerk (~> 2.3)
|
47
47
|
addressable (2.4.0)
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
48
|
+
builder (3.2.4)
|
49
|
+
coderay (1.1.3)
|
50
|
+
concurrent-ruby (1.1.9)
|
51
|
+
crass (1.0.6)
|
52
|
+
database_cleaner (2.0.1)
|
53
|
+
database_cleaner-active_record (~> 2.0.0)
|
54
|
+
database_cleaner-active_record (2.0.1)
|
55
|
+
activerecord (>= 5.a)
|
56
|
+
database_cleaner-core (~> 2.0.0)
|
57
|
+
database_cleaner-core (2.0.1)
|
54
58
|
descendants_tracker (0.0.4)
|
55
59
|
thread_safe (~> 0.3, >= 0.3.1)
|
56
|
-
diff-lcs (1.
|
57
|
-
docile (1.
|
58
|
-
erubi (1.
|
59
|
-
factory_bot (
|
60
|
-
activesupport (>=
|
61
|
-
factory_bot_rails (
|
62
|
-
factory_bot (~>
|
63
|
-
railties (>=
|
60
|
+
diff-lcs (1.5.0)
|
61
|
+
docile (1.4.0)
|
62
|
+
erubi (1.10.0)
|
63
|
+
factory_bot (6.2.0)
|
64
|
+
activesupport (>= 5.0.0)
|
65
|
+
factory_bot_rails (6.2.0)
|
66
|
+
factory_bot (~> 6.2.0)
|
67
|
+
railties (>= 5.0.0)
|
64
68
|
faraday (0.9.2)
|
65
69
|
multipart-post (>= 1.2, < 3)
|
66
|
-
ffi (1.
|
67
|
-
formatador (
|
68
|
-
git (1.
|
70
|
+
ffi (1.15.5)
|
71
|
+
formatador (1.1.0)
|
72
|
+
git (1.10.2)
|
73
|
+
rchardet (~> 1.8)
|
69
74
|
github_api (0.16.0)
|
70
75
|
addressable (~> 2.4.0)
|
71
76
|
descendants_tracker (~> 0.0.4)
|
@@ -73,13 +78,13 @@ GEM
|
|
73
78
|
hashie (>= 3.4)
|
74
79
|
mime-types (>= 1.16, < 3.0)
|
75
80
|
oauth2 (~> 1.0)
|
76
|
-
guard (2.
|
81
|
+
guard (2.18.0)
|
77
82
|
formatador (>= 0.2.4)
|
78
83
|
listen (>= 2.7, < 4.0)
|
79
84
|
lumberjack (>= 1.0.12, < 2.0)
|
80
85
|
nenv (~> 0.1)
|
81
86
|
notiffany (~> 0.0)
|
82
|
-
pry (>= 0.
|
87
|
+
pry (>= 0.13.0)
|
83
88
|
shellany (~> 0.0)
|
84
89
|
thor (>= 0.18.1)
|
85
90
|
guard-compat (1.2.1)
|
@@ -87,104 +92,109 @@ GEM
|
|
87
92
|
guard (~> 2.1)
|
88
93
|
guard-compat (~> 1.1)
|
89
94
|
rspec (>= 2.99.0, < 4.0)
|
90
|
-
hashie (
|
91
|
-
highline (2.0.
|
92
|
-
i18n (1.
|
95
|
+
hashie (5.0.0)
|
96
|
+
highline (2.0.3)
|
97
|
+
i18n (1.9.1)
|
93
98
|
concurrent-ruby (~> 1.0)
|
94
99
|
json (1.8.6)
|
95
|
-
jwt (2.
|
96
|
-
listen (3.1
|
97
|
-
rb-fsevent (~> 0.
|
98
|
-
rb-inotify (~> 0.9, >= 0.9.
|
99
|
-
|
100
|
-
loofah (2.2.3)
|
100
|
+
jwt (2.3.0)
|
101
|
+
listen (3.7.1)
|
102
|
+
rb-fsevent (~> 0.10, >= 0.10.3)
|
103
|
+
rb-inotify (~> 0.9, >= 0.9.10)
|
104
|
+
loofah (2.13.0)
|
101
105
|
crass (~> 1.0.2)
|
102
106
|
nokogiri (>= 1.5.9)
|
103
|
-
lumberjack (1.
|
104
|
-
method_source (0.
|
107
|
+
lumberjack (1.2.8)
|
108
|
+
method_source (1.0.0)
|
105
109
|
mime-types (2.99.3)
|
106
|
-
mini_portile2 (2.
|
107
|
-
minitest (5.
|
108
|
-
multi_json (1.
|
110
|
+
mini_portile2 (2.7.1)
|
111
|
+
minitest (5.15.0)
|
112
|
+
multi_json (1.15.0)
|
109
113
|
multi_xml (0.6.0)
|
110
114
|
multipart-post (2.1.1)
|
111
|
-
mysql2 (0.
|
115
|
+
mysql2 (0.5.0)
|
112
116
|
nenv (0.3.0)
|
113
|
-
nokogiri (1.
|
114
|
-
mini_portile2 (~> 2.
|
117
|
+
nokogiri (1.13.1)
|
118
|
+
mini_portile2 (~> 2.7.0)
|
119
|
+
racc (~> 1.4)
|
115
120
|
notiffany (0.1.3)
|
116
121
|
nenv (~> 0.1)
|
117
122
|
shellany (~> 0.0)
|
118
|
-
oauth2 (1.4.
|
119
|
-
faraday (>= 0.8, <
|
123
|
+
oauth2 (1.4.7)
|
124
|
+
faraday (>= 0.8, < 2.0)
|
120
125
|
jwt (>= 1.0, < 3.0)
|
121
126
|
multi_json (~> 1.3)
|
122
127
|
multi_xml (~> 0.5)
|
123
128
|
rack (>= 1.2, < 3)
|
124
|
-
paranoia (2.
|
125
|
-
activerecord (>=
|
126
|
-
pg (1.1
|
127
|
-
pry (0.
|
128
|
-
coderay (~> 1.1
|
129
|
-
method_source (~>
|
130
|
-
psych (
|
131
|
-
|
129
|
+
paranoia (2.5.2)
|
130
|
+
activerecord (>= 5.1, < 7.1)
|
131
|
+
pg (1.3.1)
|
132
|
+
pry (0.14.1)
|
133
|
+
coderay (~> 1.1)
|
134
|
+
method_source (~> 1.0)
|
135
|
+
psych (4.0.3)
|
136
|
+
stringio
|
137
|
+
racc (1.6.0)
|
138
|
+
rack (2.2.3)
|
132
139
|
rack-test (1.1.0)
|
133
140
|
rack (>= 1.0, < 3)
|
134
141
|
rails-dom-testing (2.0.3)
|
135
142
|
activesupport (>= 4.2.0)
|
136
143
|
nokogiri (>= 1.6)
|
137
|
-
rails-html-sanitizer (1.2
|
138
|
-
loofah (~> 2.
|
139
|
-
railties (
|
140
|
-
actionpack (=
|
141
|
-
activesupport (=
|
144
|
+
rails-html-sanitizer (1.4.2)
|
145
|
+
loofah (~> 2.3)
|
146
|
+
railties (6.1.4.4)
|
147
|
+
actionpack (= 6.1.4.4)
|
148
|
+
activesupport (= 6.1.4.4)
|
142
149
|
method_source
|
143
|
-
rake (>= 0.
|
144
|
-
thor (
|
145
|
-
rake (
|
146
|
-
rb-fsevent (0.
|
147
|
-
rb-inotify (0.10.
|
150
|
+
rake (>= 0.13)
|
151
|
+
thor (~> 1.0)
|
152
|
+
rake (13.0.6)
|
153
|
+
rb-fsevent (0.11.0)
|
154
|
+
rb-inotify (0.10.1)
|
148
155
|
ffi (~> 1.0)
|
156
|
+
rchardet (1.8.0)
|
149
157
|
rdoc (3.12.2)
|
150
158
|
json (~> 1.4)
|
151
|
-
rollbar (
|
152
|
-
rspec (3.
|
153
|
-
rspec-core (~> 3.
|
154
|
-
rspec-expectations (~> 3.
|
155
|
-
rspec-mocks (~> 3.
|
156
|
-
rspec-core (3.
|
157
|
-
rspec-support (~> 3.
|
158
|
-
rspec-expectations (3.
|
159
|
+
rollbar (3.3.0)
|
160
|
+
rspec (3.10.0)
|
161
|
+
rspec-core (~> 3.10.0)
|
162
|
+
rspec-expectations (~> 3.10.0)
|
163
|
+
rspec-mocks (~> 3.10.0)
|
164
|
+
rspec-core (3.10.2)
|
165
|
+
rspec-support (~> 3.10.0)
|
166
|
+
rspec-expectations (3.10.2)
|
159
167
|
diff-lcs (>= 1.2.0, < 2.0)
|
160
|
-
rspec-support (~> 3.
|
161
|
-
rspec-mocks (3.
|
168
|
+
rspec-support (~> 3.10.0)
|
169
|
+
rspec-mocks (3.10.3)
|
162
170
|
diff-lcs (>= 1.2.0, < 2.0)
|
163
|
-
rspec-support (~> 3.
|
164
|
-
rspec-support (3.
|
165
|
-
ruby_dep (1.5.0)
|
171
|
+
rspec-support (~> 3.10.0)
|
172
|
+
rspec-support (3.10.3)
|
166
173
|
semver2 (3.4.2)
|
167
174
|
shellany (0.0.1)
|
168
|
-
simplecov (0.
|
175
|
+
simplecov (0.21.2)
|
169
176
|
docile (~> 1.1)
|
170
|
-
|
171
|
-
|
172
|
-
simplecov-html (0.
|
173
|
-
|
174
|
-
|
175
|
-
|
177
|
+
simplecov-html (~> 0.11)
|
178
|
+
simplecov_json_formatter (~> 0.1)
|
179
|
+
simplecov-html (0.12.3)
|
180
|
+
simplecov_json_formatter (0.1.3)
|
181
|
+
standalone_migrations (6.1.0)
|
182
|
+
activerecord (>= 4.2.7, < 6.2.0, != 5.2.3.rc1, != 5.2.3)
|
183
|
+
railties (>= 4.2.7, < 6.2.0, != 5.2.3.rc1, != 5.2.3)
|
176
184
|
rake (>= 10.0)
|
177
|
-
|
185
|
+
stringio (3.0.1)
|
186
|
+
thor (1.2.1)
|
178
187
|
thread_safe (0.3.6)
|
179
|
-
timecop (0.9.
|
180
|
-
tzinfo (
|
181
|
-
|
188
|
+
timecop (0.9.4)
|
189
|
+
tzinfo (2.0.4)
|
190
|
+
concurrent-ruby (~> 1.0)
|
191
|
+
zeitwerk (2.5.4)
|
182
192
|
|
183
193
|
PLATFORMS
|
184
194
|
ruby
|
185
195
|
|
186
196
|
DEPENDENCIES
|
187
|
-
activerecord (
|
197
|
+
activerecord (>= 5)
|
188
198
|
activerecord-import
|
189
199
|
activesupport
|
190
200
|
bundler (~> 1.0)
|
@@ -193,7 +203,7 @@ DEPENDENCIES
|
|
193
203
|
guard
|
194
204
|
guard-rspec
|
195
205
|
jeweler!
|
196
|
-
mysql2 (= 0.
|
206
|
+
mysql2 (= 0.5)
|
197
207
|
paranoia
|
198
208
|
pg
|
199
209
|
pry
|
@@ -208,4 +218,4 @@ RUBY VERSION
|
|
208
218
|
ruby 2.6.3p62
|
209
219
|
|
210
220
|
BUNDLED WITH
|
211
|
-
1.17.
|
221
|
+
1.17.3
|
data/README.md
CHANGED
@@ -198,7 +198,7 @@ require "historiographer/postgres_migration"
|
|
198
198
|
class CreatePostHistories < ActiveRecord::Migration
|
199
199
|
def change
|
200
200
|
create_table :post_histories do |t|
|
201
|
-
t.histories
|
201
|
+
t.histories index_names: {
|
202
202
|
title: "my_index_name",
|
203
203
|
[:compound, :index] => "my_compound_index_name"
|
204
204
|
}
|
@@ -207,6 +207,15 @@ class CreatePostHistories < ActiveRecord::Migration
|
|
207
207
|
end
|
208
208
|
```
|
209
209
|
|
210
|
+
== Mysql Install
|
211
|
+
|
212
|
+
For contributors on OSX, you may have difficulty installing mysql:
|
213
|
+
|
214
|
+
```
|
215
|
+
gem install mysql2 -v '0.4.10' --source 'https://rubygems.org/' -- --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include
|
216
|
+
```
|
217
|
+
|
218
|
+
|
210
219
|
== Copyright
|
211
220
|
|
212
221
|
Copyright (c) 2016-2020 brettshollenberger. See LICENSE.txt for
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
2.0.1
|
data/historiographer.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: historiographer
|
5
|
+
# stub: historiographer 2.0.1 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "historiographer".freeze
|
9
|
-
s.version = "
|
9
|
+
s.version = "2.0.1"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib".freeze]
|
13
13
|
s.authors = ["brettshollenberger".freeze]
|
14
|
-
s.date = "
|
14
|
+
s.date = "2022-02-04"
|
15
15
|
s.description = "Creates separate tables for each history table".freeze
|
16
16
|
s.email = "brett.shollenberger@gmail.com".freeze
|
17
17
|
s.extra_rdoc_files = [
|
@@ -59,51 +59,36 @@ Gem::Specification.new do |s|
|
|
59
59
|
]
|
60
60
|
s.homepage = "http://github.com/brettshollenberger/historiographer".freeze
|
61
61
|
s.licenses = ["MIT".freeze]
|
62
|
-
s.rubygems_version = "3.
|
62
|
+
s.rubygems_version = "3.2.23".freeze
|
63
63
|
s.summary = "Create histories of your ActiveRecord tables".freeze
|
64
64
|
|
65
65
|
if s.respond_to? :specification_version then
|
66
66
|
s.specification_version = 4
|
67
|
+
end
|
67
68
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
else
|
84
|
-
s.add_dependency(%q<activerecord>.freeze, ["~> 5.1"])
|
85
|
-
s.add_dependency(%q<activesupport>.freeze, [">= 0"])
|
86
|
-
s.add_dependency(%q<rollbar>.freeze, [">= 0"])
|
87
|
-
s.add_dependency(%q<activerecord-import>.freeze, [">= 0"])
|
88
|
-
s.add_dependency(%q<pg>.freeze, [">= 0"])
|
89
|
-
s.add_dependency(%q<pry>.freeze, [">= 0"])
|
90
|
-
s.add_dependency(%q<mysql2>.freeze, ["= 0.4.10"])
|
91
|
-
s.add_dependency(%q<standalone_migrations>.freeze, [">= 0"])
|
92
|
-
s.add_dependency(%q<timecop>.freeze, [">= 0"])
|
93
|
-
s.add_dependency(%q<paranoia>.freeze, [">= 0"])
|
94
|
-
s.add_dependency(%q<rdoc>.freeze, ["~> 3.12"])
|
95
|
-
s.add_dependency(%q<bundler>.freeze, ["~> 1.0"])
|
96
|
-
s.add_dependency(%q<jeweler>.freeze, [">= 0"])
|
97
|
-
s.add_dependency(%q<simplecov>.freeze, [">= 0"])
|
98
|
-
end
|
69
|
+
if s.respond_to? :add_runtime_dependency then
|
70
|
+
s.add_runtime_dependency(%q<activerecord>.freeze, [">= 5"])
|
71
|
+
s.add_runtime_dependency(%q<activesupport>.freeze, [">= 0"])
|
72
|
+
s.add_runtime_dependency(%q<rollbar>.freeze, [">= 0"])
|
73
|
+
s.add_runtime_dependency(%q<activerecord-import>.freeze, [">= 0"])
|
74
|
+
s.add_development_dependency(%q<pg>.freeze, [">= 0"])
|
75
|
+
s.add_development_dependency(%q<pry>.freeze, [">= 0"])
|
76
|
+
s.add_development_dependency(%q<mysql2>.freeze, ["= 0.5"])
|
77
|
+
s.add_development_dependency(%q<standalone_migrations>.freeze, [">= 0"])
|
78
|
+
s.add_development_dependency(%q<timecop>.freeze, [">= 0"])
|
79
|
+
s.add_development_dependency(%q<paranoia>.freeze, [">= 0"])
|
80
|
+
s.add_development_dependency(%q<rdoc>.freeze, ["~> 3.12"])
|
81
|
+
s.add_development_dependency(%q<bundler>.freeze, ["~> 1.0"])
|
82
|
+
s.add_development_dependency(%q<jeweler>.freeze, [">= 0"])
|
83
|
+
s.add_development_dependency(%q<simplecov>.freeze, [">= 0"])
|
99
84
|
else
|
100
|
-
s.add_dependency(%q<activerecord>.freeze, ["
|
85
|
+
s.add_dependency(%q<activerecord>.freeze, [">= 5"])
|
101
86
|
s.add_dependency(%q<activesupport>.freeze, [">= 0"])
|
102
87
|
s.add_dependency(%q<rollbar>.freeze, [">= 0"])
|
103
88
|
s.add_dependency(%q<activerecord-import>.freeze, [">= 0"])
|
104
89
|
s.add_dependency(%q<pg>.freeze, [">= 0"])
|
105
90
|
s.add_dependency(%q<pry>.freeze, [">= 0"])
|
106
|
-
s.add_dependency(%q<mysql2>.freeze, ["= 0.
|
91
|
+
s.add_dependency(%q<mysql2>.freeze, ["= 0.5"])
|
107
92
|
s.add_dependency(%q<standalone_migrations>.freeze, [">= 0"])
|
108
93
|
s.add_dependency(%q<timecop>.freeze, [">= 0"])
|
109
94
|
s.add_dependency(%q<paranoia>.freeze, [">= 0"])
|
@@ -16,15 +16,17 @@ module Historiographer
|
|
16
16
|
# Will automatically add user_id, history_started_at,
|
17
17
|
# and history_ended_at columns
|
18
18
|
#
|
19
|
-
def histories(except: [], only: [], no_business_columns: false)
|
20
|
-
|
21
|
-
|
19
|
+
def histories(except: [], only: [], no_business_columns: false, index_names: {})
|
20
|
+
index_names.symbolize_keys!
|
21
|
+
|
22
|
+
original_table_name = self.name.gsub(/_histories$/) { }.pluralize
|
23
|
+
foreign_key = original_table_name.singularize.foreign_key
|
22
24
|
|
23
25
|
class_definer = Class.new(ActiveRecord::Base) do
|
24
26
|
end
|
25
27
|
|
26
28
|
class_name = original_table_name.classify
|
27
|
-
klass
|
29
|
+
klass = Object.const_set(class_name, class_definer)
|
28
30
|
original_columns = klass.columns.reject { |c| c.name == "id" || except.include?(c.name) || (only.any? && only.exclude?(c.name)) || no_business_columns }
|
29
31
|
|
30
32
|
integer foreign_key.to_sym, null: false
|
@@ -48,7 +50,6 @@ module Historiographer
|
|
48
50
|
ActiveRecord::Base.connection.indexes(original_table_name).each do |index|
|
49
51
|
index index.columns
|
50
52
|
end
|
51
|
-
|
52
53
|
end
|
53
54
|
end
|
54
55
|
end
|
data/lib/historiographer/safe.rb
CHANGED
data/lib/historiographer.rb
CHANGED
@@ -91,7 +91,10 @@ module Historiographer
|
|
91
91
|
end
|
92
92
|
|
93
93
|
alias_method :destroy_without_history, :destroy
|
94
|
-
|
94
|
+
|
95
|
+
def destroy_with_history(history_user_id: nil)
|
96
|
+
history_user_absent_action if history_user_id.nil?
|
97
|
+
|
95
98
|
current_history = histories.where(history_ended_at: nil).order("id desc").limit(1).last
|
96
99
|
current_history.update!(history_ended_at: UTC.now) if current_history.present?
|
97
100
|
|
@@ -104,6 +107,7 @@ module Historiographer
|
|
104
107
|
@no_history = false
|
105
108
|
end
|
106
109
|
end
|
110
|
+
|
107
111
|
alias_method :destroy, :destroy_with_history
|
108
112
|
|
109
113
|
def assign_attributes(new_attributes)
|
@@ -111,7 +115,7 @@ module Historiographer
|
|
111
115
|
|
112
116
|
if huid.present?
|
113
117
|
self.class.nested_attributes_options.each do |association, _|
|
114
|
-
reflection
|
118
|
+
reflection = self.class.reflect_on_association(association)
|
115
119
|
assoc_attrs = new_attributes["#{association}_attributes"]
|
116
120
|
|
117
121
|
if assoc_attrs.present?
|
@@ -132,11 +136,12 @@ module Historiographer
|
|
132
136
|
def historiographer_changes?
|
133
137
|
case Rails.version.to_f
|
134
138
|
when 0..5 then changed? && valid?
|
135
|
-
when 5.1..
|
139
|
+
when 5.1..7 then saved_changes?
|
136
140
|
else
|
137
141
|
raise "Unsupported Rails version"
|
138
142
|
end
|
139
143
|
end
|
144
|
+
|
140
145
|
#
|
141
146
|
# If there are any changes, and the model is valid,
|
142
147
|
# and we're not force-overriding history recording,
|
@@ -193,6 +198,7 @@ module Historiographer
|
|
193
198
|
end
|
194
199
|
end
|
195
200
|
end
|
201
|
+
|
196
202
|
base.send(:prepend, UpdateColumnsWithHistory)
|
197
203
|
|
198
204
|
def save_without_history(*args, &block)
|
@@ -222,9 +228,9 @@ module Historiographer
|
|
222
228
|
def record_history
|
223
229
|
history_user_absent_action if history_user_id.nil?
|
224
230
|
|
225
|
-
attrs
|
231
|
+
attrs = attributes.clone
|
226
232
|
history_class = self.class.history_class
|
227
|
-
foreign_key
|
233
|
+
foreign_key = history_class.history_foreign_key
|
228
234
|
|
229
235
|
now = UTC.now
|
230
236
|
attrs.merge!(foreign_key => attrs["id"], history_started_at: now, history_user_id: history_user_id)
|
data/spec/db/database.yml
CHANGED
@@ -1,14 +1,13 @@
|
|
1
|
-
|
1
|
+
development:
|
2
2
|
adapter: postgresql
|
3
3
|
prepared_statements: false
|
4
4
|
url: "postgres://localhost/historiographer_development"
|
5
5
|
|
6
|
-
development:
|
7
|
-
<<: *default
|
8
|
-
|
9
6
|
test:
|
10
7
|
adapter: postgresql
|
11
8
|
database: historiographer_test
|
9
|
+
url: "postgres://localhost/historiographer_test"
|
10
|
+
|
12
11
|
# mysql_default: &mysql_default
|
13
12
|
# adapter: mysql2
|
14
13
|
# encoding: utf8
|
data/spec/db/schema.rb
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
# of editing this file, please use the migrations feature of Active Record to
|
3
3
|
# incrementally modify your database, and then regenerate this schema definition.
|
4
4
|
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
# from scratch.
|
9
|
-
#
|
5
|
+
# This file is the source Rails uses to define your schema when running `bin/rails
|
6
|
+
# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
|
7
|
+
# be faster and is potentially less error prone than running all of your
|
8
|
+
# migrations from scratch. Old migrations may fail to apply correctly if those
|
9
|
+
# migrations use external dependencies or application code.
|
10
10
|
#
|
11
11
|
# It's strongly recommended that you check this file into your version control system.
|
12
12
|
|
data/spec/examples.txt
CHANGED
@@ -1,21 +1,29 @@
|
|
1
|
-
example_id
|
2
|
-
|
3
|
-
./spec/historiographer_spec.rb[1:1:1]
|
4
|
-
./spec/historiographer_spec.rb[1:1:2]
|
5
|
-
./spec/historiographer_spec.rb[1:1:3]
|
6
|
-
./spec/historiographer_spec.rb[1:2:1]
|
7
|
-
./spec/historiographer_spec.rb[1:2:2]
|
8
|
-
./spec/historiographer_spec.rb[1:2:3:1] | passed | 0.
|
9
|
-
./spec/historiographer_spec.rb[1:2:3:2] | passed | 0.
|
10
|
-
./spec/historiographer_spec.rb[1:2:3:
|
11
|
-
./spec/historiographer_spec.rb[1:2:
|
12
|
-
./spec/historiographer_spec.rb[1:2:
|
13
|
-
./spec/historiographer_spec.rb[1:2:
|
14
|
-
./spec/historiographer_spec.rb[1:3:
|
15
|
-
./spec/historiographer_spec.rb[1:4:1] | passed | 0.
|
16
|
-
./spec/historiographer_spec.rb[1:
|
17
|
-
./spec/historiographer_spec.rb[1:
|
18
|
-
./spec/historiographer_spec.rb[1:
|
19
|
-
./spec/historiographer_spec.rb[1:
|
20
|
-
./spec/historiographer_spec.rb[1:7
|
21
|
-
./spec/historiographer_spec.rb[1:
|
1
|
+
example_id | status | run_time |
|
2
|
+
----------------------------------------- | ------ | --------------- |
|
3
|
+
./spec/historiographer_spec.rb[1:1:1] | passed | 0.00973 seconds |
|
4
|
+
./spec/historiographer_spec.rb[1:1:2] | passed | 0.01848 seconds |
|
5
|
+
./spec/historiographer_spec.rb[1:1:3] | passed | 0.0092 seconds |
|
6
|
+
./spec/historiographer_spec.rb[1:2:1] | passed | 0.02492 seconds |
|
7
|
+
./spec/historiographer_spec.rb[1:2:2] | passed | 0.00099 seconds |
|
8
|
+
./spec/historiographer_spec.rb[1:2:3:1:1] | passed | 0.13892 seconds |
|
9
|
+
./spec/historiographer_spec.rb[1:2:3:1:2] | passed | 0.1202 seconds |
|
10
|
+
./spec/historiographer_spec.rb[1:2:3:2:1] | passed | 0.02734 seconds |
|
11
|
+
./spec/historiographer_spec.rb[1:2:3:2:2] | passed | 0.04699 seconds |
|
12
|
+
./spec/historiographer_spec.rb[1:2:3:2:3] | passed | 0.02185 seconds |
|
13
|
+
./spec/historiographer_spec.rb[1:2:3:3:1] | passed | 0.08042 seconds |
|
14
|
+
./spec/historiographer_spec.rb[1:2:3:3:2] | passed | 0.02825 seconds |
|
15
|
+
./spec/historiographer_spec.rb[1:2:4:1] | passed | 0.02411 seconds |
|
16
|
+
./spec/historiographer_spec.rb[1:2:4:2] | passed | 0.01286 seconds |
|
17
|
+
./spec/historiographer_spec.rb[1:2:4:3] | passed | 0.00469 seconds |
|
18
|
+
./spec/historiographer_spec.rb[1:2:5] | passed | 0.00478 seconds |
|
19
|
+
./spec/historiographer_spec.rb[1:2:6] | passed | 0.0035 seconds |
|
20
|
+
./spec/historiographer_spec.rb[1:2:7] | passed | 0.01157 seconds |
|
21
|
+
./spec/historiographer_spec.rb[1:3:1] | passed | 0.09042 seconds |
|
22
|
+
./spec/historiographer_spec.rb[1:4:1] | passed | 0.05553 seconds |
|
23
|
+
./spec/historiographer_spec.rb[1:5:1] | passed | 0.0104 seconds |
|
24
|
+
./spec/historiographer_spec.rb[1:5:2] | passed | 0.00905 seconds |
|
25
|
+
./spec/historiographer_spec.rb[1:6:1] | passed | 0.02652 seconds |
|
26
|
+
./spec/historiographer_spec.rb[1:6:2] | passed | 0.04419 seconds |
|
27
|
+
./spec/historiographer_spec.rb[1:7:1] | passed | 0.02102 seconds |
|
28
|
+
./spec/historiographer_spec.rb[1:8:1] | passed | 0.02556 seconds |
|
29
|
+
./spec/historiographer_spec.rb[1:9:1] | passed | 0.01444 seconds |
|
@@ -10,6 +10,7 @@ end
|
|
10
10
|
|
11
11
|
class SafePost < ActiveRecord::Base
|
12
12
|
include Historiographer::Safe
|
13
|
+
acts_as_paranoid
|
13
14
|
end
|
14
15
|
|
15
16
|
class SafePostHistory < ActiveRecord::Base
|
@@ -445,6 +446,30 @@ describe Historiographer do
|
|
445
446
|
expect(PostHistory.where.not(deleted_at: nil).count).to eq 1
|
446
447
|
expect(PostHistory.last.history_user_id).to eq 2
|
447
448
|
end
|
449
|
+
|
450
|
+
it "works with Historiographer::Safe" do
|
451
|
+
post = SafePost.create(title: "HELLO", body: "YO", author_id: 1)
|
452
|
+
|
453
|
+
expect {
|
454
|
+
post.destroy
|
455
|
+
}.to_not raise_error
|
456
|
+
|
457
|
+
expect(SafePost.count).to eq 0
|
458
|
+
expect(post.deleted_at).to_not be_nil
|
459
|
+
expect(SafePostHistory.count).to eq 2
|
460
|
+
expect(SafePostHistory.current.last.deleted_at).to eq post.deleted_at
|
461
|
+
|
462
|
+
post2 = SafePost.create(title: "HELLO", body: "YO", author_id: 1)
|
463
|
+
|
464
|
+
expect {
|
465
|
+
post2.destroy!
|
466
|
+
}.to_not raise_error
|
467
|
+
|
468
|
+
expect(SafePost.count).to eq 0
|
469
|
+
expect(post2.deleted_at).to_not be_nil
|
470
|
+
expect(SafePostHistory.count).to eq 4
|
471
|
+
expect(SafePostHistory.current.where(safe_post_id: post2.id).last.deleted_at).to eq post2.deleted_at
|
472
|
+
end
|
448
473
|
end
|
449
474
|
|
450
475
|
describe "Scopes" do
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: historiographer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- brettshollenberger
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-02-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '5
|
19
|
+
version: '5'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '5
|
26
|
+
version: '5'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activesupport
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -100,14 +100,14 @@ dependencies:
|
|
100
100
|
requirements:
|
101
101
|
- - '='
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: 0.
|
103
|
+
version: '0.5'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - '='
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: 0.
|
110
|
+
version: '0.5'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: standalone_migrations
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -255,7 +255,7 @@ homepage: http://github.com/brettshollenberger/historiographer
|
|
255
255
|
licenses:
|
256
256
|
- MIT
|
257
257
|
metadata: {}
|
258
|
-
post_install_message:
|
258
|
+
post_install_message:
|
259
259
|
rdoc_options: []
|
260
260
|
require_paths:
|
261
261
|
- lib
|
@@ -270,8 +270,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
270
270
|
- !ruby/object:Gem::Version
|
271
271
|
version: '0'
|
272
272
|
requirements: []
|
273
|
-
rubygems_version: 3.
|
274
|
-
signing_key:
|
273
|
+
rubygems_version: 3.2.23
|
274
|
+
signing_key:
|
275
275
|
specification_version: 4
|
276
276
|
summary: Create histories of your ActiveRecord tables
|
277
277
|
test_files: []
|