Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing specific versions from the histroy #103

Closed
jcsrb opened this issue Jan 10, 2019 · 3 comments
Closed

Removing specific versions from the histroy #103

jcsrb opened this issue Jan 10, 2019 · 3 comments
Labels

Comments

@jcsrb
Copy link
Contributor

jcsrb commented Jan 10, 2019

I am currently working on a way to clean up the history as I did not use the without_logging wisely in the past in regards to some maintenance tasks and now what to expose part of the history to users.

My approach is to remove the specific version from the json and updating the number of the other versions.

Is this something that would make sense to added to the gem?
Are there any obvious issues with my approach?

@palkan
Copy link
Owner

palkan commented Jan 10, 2019

Is this something that would make sense to added to the gem?

Yep, I think that could be useful. Something like record.remove_log_version(version_number).

Are there any obvious issues with my approach?

Depends on the implementation. I suggest adding a DB-side function/procedure and call it to avoid race conditions, e.g.:

update my_table set log_data = logidze_remove_version(log_data, version_number) where id = 1

@palkan
Copy link
Owner

palkan commented Jul 29, 2020

Closing this for now.
Removing the version from the log is not straightforward as it might seem: we need to care about the log consistency, thus removing a version is closer to compaction, since we need to merge the diff from the removed version with the previous one (or the next one?).

Probably, doing such tasks manually (i.e., in Ruby, smth like Mode.find_each { |item| LogCleaner.call(item) }) is a better way.

@palkan palkan closed this as completed Jul 29, 2020
@jcsrb
Copy link
Contributor Author

jcsrb commented Jul 29, 2020

here is a helpful snippet, implementation of remove_version works on the json and depends on the exact thing one tries to achieve

subject.with_lock do
  raw_history = subject.read_attribute_before_type_cast(:log_data)

  altered_history = remove_version raw_history, version
  Logidze.without_logging do
    subject.update_column(:log_data, altered_history)
  end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants