koyo-postgres-replication 0.1.3.pre → 0.1.4.pre

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1cc8e3d452d94177ba7d15d098bbb38b949c45a4e25c22562b358f2858b8d541
4
- data.tar.gz: f844b6eb897ab00c079be8e09a45398532657938ab9e2ae762ddd07c67f685be
3
+ metadata.gz: d7e309ca1f76d89a85e0d84b66fd54b629e7060ffd089a6a4383099230ccad9f
4
+ data.tar.gz: d387c7c45a91cf7500c83188688024fd8c08c97c4298fcc015d1d7b12adc425b
5
5
  SHA512:
6
- metadata.gz: b7e17ddc565bcc1badd81dd6520506578e9eaf09be4598ace88b1336b8c8d797ea01e48724bad5217faf2442bcd04b5cce23a48f5feb048adc00d055e7c912d7
7
- data.tar.gz: df0fd55f7909c6c401fbef598e618cd4837b22634400931b9942c50b650cde64b275c61ecdb7b0f82ab5f620a0b82b3851d9c4e40c20e9ecf7303b9e3628282c
6
+ metadata.gz: 69dae55f084fc5d4206164d47e312d5bcbf530397190563126097fc3e0250760537ae1930b68228e18f7490e929e374af67663bb3ee8b6da99460dc718951bc6
7
+ data.tar.gz: 4c53b1c6a422c78f70885ac5db3a4951b8323b8ba9707771915cd4cbe933274d2697c467c2b75586ca9c77e2e5fd299cf8bdfdc5b011a39dc6efa2ab6288bb82
data/.yardoc/checksums CHANGED
@@ -3,12 +3,12 @@ lib/koyo/repl/log.rb 811d21aa6f8843589b66da79a96a4e8b755fcc2d
3
3
  lib/koyo/repl/mod.rb 92b54b56643b06fdc74adc65dc04460f631d4036
4
4
  lib/koyo/repl/data.rb cb847585c0f439b9f645b5ebd7fa3b96e08b94ff
5
5
  lib/koyo/repl/install.rb 9b19b7bb74d084882a1f726693bac2d693015daa
6
- lib/koyo/repl/railtie.rb acb36cbbe1b386ece7567990945adecb6b6e5b80
7
- lib/koyo/repl/version.rb 45af9c57eb86c840d6c0756f1cd0b8a2f4b00ac0
8
- lib/koyo/repl/data_row.rb 321caf0b080621f2d319fa152948cbe864c77294
9
- lib/koyo/repl/database.rb 39a304909ccf68d69d36c84e3036debd9f29f6ec
6
+ lib/koyo/repl/railtie.rb 9c560c38f4663edda57aa39c9bb4bd9411daabbd
7
+ lib/koyo/repl/version.rb d0d535b2aac27e3caa5eaeef69e117772e334f44
8
+ lib/koyo/repl/data_row.rb 46bd0b440721f3b0ddcded3fef1817ca5d77cb35
9
+ lib/koyo/repl/database.rb 719f2723b83a927e0524f6dea79393caaeba0514
10
10
  lib/koyo/repl/diagnostics.rb 93226c47642c5e20f615425aff8a0c0ba988b07b
11
11
  lib/koyo/repl/configuration.rb 8a32f819abf035340a3997d989ccafe0751d209e
12
- lib/koyo/repl/postgres_server.rb c8f557e1eec5b9be51ebd48002a3986eddbd6634
12
+ lib/koyo/repl/postgres_server.rb 3d564dff9e7820962da02f8a383a607fb72110dc
13
13
  lib/koyo_postgres_replication.rb e3f4d905e3045b59f1f7c799d84cd9fde70eebd8
14
14
  lib/koyo/repl/event_handler_service.rb 99b67bdcf3e0e92a04cd01bf8d05a4569b45d218
data/.yardoc/object_types CHANGED
Binary file
Binary file
data/Gemfile CHANGED
@@ -6,6 +6,7 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
6
6
  # Specify your gem's dependencies in koyo_repl.gemspec
7
7
  gemspec
8
8
 
9
+ gem 'composite_primary_keys', '~> 14.0'
9
10
  gem 'pg', '~> 1.1'
10
11
  gem 'rails', '~> 7.0'
11
12
  gem 'rake', '~> 13.0'
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- koyo-postgres-replication (0.1.2.pre)
4
+ koyo-postgres-replication (0.1.4.pre)
5
5
  pg (~> 1.1)
6
6
  rack (~> 2.0, >= 2.0.0)
7
7
  rails (~> 7.0)
@@ -78,6 +78,8 @@ GEM
78
78
  ast (2.4.2)
79
79
  base64 (0.1.1)
80
80
  builder (3.2.4)
81
+ composite_primary_keys (14.0.6)
82
+ activerecord (~> 7.0.2)
81
83
  concurrent-ruby (1.2.2)
82
84
  crass (1.0.6)
83
85
  date (3.3.3)
@@ -215,6 +217,7 @@ PLATFORMS
215
217
  arm64-darwin-22
216
218
 
217
219
  DEPENDENCIES
220
+ composite_primary_keys (~> 14.0)
218
221
  debug
219
222
  factory_bot_rails
220
223
  ffaker
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # Koyo::Postgres::Replication
2
2
 
3
3
  例 rei - Japanese for example
4
+
4
5
  効用 koyo - Japanese for utility
5
6
 
6
7
  ## Replcation slots
@@ -170,6 +171,9 @@ for sql examples on how to interact with replication slots.
170
171
 
171
172
  ## Yard Doc
172
173
 
174
+ Yard docs are up on
175
+ [RubyDoc.info](https://rubydoc.info/github/wiseleyb/koyo-postgres-replication/main)
176
+
173
177
  Cheat sheets:
174
178
  * https://gist.github.com/chetan/1827484
175
179
  * https://kapeli.com/cheat_sheets/Yard.docset/Contents/Resources/Documents/index
data/changelog.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Koyo Postgres Replication Changelog
2
2
 
3
+ ## 0.1.4.pre
4
+
5
+ - Add link to
6
+ [doc](https://rubydoc.info/github/wiseleyb/koyo-postgres-replication/main) in
7
+ README
8
+ - Fix issues around composite keys (multiple primary keys) [Issues
9
+ 4](https://github.com/wiseleyb/koyo-postgres-replication/issues/4)
10
+
3
11
  ## 0.1.3.pre
4
12
 
5
13
  - republishing yanked gem
@@ -11,8 +11,10 @@ module Koyo
11
11
  :kind, # insert/update/delete
12
12
  :schema, # always public for this - not needed
13
13
  :table, # table being changed
14
- :id, # table.id
15
- :id_type, # integer/uuid
14
+ :id, # table.id, null for composite keys
15
+ :id_type, # integer/uuid, null for composite keys
16
+ :ids, # for composite keys - array of ids
17
+ :id_types, # for composite keys - array of types
16
18
  :columns, # all columns from table - array
17
19
  :column_types, # all types of columns - array
18
20
  :values # all values from table - array
@@ -34,12 +36,12 @@ module Koyo
34
36
  # WARN: this breaks for multiple primary keys
35
37
  def check_set_primary_keys
36
38
  if @row['oldkeys']
37
- if @row['oldkeys']['keynames'].size > 1
38
- raise "This doesn't support multiple keys right now"
39
+ @ids = Array.new(@row['oldkeys']['keyvalues'])
40
+ @id_types = Array.new(@row['oldkeys']['keytypes'])
41
+ if @row['oldkeys']['keynames'].size == 1
42
+ @id = @ids.first
43
+ @id_type = @id_types.first
39
44
  end
40
-
41
- @id = @row['oldkeys']['keyvalues'].first
42
- @id_type = @row['oldkeys']['keytypes'].first
43
45
  else
44
46
  @id = val(:id)
45
47
  @id_type = type(:id)
@@ -49,13 +51,15 @@ module Koyo
49
51
  # Gets a value for a name from columnsvalues
50
52
  # @param name column name
51
53
  def val(name)
52
- values[columns.index(name.to_s)]
54
+ idx = columns.index(name.to_s)
55
+ idx ? values[idx] : nil
53
56
  end
54
57
 
55
58
  # Get a val type from columntypes
56
59
  # @param name column name
57
60
  def type(name)
58
- column_types[columns.index(name.to_s)]
61
+ idx = columns.index(name.to_s)
62
+ idx ? column_types[idx] : nil
59
63
  end
60
64
  end
61
65
  end
@@ -62,6 +62,18 @@ module Koyo
62
62
  end
63
63
  end
64
64
 
65
+ # Does a single check of the replication slot
66
+ # If test_mode=true uses peek, which will
67
+ # leave data in the replication slot (for testing/debugging)
68
+ def check
69
+ read_sql_results.each do |sql_res|
70
+ rows = Koyo::Repl::Data.new(sql_res).rows # returns ReplDataRow
71
+ rows.each do |row|
72
+ check_row(row)
73
+ end
74
+ end
75
+ end
76
+
65
77
  # Attempts to re-establish DB connection. If it finds any other
66
78
  # error this is fatal and server crashes at this point
67
79
  # @param [StandardError] err Error that kicked off this retry loop
@@ -121,18 +133,6 @@ module Koyo
121
133
  @tick_tock = 0
122
134
  end
123
135
 
124
- # Does a single check of the replication slot
125
- # If test_mode=true uses peek, which will
126
- # leave data in the replication slot (for testing/debugging)
127
- def check
128
- read_sql_results.each do |sql_res|
129
- rows = Koyo::Repl::Data.new(sql_res).rows # returns ReplDataRow
130
- rows.each do |row|
131
- check_row(row)
132
- end
133
- end
134
- end
135
-
136
136
  # Reads data from the replication slot
137
137
  # Handles test_mode (so will only peek if true)
138
138
  def read_sql_results
@@ -31,6 +31,11 @@ module Koyo
31
31
  puts 'Running Koyo::Repl::PostgresServer.run!'
32
32
  Koyo::Repl::PostgresServer.run!
33
33
  end
34
+
35
+ desc 'Recreate replication slot'
36
+ task recreate: :environment do
37
+ Koyo::Repl::Database.drop_create_slot!
38
+ end
34
39
  end
35
40
  end
36
41
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Koyo
4
4
  module Repl
5
- VERSION = '0.1.3.pre'
5
+ VERSION = '0.1.4.pre'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: koyo-postgres-replication
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3.pre
4
+ version: 0.1.4.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Wiseley
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-08-18 00:00:00.000000000 Z
11
+ date: 2023-08-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pg