Comments (8)
But when I want to check the value at any version, it always returns the current version one even when it was nil in previous versions:
I think, it can be considered a bug.
However, I don't have a quick solution in mind. The way Logidze travels back is by creating an aggregated diff (from the initial version to the specified) and applying to the current state of the record.
If we can assume that the initial version is full snapshot, we're can nullify all the attributes not present in the diff. But I'm not sure about the assumption—does it always hold? Not really: if we filter columns, we shouldn't nullify the ones we do not track.
So, the solution could be:
- Nullify all attributes present in the current schema and missing in the diff.
- In case not all columns are being tracked, we must only take into account trackable columns in the schema. We can try to read this information from Postgres.
Does anyone see any other edge cases?
from logidze.
I did run into a similar situation. In my case, there were both tracked and untracked column.
To make it work properly, I patched up the history with nil values for the newly added fields .
Something like
Model.find_each(batch_size: 50) do |subject|
subject.with_lock do
raw_history = subject.read_attribute_before_type_cast(:log_data)
parsed = JSON.parse(raw_history)
next if parsed["h"][0]["c"].key?("new_field")
parsed["h"][0]["c"]["new_field"] = nil
altered_history = parsed.to_json
Logidze.without_logging do
subject.update_column(:log_data, altered_history)
end
end
end
end
note here that I always take snapshot right after creation, so I know version 1 should have nil
for the new_field
from logidze.
Have you used Tracking only selected columns —except=
/ —only=
option in your model?
Otherwise looks a lot like my case #230
from logidze.
@adas172002 I did not - I track everything. And even if I save the model again with a change on a different column Logidze/PG doesn’t detect a change in column because the column didn’t exist before and is null now.
from logidze.
Sounds reasonable, yes 👌
from logidze.
If the default value of the new column is not null, I think it should not be nulled either
from logidze.
If the default value of the new column is not null, I think it should not be nulled either
That's a good point; we can restore it to the default value; however, it's not always possible to obtain this information from Active Record, so, I guess, in this case we should still use nil
.
from logidze.
What if in Lodigze::History#changes_to, instead of making a reduction to accumulate the attributes from the log changes until the version or time. It will also check for missing attributes by checking the @attributes and continue to accumulate until all missing attributes are found.
Then we will get all the attributes that are closest to the version or time we requested, instead of the latest data.
from logidze.
Related Issues (20)
- Tracking changes on JSONB column error
- How to list all versions of a record? HOT 4
- Association versioning with ignore_log_data and at(version: ) doesn't return expected results HOT 5
- Partition-friendly logging (triggers) HOT 3
- JSONB column and switch_to! with append: true HOT 2
- PG::UndefinedFunction: ERROR: function hstore(model_name) does not exist HOT 1
- Meta per request HOT 1
- Logidze.ignore_log_data_by_default causing db:migrate errors HOT 2
- Responsible from different sources HOT 3
- Associations versioning - accessing versions with `at(version: #)` HOT 2
- GlobalID support for metadata
- `responsible_id` is not updated on relation with `touch: true` HOT 6
- reload_log_data doesn't work when used with acts_as_paranoid and deleted records HOT 2
- docs: logdize cannot set session meta data when using a connection pool HOT 1
- How can I get the last 100 versions of a model? regardless of the record HOT 2
- Saving log with only metadata changes HOT 1
- Not possible to use latest logidze and anyway_config with Ruby 3.3.0 HOT 1
- Make Sequel support independent from ActiveRecord and ActiveSupport
- Updating history when column names change HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from logidze.