lib/table_sync/receiving/handler.rb in table_sync-4.1.0 vs lib/table_sync/receiving/handler.rb in table_sync-4.1.1

- old
+ new

@@ -21,10 +21,12 @@ target_keys = config.target_keys(data: data) validate_data(data, target_keys: target_keys) + data.sort_by! { |row| row.values_at(*target_keys) } + params = { data: data, target_keys: target_keys, version_key: version_key } if event == :update params[:default_values] = config.default_values(data: data) end @@ -51,20 +53,24 @@ def model=(name) super(name.to_s) end def configs - @configs ||= self.class.configs[model]&.map do |config| - ::TableSync::Receiving::ConfigDecorator.new( - config: config, - # next parameters will be send to each proc-options from config - event: event, - model: model, - version: version, - project_id: project_id, - raw_data: data, - ) + @configs ||= begin + configs = self.class.configs[model] + configs = configs.sort_by { |config| "#{config.model.schema}.#{config.model.table}" } + configs.map do |config| + ::TableSync::Receiving::ConfigDecorator.new( + config: config, + # next parameters will be send to each proc-options from config + event: event, + model: model, + version: version, + project_id: project_id, + raw_data: data, + ) + end end end def processed_data(config) data.map do |row| @@ -97,12 +103,10 @@ data, target_keys, "Some target keys not found in received attributes!" ) end if data.uniq { |row| row.slice(*target_keys) }.size != data.size - raise TableSync::DataError.new( - data, target_keys, "Duplicate rows found!" - ) + raise TableSync::DataError.new(data, target_keys, "Duplicate rows found!") end end def perform(config, params) model = config.model