|
131 | 131 |
|
132 | 132 | Now when you run `create_snapshot!` the associations will be tracked accordingly
|
133 | 133 |
|
134 |
| -# Reifying Snapshot Items |
| 134 | +# Reifying Snapshots |
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 | +A reified record refers to an ActiveRecord instance where the local objects data is set to match the snaphotted data, but the database remains changed. |
| 137 | + |
| 138 | +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 | 139 |
|
138 | 140 | ```ruby
|
139 | 141 | reified_parent, reified_children_hash = snapshot.fetch_reified_items
|
@@ -166,6 +168,32 @@ attrs_not_changed = old_attrs.to_a.intersection(new_attrs.to_a).to_h
|
166 | 168 | attrs_changed = new_attrs.to_a - attrs_not_changed.to_a
|
167 | 169 | ```
|
168 | 170 |
|
| 171 | +# Important Data Considerations / Warnings |
| 172 | + |
| 173 | +### Dropping columns |
| 174 | + |
| 175 | +If you plan to use the snapshot restore capabilities please be aware: |
| 176 | + |
| 177 | +Whenever you drop a database column and there already exists snapshots of that model then you are kind of silently breaking your restore mechanism. Because now the application will not be able to assign data to columns that dont exist on the model. We work around this by bypassing the attribute assignment for snapshot item object entries that does not correlate to a current database column. |
| 178 | + |
| 179 | +I recommend that you add an entry to this in your applications safe-migrations guidelines. |
| 180 | + |
| 181 | +If you would like to detect if this situation has already ocurred you can use the following script: |
| 182 | + |
| 183 | +```ruby |
| 184 | +SnapshotItem.all.each do |snapshot_item| |
| 185 | + snapshot_item.object.keys.each do |key| |
| 186 | + klass = Class.const_get(snapshot_item.item_type) |
| 187 | + |
| 188 | + if !klass.column_names.include?(key) |
| 189 | + invalid_data = snapshot_item.object.slice(*klass.column_names) |
| 190 | + |
| 191 | + raise "invalid data found - #{invalid_data}" |
| 192 | + end |
| 193 | + end |
| 194 | +end |
| 195 | +``` |
| 196 | + |
169 | 197 | # Key Models Provided & Additional Customizations
|
170 | 198 |
|
171 | 199 | A key aspect of this library is its simplicity and small API. For major functionality customizations we encourage you to first delete this gem and then copy this gems code directly into your repository.
|
|
0 commit comments