active_snapshot 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -1
- data/README.md +8 -8
- data/lib/active_snapshot/models/concerns/snapshots_concern.rb +6 -4
- data/lib/active_snapshot/version.rb +1 -1
- data/lib/active_snapshot.rb +0 -2
- data/lib/generators/active_snapshot/install/templates/create_snapshots_tables.rb.erb +9 -2
- metadata +6 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5b48af4ad66af3d9fe9110f544df49f29ec6586969cb7e2c7f62431b54163a84
|
4
|
+
data.tar.gz: fddc58303f066d5b77b56304c4367874e2b3dda0ea2e76e710d81a0f1705861e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a769fccb45b11f7163384b6ee79e5ff056b897cb3f382bb48054eaf9e20dba87371ab6b42da4ac117eafd136ebdc5d2dcd3441c7cf3a397ea087ec481dbc61d
|
7
|
+
data.tar.gz: 2ca41b8874d1511596e25893ddb9b0b05daeead16a12150ff25b1812b1dd3f2901fdcad501ece2681b4a96161e8909e5fd475d52e8c7eda72d74e83804b38574
|
data/CHANGELOG.md
CHANGED
@@ -2,9 +2,17 @@ CHANGELOG
|
|
2
2
|
---------
|
3
3
|
|
4
4
|
- **Unreleased**
|
5
|
-
* [View Diff](https://github.com/westonganger/active_snapshot/compare/v0.
|
5
|
+
* [View Diff](https://github.com/westonganger/active_snapshot/compare/v0.4.0...master)
|
6
6
|
* Nothing yet
|
7
7
|
|
8
|
+
- **v0.4.0** - July 23, 2024
|
9
|
+
* [View Diff](https://github.com/westonganger/active_snapshot/compare/v0.3.2...v0.4.0)
|
10
|
+
* [#44](https://github.com/westonganger/active_snapshot/pull/44) - Remove dependency on activerecord-import with vanilla ActiveRecord upsert_all
|
11
|
+
|
12
|
+
- **v0.3.2** - Oct 17, 2023
|
13
|
+
* [View Diff](https://github.com/westonganger/active_snapshot/compare/v0.3.1...v0.3.2)
|
14
|
+
* [#43](https://github.com/westonganger/active_snapshot/pull/43) - Fix unique index error in generated DB migration
|
15
|
+
|
8
16
|
- **v0.3.1** - August 4, 2023
|
9
17
|
* [View Diff](https://github.com/westonganger/active_snapshot/compare/v0.3.0...v0.3.1)
|
10
18
|
* [#36](https://github.com/westonganger/active_snapshot/pull/36) - Allow ActiveRecord to be lazy loaded using `ActiveSupport.on_load`
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# ActiveSnapshot
|
2
2
|
|
3
3
|
<a href="https://badge.fury.io/rb/active_snapshot" target="_blank"><img height="21" style='border:0px;height:21px;' border='0' src="https://badge.fury.io/rb/active_snapshot.svg" alt="Gem Version"></a>
|
4
|
-
<a href='https://github.com/westonganger/active_snapshot/actions' target='_blank'><img src="https://github.com/westonganger/active_snapshot/workflows/
|
4
|
+
<a href='https://github.com/westonganger/active_snapshot/actions' target='_blank'><img src="https://github.com/westonganger/active_snapshot/actions/workflows/test.yml/badge.svg?branch=master" style="max-width:100%;" height='21' style='border:0px;height:21px;' border='0' alt="CI Status"></a>
|
5
5
|
<a href='https://rubygems.org/gems/active_snapshot' target='_blank'><img height='21' style='border:0px;height:21px;' src='https://img.shields.io/gem/dt/active_snapshot?color=brightgreen&label=Rubygems%20Downloads' border='0' alt='RubyGems Downloads' /></a>
|
6
6
|
|
7
7
|
Simplified snapshots and restoration for ActiveRecord models and associations with a transparent white-box implementation.
|
@@ -101,24 +101,24 @@ snapshot.destroy!
|
|
101
101
|
```ruby
|
102
102
|
class Post < ActiveRecord::Base
|
103
103
|
include ActiveSnapshot
|
104
|
-
|
104
|
+
|
105
105
|
has_snapshot_children do
|
106
106
|
### Executed in the context of the instance / self
|
107
107
|
|
108
108
|
### Reload record from database to ensure a clean state and eager load the specified associations
|
109
109
|
instance = self.class.includes(:tags, :ip_address, comments: [:comment_sub_records]).find(id)
|
110
|
-
|
110
|
+
|
111
111
|
### Define the associated records that will be restored
|
112
112
|
{
|
113
113
|
comments: instance.comments,
|
114
|
-
|
114
|
+
|
115
115
|
### Nested Associations can be handled by simply mapping them into an array
|
116
|
-
comment_sub_records: instance.comments.flat_map{|x| x.comment_sub_records },
|
117
|
-
|
116
|
+
comment_sub_records: instance.comments.flat_map{|x| x.comment_sub_records },
|
117
|
+
|
118
118
|
tags: {
|
119
119
|
records: instance.tags
|
120
120
|
},
|
121
|
-
|
121
|
+
|
122
122
|
ip_address: {
|
123
123
|
record: instance.ip_address,
|
124
124
|
delete_method: ->(item){ item.release! }
|
@@ -133,7 +133,7 @@ Now when you run `create_snapshot!` the associations will be tracked accordingly
|
|
133
133
|
|
134
134
|
# Reifying Snapshot Items
|
135
135
|
|
136
|
-
You can view all of the reified snapshot items by calling the following method. Its completely up to you on how to use this data.
|
136
|
+
You can view all of the reified snapshot items by calling the following method. Its completely up to you on how to use this data.
|
137
137
|
|
138
138
|
```ruby
|
139
139
|
reified_parent, reified_children_hash = snapshot.fetch_reified_items
|
@@ -22,21 +22,23 @@ module ActiveSnapshot
|
|
22
22
|
metadata: (metadata || {}),
|
23
23
|
})
|
24
24
|
|
25
|
-
|
25
|
+
new_entries = []
|
26
26
|
|
27
|
-
|
27
|
+
current_time = Time.now
|
28
|
+
|
29
|
+
new_entries << snapshot.build_snapshot_item(self).attributes.merge(created_at: current_time)
|
28
30
|
|
29
31
|
snapshot_children = self.children_to_snapshot
|
30
32
|
|
31
33
|
if snapshot_children
|
32
34
|
snapshot_children.each do |child_group_name, h|
|
33
35
|
h[:records].each do |child_item|
|
34
|
-
|
36
|
+
new_entries << snapshot.build_snapshot_item(child_item, child_group_name: child_group_name).attributes.merge(created_at: current_time)
|
35
37
|
end
|
36
38
|
end
|
37
39
|
end
|
38
40
|
|
39
|
-
SnapshotItem.
|
41
|
+
SnapshotItem.upsert_all(new_entries.map{|x| x.delete("id"); x }, returning: false)
|
40
42
|
|
41
43
|
snapshot
|
42
44
|
end
|
data/lib/active_snapshot.rb
CHANGED
@@ -3,16 +3,23 @@ class <%= migration_name %> < ActiveRecord::Migration::Current
|
|
3
3
|
def change
|
4
4
|
create_table :snapshots<%= table_options %> do |t|
|
5
5
|
t.belongs_to :item, polymorphic: true, null: false, index: true
|
6
|
-
t.string :identifier, unique: [:item_id, :item_type], index: true
|
7
6
|
t.belongs_to :user, polymorphic: true
|
7
|
+
|
8
|
+
t.string :identifier, index: true
|
9
|
+
t.index [:identifier, :item_id, :item_type], unique: true
|
10
|
+
|
8
11
|
t.<%= ActiveSnapshot.config.storage_method == 'native_json' ? 'json' : 'text' %> :metadata
|
12
|
+
|
9
13
|
t.datetime :created_at, null: false
|
10
14
|
end
|
11
15
|
|
12
16
|
create_table :snapshot_items<%= table_options %> do |t|
|
13
17
|
t.belongs_to :snapshot, null: false, index: true
|
14
|
-
t.belongs_to :item, polymorphic: true, null: false,
|
18
|
+
t.belongs_to :item, polymorphic: true, null: false, index: true
|
19
|
+
t.index [:snapshot_id, :item_id, :item_type], unique: true
|
20
|
+
|
15
21
|
t.<%= ActiveSnapshot.config.storage_method == 'native_json' ? 'json' : 'text' %> :object, null: false
|
22
|
+
|
16
23
|
t.datetime :created_at, null: false
|
17
24
|
t.string :child_group_name
|
18
25
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_snapshot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Weston Ganger
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-07-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
19
|
+
version: '6.0'
|
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: '0'
|
26
|
+
version: '6.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: railties
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -38,20 +38,6 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: activerecord-import
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
|
-
type: :runtime
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
41
|
- !ruby/object:Gem::Dependency
|
56
42
|
name: rake
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -170,14 +156,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
170
156
|
requirements:
|
171
157
|
- - ">="
|
172
158
|
- !ruby/object:Gem::Version
|
173
|
-
version:
|
159
|
+
version: '0'
|
174
160
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
175
161
|
requirements:
|
176
162
|
- - ">="
|
177
163
|
- !ruby/object:Gem::Version
|
178
164
|
version: '0'
|
179
165
|
requirements: []
|
180
|
-
rubygems_version: 3.4.
|
166
|
+
rubygems_version: 3.4.22
|
181
167
|
signing_key:
|
182
168
|
specification_version: 4
|
183
169
|
summary: Dead simple snapshot versioning for ActiveRecord models and associations.
|