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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a4f6546810d969fb905818b357aff6f3130a85e80cc1bc3037f5fb885660856e
4
- data.tar.gz: e3e2167bdb2104ef7f2a56f9381e16b7648dc800b25785094a5ca3825277d980
3
+ metadata.gz: d3769a9624f0d50658cde81f3275a273cc026ae4a5c19b37fdc86031727df2b1
4
+ data.tar.gz: 64c02f0431cc68a44149f64088dec31b2fee7c0e78ddfdb51e36ecb85f546f5b
5
5
  SHA512:
6
- metadata.gz: fa67585d54cbfa598729a139b36b788f0f0cf7ca5e7bccdd6ac82a660f000467b56f8ac97c07fa967028a4f501397fa0901af9de309eb03f184afd029c0dbed7
7
- data.tar.gz: 719e681acf4ae6f07a3de41fc7c7cbb3b7296e18d821a88bef7b82f62b618e0e4e64059672e20a2b60a60c834db69f45afec9df239b97d4068c7ded887a685bc
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, :temporal => true do |t|
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
- attr_accessible :name
55
- belongs_to :coven
54
+ belongs_to :coven, optional: true
56
55
  has_many :warts
57
56
 
58
- def label
59
- "#{name} from #{coven.name}"
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.name}")
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.label #=> "Grunthilda from Delta Gamma Gamma"
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. Defaults to schema_migrations and sessions 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 field to all temporal tables to track who made any changes. Defaults to a :string field. The block is called when records are saved to determine the value to place within the updated_by field.
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.try(:id) }
143
+ TemporalTables.add_updated_by_field(:integer) { User.current_user&.id }
136
144
  ```
137
145
 
138
146
  ## Copyright
@@ -1,3 +1,3 @@
1
1
  module TemporalTables
2
- VERSION = "0.6.2"
2
+ VERSION = "0.6.3"
3
3
  end
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: temporal_tables
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ version: 0.6.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brent Kroeker