active_snapshot 0.5.1 → 1.0.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 +12 -3
- data/README.md +0 -19
- data/lib/active_snapshot/config.rb +21 -9
- data/lib/active_snapshot/models/snapshot.rb +8 -4
- data/lib/active_snapshot/models/snapshot_item.rb +8 -6
- data/lib/active_snapshot/version.rb +1 -1
- data/lib/generators/active_snapshot/install/templates/create_snapshots_tables.rb.erb +2 -2
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 214cb14c7afa97c56711b7aaf4d0ed4c3001ba995578de0187432a6951ee8a80
|
4
|
+
data.tar.gz: 72798e3577020e343768f3ba79cb93adb9c97f8636e3dd869eb6443683e2d2b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 330a15dd3e253a01b366445442d4b3164b24bb2e557a7a3ed660459314deec0f847fdfdde0fc945ea9b6093943baf73b757e7faf8848f6b8695846a598b322f4
|
7
|
+
data.tar.gz: f75841865ec536b0f9aaf2ead65260a8efefd7ffe6062928b8de1095e9d35ce2be97bff4f52e2f0fa52aa764d515ac2b12f33659e6c4089f6f1cf21c231f7e12
|
data/CHANGELOG.md
CHANGED
@@ -2,9 +2,18 @@ CHANGELOG
|
|
2
2
|
---------
|
3
3
|
|
4
4
|
- **Unreleased**
|
5
|
-
* [View Diff](https://github.com/westonganger/active_snapshot/compare/
|
5
|
+
* [View Diff](https://github.com/westonganger/active_snapshot/compare/v1.0.0...master)
|
6
6
|
* Nothing yet
|
7
7
|
|
8
|
+
- **v1.0.0** - Jan 17 2025
|
9
|
+
* [View Diff](https://github.com/westonganger/active_snapshot/compare/v0.5.2...v1.0.0)
|
10
|
+
* There are no functional changes. This release v1.0.0 is to signal that its stable and ready for widespread usage.
|
11
|
+
|
12
|
+
- **v0.5.2** - Nov 11, 2024
|
13
|
+
* [View Diff](https://github.com/westonganger/active_snapshot/compare/v0.5.1...v0.5.2)
|
14
|
+
* [#67](https://github.com/westonganger/active_snapshot/pull/67) - Switch default storage method to native SQL JSON columns. No longer recommend to set `ActiveSnapshot.config.storage_method`, this configuration option is only retained to support legacy installations which utilize serialized YAML or serialized JSON text columns. The default storage method will fallback gracefully for legacy installations, if there already exists a text column then it defaults to `ActiveSnapshot.config.storage_method = "serialized_json"`
|
15
|
+
* Drop support for Rails 6.0. Rails 6.1 is minimum required version now.
|
16
|
+
|
8
17
|
- **v0.5.1** - Nov 11, 2024
|
9
18
|
* [View Diff](https://github.com/westonganger/active_snapshot/compare/v0.5.0...v0.5.1)
|
10
19
|
* [#66](https://github.com/westonganger/active_snapshot/pull/66) - Ensure `SnapshotItem#restore_item!` and `Snapshot#fetch_reified_items` bypass assignment for snapshot object data where the associated column no longer exists.
|
@@ -42,9 +51,9 @@ CHANGELOG
|
|
42
51
|
* [PR #32](https://github.com/westonganger/active_snapshot/pull/32) - Change default storage method from `serialized_yaml` to `serialized_json`.
|
43
52
|
* [PR #32](https://github.com/westonganger/active_snapshot/pull/32) - `snapshot.metadata` and `snapshot_item.object` no longer return a HashWithIndifferentAccess. Now they simply return a regular Hash.
|
44
53
|
* **Upgrade Instructions**
|
45
|
-
* Change all instances of `create_snapshot!("my-snapshot-1"` to `create_snapshot!(identifier: "my-snapshot-1"`
|
54
|
+
* Change all instances of `create_snapshot!("my-snapshot-1"` to `create_snapshot!(identifier: "my-snapshot-1")`
|
46
55
|
* Create a migration with the following `change_column_null :snapshots, :identifier, true` to remove the null constraint here
|
47
|
-
* If you have existing snapshots from a previous version then please set `ActiveSnapshot.config.storage_method = "serialized_yaml"`
|
56
|
+
* If you have existing snapshots from a previous version then please set `ActiveSnapshot.config.storage_method = "serialized_yaml"` in an initializer
|
48
57
|
|
49
58
|
- **v0.2.4** - Feb 25, 2022
|
50
59
|
* [View Diff](https://github.com/westonganger/active_snapshot/compare/v0.2.3...v0.2.4)
|
data/README.md
CHANGED
@@ -53,25 +53,6 @@ It defines an optional extension to your model: `has_snapshot_children`.
|
|
53
53
|
|
54
54
|
It defines one instance method to your model: `create_snapshot!`
|
55
55
|
|
56
|
-
# Using a different storage format
|
57
|
-
|
58
|
-
By default ActiveSnapshot encodes objects to JSON and stores in the database as plain text. If you prefer to have YAML encoded columns or native JSON DB columns you can configure this as follows:
|
59
|
-
|
60
|
-
```ruby
|
61
|
-
ActiveSnapshot.config do |config|
|
62
|
-
config.storage_method = "serialized_json" # default, for text column
|
63
|
-
#config.storage_method = "serialized_yaml" # for text column
|
64
|
-
#config.storage_method = "native_json" # for json/jsonb column
|
65
|
-
end
|
66
|
-
```
|
67
|
-
|
68
|
-
If using a native json column, you should configure the `storage_method` before generating the migration. If this step was missed then you would need to create a migration to change the `:object` and `:metadata` columns to json (or jsonb)
|
69
|
-
|
70
|
-
```ruby
|
71
|
-
change_column :snapshots, :object, :json
|
72
|
-
change_column :snapshots, :metadata, :json
|
73
|
-
```
|
74
|
-
|
75
56
|
# Basic Usage
|
76
57
|
|
77
58
|
You now have access to the following methods:
|
@@ -1,12 +1,24 @@
|
|
1
1
|
module ActiveSnapshot
|
2
2
|
class Config
|
3
|
-
attr_reader :storage_method
|
4
|
-
|
5
3
|
def initialize
|
6
|
-
|
4
|
+
end
|
5
|
+
|
6
|
+
def storage_method
|
7
|
+
if @storage_method.nil?
|
8
|
+
if ActiveSnapshot::SnapshotItem.table_exists? && ActiveSnapshot::SnapshotItem.type_for_attribute(:object).type == :text
|
9
|
+
# for legacy active_snapshot configurations only
|
10
|
+
self.storage_method = 'serialized_json'
|
11
|
+
else
|
12
|
+
self.storage_method = 'native_json'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
@storage_method
|
7
17
|
end
|
8
18
|
|
9
19
|
def storage_method=(value)
|
20
|
+
# for legacy active_snapshot configurations only
|
21
|
+
|
10
22
|
value_str = value.to_s
|
11
23
|
|
12
24
|
if ['serialized_yaml', 'serialized_json', 'native_json'].include?(value_str)
|
@@ -17,15 +29,15 @@ module ActiveSnapshot
|
|
17
29
|
end
|
18
30
|
|
19
31
|
def storage_method_yaml?
|
20
|
-
|
32
|
+
# for legacy active_snapshot configurations only
|
33
|
+
storage_method == 'serialized_yaml'
|
21
34
|
end
|
22
35
|
|
23
|
-
def
|
24
|
-
|
36
|
+
def storage_method_serialized_json?
|
37
|
+
# for legacy active_snapshot configurations only
|
38
|
+
storage_method == 'serialized_json'
|
25
39
|
end
|
40
|
+
alias_method :storage_method_json?, :storage_method_serialized_json?
|
26
41
|
|
27
|
-
def storage_method_native_json?
|
28
|
-
@storage_method == 'native_json'
|
29
|
-
end
|
30
42
|
end
|
31
43
|
end
|
@@ -18,9 +18,11 @@ module ActiveSnapshot
|
|
18
18
|
def metadata
|
19
19
|
return @metadata if @metadata
|
20
20
|
|
21
|
-
if ActiveSnapshot.config.
|
21
|
+
if ActiveSnapshot.config.storage_method_serialized_json?
|
22
|
+
# for legacy active_snapshot configurations only
|
22
23
|
@metadata = JSON.parse(self[:metadata])
|
23
24
|
elsif ActiveSnapshot.config.storage_method_yaml?
|
25
|
+
# for legacy active_snapshot configurations only
|
24
26
|
yaml_method = "unsafe_load"
|
25
27
|
|
26
28
|
if !YAML.respond_to?("unsafe_load")
|
@@ -28,7 +30,7 @@ module ActiveSnapshot
|
|
28
30
|
end
|
29
31
|
|
30
32
|
@metadata = YAML.send(yaml_method, self[:metadata])
|
31
|
-
|
33
|
+
else
|
32
34
|
@metadata = self[:metadata]
|
33
35
|
end
|
34
36
|
end
|
@@ -36,11 +38,13 @@ module ActiveSnapshot
|
|
36
38
|
def metadata=(h)
|
37
39
|
@metadata = nil
|
38
40
|
|
39
|
-
if ActiveSnapshot.config.
|
41
|
+
if ActiveSnapshot.config.storage_method_serialized_json?
|
42
|
+
# for legacy active_snapshot configurations only
|
40
43
|
self[:metadata] = h.to_json
|
41
44
|
elsif ActiveSnapshot.config.storage_method_yaml?
|
45
|
+
# for legacy active_snapshot configurations only
|
42
46
|
self[:metadata] = YAML.dump(h)
|
43
|
-
|
47
|
+
else
|
44
48
|
self[:metadata] = h
|
45
49
|
end
|
46
50
|
end
|
@@ -17,27 +17,29 @@ module ActiveSnapshot
|
|
17
17
|
def object
|
18
18
|
return @object if @object
|
19
19
|
|
20
|
-
if ActiveSnapshot.config.
|
20
|
+
if ActiveSnapshot.config.storage_method_serialized_json?
|
21
|
+
# for legacy active_snapshot configurations only
|
21
22
|
@object = self[:object] ? JSON.parse(self[:object]) : {}
|
22
23
|
elsif ActiveSnapshot.config.storage_method_yaml?
|
24
|
+
# for legacy active_snapshot configurations only
|
23
25
|
yaml_method = YAML.respond_to?(:unsafe_load) ? :unsafe_load : :load
|
24
26
|
|
25
27
|
@object = self[:object] ? YAML.public_send(yaml_method, self[:object]) : {}
|
26
|
-
elsif ActiveSnapshot.config.storage_method_native_json?
|
27
|
-
@object = self[:object]
|
28
28
|
else
|
29
|
-
|
29
|
+
@object = self[:object]
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
33
|
def object=(h)
|
34
34
|
@object = nil
|
35
35
|
|
36
|
-
if ActiveSnapshot.config.
|
36
|
+
if ActiveSnapshot.config.storage_method_serialized_json?
|
37
|
+
# for legacy active_snapshot configurations only
|
37
38
|
self[:object] = h.to_json
|
38
39
|
elsif ActiveSnapshot.config.storage_method_yaml?
|
40
|
+
# for legacy active_snapshot configurations only
|
39
41
|
self[:object] = YAML.dump(h)
|
40
|
-
|
42
|
+
else
|
41
43
|
self[:object] = h
|
42
44
|
end
|
43
45
|
end
|
@@ -8,7 +8,7 @@ class <%= migration_name %> < ActiveRecord::Migration::Current
|
|
8
8
|
t.string :identifier, index: true
|
9
9
|
t.index [:identifier, :item_id, :item_type], unique: true
|
10
10
|
|
11
|
-
t
|
11
|
+
t.json :metadata
|
12
12
|
|
13
13
|
t.datetime :created_at, null: false
|
14
14
|
end
|
@@ -18,7 +18,7 @@ class <%= migration_name %> < ActiveRecord::Migration::Current
|
|
18
18
|
t.belongs_to :item, polymorphic: true, null: false, index: true
|
19
19
|
t.index [:snapshot_id, :item_id, :item_type], unique: true
|
20
20
|
|
21
|
-
t
|
21
|
+
t.json :object, null: false
|
22
22
|
|
23
23
|
t.datetime :created_at, null: false
|
24
24
|
t.string :child_group_name
|
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: 1.0.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: 2025-01-17 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: '6.
|
19
|
+
version: '6.1'
|
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: '6.
|
26
|
+
version: '6.1'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: railties
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|