temporal_tables 0.6.2 → 0.6.3
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/README.md +23 -15
- data/lib/temporal_tables/version.rb +1 -1
- data/lib/temporal_tables.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d3769a9624f0d50658cde81f3275a273cc026ae4a5c19b37fdc86031727df2b1
|
4
|
+
data.tar.gz: 64c02f0431cc68a44149f64088dec31b2fee7c0e78ddfdb51e36ecb85f546f5b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c64cc0fa0c02b4f7c622e1e1fa3b94c1701525720586a56e864fc7b4ada9744cc278defd276dea5dcdb6f1a98b673e7af1816661584eec82ebe1f5832818393
|
7
|
+
data.tar.gz: 59e1cd19d8ea5c12c5afd890093dab74c98c7fc1a34203e84a3021d07fa325fb5ec913de0daf96beb9a87d442f1c28fdf2f01a87c7d4bd3f96c87925e3061482
|
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.4, Rails 5.2, Postgres, MySQL
|
5
|
+
Currently tested on Ruby 2.4, Rails 5.2, Postgres 10.3, MySQL 8.0.11
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
@@ -27,7 +27,7 @@ $ gem install temporal_tables
|
|
27
27
|
|
28
28
|
In your rails migration, specify that you want a table to have its history tracked:
|
29
29
|
``` ruby
|
30
|
-
create_table :people, :
|
30
|
+
create_table :people, temporal: true do |t|
|
31
31
|
...
|
32
32
|
end
|
33
33
|
```
|
@@ -51,25 +51,32 @@ add_temporal_table :people
|
|
51
51
|
For the below queries, we'll assume the following schema:
|
52
52
|
``` ruby
|
53
53
|
class Person < ActiveRecord::Base
|
54
|
-
|
55
|
-
belongs_to :coven
|
54
|
+
belongs_to :coven, optional: true
|
56
55
|
has_many :warts
|
57
56
|
|
58
|
-
def
|
59
|
-
|
57
|
+
def to_s
|
58
|
+
parts = [name]
|
59
|
+
parts << "from #{coven.name}" if coven
|
60
|
+
parts.join ' '
|
60
61
|
end
|
61
62
|
end
|
62
63
|
|
63
64
|
class Coven < ActiveRecord::Base
|
64
|
-
attr_accessible :name
|
65
65
|
has_many :members, class_name: "Person"
|
66
|
+
|
67
|
+
def to_s
|
68
|
+
name
|
69
|
+
end
|
66
70
|
end
|
67
71
|
|
68
72
|
class Wart < ActiveRecord::Base
|
69
|
-
attr_accessible :location
|
70
73
|
belongs_to :person
|
71
74
|
|
72
75
|
scope :very_hairy, -> { where(arel_table[:num_hairs].gteq(3)) }
|
76
|
+
|
77
|
+
def to_s
|
78
|
+
"wart on #{location} with #{pluralize num_hairs, 'hair'}"
|
79
|
+
end
|
73
80
|
end
|
74
81
|
```
|
75
82
|
|
@@ -81,10 +88,10 @@ Person.history #=> PersonHistory(history_id: :integer, id: :integer, name: :stri
|
|
81
88
|
|
82
89
|
You can easily get a history of all changes to a records.
|
83
90
|
``` ruby
|
84
|
-
Person.history.where(id: 1).map { |p| "#{p.eff_from}: #{p.
|
91
|
+
Person.history.where(id: 1).map { |p| "#{p.eff_from}: #{p.to_s}")
|
85
92
|
# => [
|
86
93
|
# "1974-01-14: Emily",
|
87
|
-
# "2003-11-03: Grunthilda"
|
94
|
+
# "2003-11-03: Grunthilda from Delta Gamma Gamma"
|
88
95
|
# ]
|
89
96
|
```
|
90
97
|
|
@@ -113,26 +120,27 @@ grunthilda.warts.very_hairy.count #=> 7
|
|
113
120
|
|
114
121
|
Instance methods are inherited.
|
115
122
|
``` ruby
|
116
|
-
grunthilda.
|
123
|
+
grunthilda.to_s #=> "Grunthilda from Delta Gamma Gamma"
|
117
124
|
grunthilda.class.name #=> "PersonHistory"
|
118
125
|
grunthilda.class.superclass.name #=> "Person"
|
119
126
|
```
|
120
127
|
|
121
128
|
## Config
|
129
|
+
You can configure temporal_tables in an initializer.
|
122
130
|
|
123
|
-
Create temporal tables for all tables by default
|
131
|
+
Create temporal tables for all tables by default (default = false)
|
124
132
|
``` ruby
|
125
133
|
TemporalTables.create_by_default = true
|
126
134
|
```
|
127
135
|
|
128
|
-
Don't create temporal tables for these tables.
|
136
|
+
Don't create temporal tables for these tables. (default = %w{schema_migrations sessions ar_internal_metadata})
|
129
137
|
``` ruby
|
130
138
|
TemporalTables.skip_temporal_table_for :table_one, :table_two
|
131
139
|
```
|
132
140
|
|
133
|
-
Add an updated_by
|
141
|
+
Add an `updated_by` column to all temporal tables to track who made any changes, which is quite useful for auditing. Defaults to a :string field. The block is called when records are saved to determine the value to place within the `updated_by` field. `updated_by` fields are only auto-created if this is configured.
|
134
142
|
``` ruby
|
135
|
-
TemporalTables.add_updated_by_field(:integer) { User.current_user
|
143
|
+
TemporalTables.add_updated_by_field(:integer) { User.current_user&.id }
|
136
144
|
```
|
137
145
|
|
138
146
|
## Copyright
|
data/lib/temporal_tables.rb
CHANGED
@@ -34,7 +34,7 @@ module TemporalTables
|
|
34
34
|
@@create_by_default = default
|
35
35
|
end
|
36
36
|
|
37
|
-
@@skipped_temporal_tables = [:schema_migrations, :sessions]
|
37
|
+
@@skipped_temporal_tables = [:schema_migrations, :sessions, :ar_internal_metadata]
|
38
38
|
def self.skip_temporal_table_for(*tables)
|
39
39
|
@@skipped_temporal_tables += tables
|
40
40
|
end
|