westonganger / active_snapshot

Simplified snapshots and restoration for ActiveRecord models and associations with a transparent white-box implementation
MIT License
103 stars 16 forks source link

Make identifier argument of create_snapshot optional #27

Closed westonganger closed 1 year ago

westonganger commented 1 year ago

As suggested in https://github.com/westonganger/active_snapshot/issues/13#issuecomment-965690730 , we could make the identifier option of create_snapshot optional. If someone does not set it then we could utilize the id of the record

class SnapshotItem
  validates :identifier, presence: true, unique: {...}, allow_nil: true

  def identifier
    self[:identifier] || id
  end
end

Not sure how I feel about automatically setting some identifier value that are not conciously thought about by the developer. So would like some feedback on this.

westonganger commented 1 year ago

I dont think we need to set the identifier at all. If anyone needs to find a snapshot they can use the created_at timestamp column.

westonganger commented 1 year ago

Merged to master on Sept 19 2022, will update this issue once a new version is released.