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 database columns results in inability to restore/reify. #58

Closed
commuun opened this issue Aug 27, 2024 · 6 comments
Closed

Removing database columns results in inability to restore/reify. #58

commuun opened this issue Aug 27, 2024 · 6 comments

Comments

@commuun
Copy link

commuun commented Aug 27, 2024

When a database column is removed, restoring or reifying existing items that still reference that column will result in an "unknown attribute" error.

For instance I removed the price field from my products table and tried to reify an old snapshot:

> Product.find(1234).snapshots.last.fetch_reified_items
ActiveModel::UnknownAttributeError: unknown attribute 'price' for Product.

This happens in both Snapshot#fetch_reified_items and SnapshotItem#restore_item!

I'm not sure what the best solution would be.

  • Attack it at the source (SnapshotItem#object) and remove all fields that are no longer present in (in this example) Product.attribute_names, which would fix both cases
  • Filter it out in Snapshot#fetch_reified_items and SnapshotItem#restore_item! individually so that #object stays "pure"
@westonganger
Copy link
Owner

I think that Snapshot#fetch_reified_items and SnapshotItem#restore_item! would be the place to put it.

@westonganger
Copy link
Owner

Would appreciate a PR for this.

@dmrAnderson
Copy link
Contributor

@westonganger
Would you like some help with that? Do you already know how to do it effectively?

@westonganger
Copy link
Owner

This is tough

I dont want this gem to silently ignore this issue. When this issue is encountered this it means that you have made a breaking change to your backup and restore system.

But we also need restore to continue to work after this situation.

Just need to figure our what the best way to notify the developer when this situation is encountered. Some ideas:

  • Readme section to describe this issue, basically state "you have been warned"
  • Log a warning
  • Raise exception (the longer I think about this the worse this solution feels, I want to notify the developer before they break it...)
  • Silently ignore

@westonganger
Copy link
Owner

I've added #66 which looks to solve this.

Took the approach of readme updates and silently ignoring the data.

westonganger added a commit that referenced this issue Nov 12, 2024
…iated column no longer exists (#66)

Ensure `SnapshotItem#restore_item!` and `Snapshot#fetch_reified_items` bypass assignment for snapshot object data where the associated column no longer exists.

Solves #58
@westonganger
Copy link
Owner

v0.5.1 is now released which contains the changes which now ignores data which cannot be assigned to the model instance

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

No branches or pull requests

3 participants