seamusabshere/upsert

Configure attributes not to be updated (other than created_(at|on)

jan opened this issue · 3 comments

jan commented

Sometimes it makes sense not to update fields, but you still need to set them for new records. You are already doing this for created_(at|on). We have a use case for not updating an additional field.

This would be much easier to implement than different create_atts and update_atts like suggested in
#17 by passing an option and then using it in here:

  def update_column_definitions
    setter_column_definitions.select { |cd| cd.name !~ CREATED_COL_REGEX }
  end

Does that make sense? Would you integrate such a pull request into your gem?

@jan definitely - i would love for there not to be a static set of cols

@jan @seamusabshere I think that something between these two options would be the most useful solution - something like

  • Upsert.batch(connection, table, separate_selector_and_setter: true) OR
  • Upsert.batch(connection, table, ignore_update_fields: %w[list of fields])

which would allow you to enable the functionality as-needed.

I would rather not use a constant (or class level variable) as that's going to cause issues with thread safety.

@seamusabshere , is this feature available now? Can't find it in the documentation.