table_sync 4.1.0 → 4.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d6b452885641883758a131ec14f3a9aa2f8508bb1c3a540b8e78c727a8d86a88
4
- data.tar.gz: efd055d98480febde524af5af5db5cfefde1b534a5fa40d7b8cb696ac11432ba
3
+ metadata.gz: 1d5af530003a4144653d1866fda0a581a5ecf021cbcd8e7c2a29028c0e838eb2
4
+ data.tar.gz: 836de51df89dc99294bd8be65eeaf4e00cba6bdb22071170bef42372c4984a70
5
5
  SHA512:
6
- metadata.gz: bd98bc390f5d04625d98c9c5fac179a9b588830210502727288b74c46f4badf4a177afbcbe02b67bd33cdd7ba8ed7d3fea593e3893e5519f5d2c40c01f3a454e
7
- data.tar.gz: 230f6a412f0d2d55750a4d1edb75b5c9605730de1c6352d5e5d1e8b4375ed16081fe296f70ace3dff65b54d5b85bc1a18a153119d8a6f7c1994289d5170ddc80
6
+ metadata.gz: 2558335ef49a853d8d0d12878cdb42cfb91d4bf7dc7838f22c4853dbf09a22aa60569c420eaee0f5a667f21ea55c02b4a62d3c9d7a4299128d2a6d4b47d7b76a
7
+ data.tar.gz: d24f3e8e2cab9f946a37296261d531a44b3ea6e660aa1a9424e0685c9ba2ffff73130e6b9661f3ff76a0636eab9c877e4f7b18ce2c1b7b65326bfb5d2434df48
@@ -1,6 +1,26 @@
1
1
  # Changelog
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
+ ## [4.2.2] - 2020-11-20
5
+ ### Fixed
6
+ - potential data corruption with batches
7
+
8
+ ## [4.2.1] - 2020-11-20
9
+ ### Fixed
10
+ - bug with sorting data in handler, it was bad idea to use `.hash` replaced to `.to_s`
11
+
12
+ ## [4.2.0] - 2020-11-19
13
+
14
+ - No changes. Just stabilization release.
15
+
16
+ ## [4.1.2] - 2020-11-19
17
+ ### Fixed
18
+ - bug with sorting data in handler
19
+
20
+ ## [4.1.1] - 2020-11-06
21
+ ### Fixed
22
+ - dead locks in receiving module (see: `spec/receiving/handler_spec.rb#avoid dead locks`)
23
+
4
24
  ## [4.1.0] - 2020-11-02
5
25
  ### Changed
6
26
  - move `TableSync::Instrument.notify` from models to the handler
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- table_sync (4.1.0)
4
+ table_sync (4.2.2)
5
5
  memery
6
6
  rabbit_messaging (~> 0.3)
7
7
  rails
@@ -84,7 +84,7 @@ GEM
84
84
  crass (1.0.6)
85
85
  diff-lcs (1.4.4)
86
86
  docile (1.3.2)
87
- erubi (1.9.0)
87
+ erubi (1.10.0)
88
88
  exception_notification (4.4.3)
89
89
  actionmailer (>= 4.0, < 7)
90
90
  activesupport (>= 4.0, < 7)
@@ -119,11 +119,11 @@ GEM
119
119
  pry (0.13.1)
120
120
  coderay (~> 1.1)
121
121
  method_source (~> 1.0)
122
- rabbit_messaging (0.7.1)
122
+ rabbit_messaging (0.9.0)
123
123
  bunny (~> 2.0)
124
124
  exception_notification
125
125
  lamian
126
- rails
126
+ rails (>= 5.2)
127
127
  sneakers (~> 2.0)
128
128
  tainbox
129
129
  rack (2.2.3)
@@ -23,6 +23,8 @@ class TableSync::Receiving::Handler < Rabbit::EventHandler
23
23
 
24
24
  validate_data(data, target_keys: target_keys)
25
25
 
26
+ data.sort_by! { |row| row.values_at(*target_keys).to_s }
27
+
26
28
  params = { data: data, target_keys: target_keys, version_key: version_key }
27
29
 
28
30
  if event == :update
@@ -53,16 +55,20 @@ class TableSync::Receiving::Handler < Rabbit::EventHandler
53
55
  end
54
56
 
55
57
  def configs
56
- @configs ||= self.class.configs[model]&.map do |config|
57
- ::TableSync::Receiving::ConfigDecorator.new(
58
- config: config,
59
- # next parameters will be send to each proc-options from config
60
- event: event,
61
- model: model,
62
- version: version,
63
- project_id: project_id,
64
- raw_data: data,
65
- )
58
+ @configs ||= begin
59
+ configs = self.class.configs[model]
60
+ configs = configs.sort_by { |config| "#{config.model.schema}.#{config.model.table}" }
61
+ configs.map do |config|
62
+ ::TableSync::Receiving::ConfigDecorator.new(
63
+ config: config,
64
+ # next parameters will be send to each proc-options from config
65
+ event: event,
66
+ model: model,
67
+ version: version,
68
+ project_id: project_id,
69
+ raw_data: data,
70
+ )
71
+ end
66
72
  end
67
73
  end
68
74
 
@@ -99,9 +105,18 @@ class TableSync::Receiving::Handler < Rabbit::EventHandler
99
105
  end
100
106
 
101
107
  if data.uniq { |row| row.slice(*target_keys) }.size != data.size
102
- raise TableSync::DataError.new(
103
- data, target_keys, "Duplicate rows found!"
104
- )
108
+ raise TableSync::DataError.new(data, target_keys, "Duplicate rows found!")
109
+ end
110
+
111
+ keys_sample = data[0].keys
112
+ keys_diff = data.each_with_object(Set.new) do |row, set|
113
+ (row.keys - keys_sample | keys_sample - row.keys).each(&set.method(:add))
114
+ end
115
+
116
+ unless keys_diff.empty?
117
+ raise TableSync::DataError.new(data, target_keys, <<~MESSAGE)
118
+ Bad batch structure, check keys: #{keys_diff.to_a}
119
+ MESSAGE
105
120
  end
106
121
  end
107
122
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TableSync
4
- VERSION = "4.1.0"
4
+ VERSION = "4.2.2"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: table_sync
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.0
4
+ version: 4.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Umbrellio
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-03 00:00:00.000000000 Z
11
+ date: 2020-11-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: memery