koyo-postgres-replication 0.1.3.pre → 0.1.5.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.yardoc/checksums +5 -5
- data/.yardoc/object_types +0 -0
- data/.yardoc/objects/root.dat +0 -0
- data/Dockerfile +29 -0
- data/Gemfile +1 -0
- data/Gemfile.lock +7 -1
- data/README.md +14 -0
- data/changelog.md +13 -0
- data/docker/postgres/Dockerfile +3 -0
- data/docker-compose.yml +34 -0
- data/entrypoint.sh +5 -0
- data/koyo-postgres-replication.gemspec +1 -1
- data/lib/koyo/repl/data_row.rb +13 -9
- data/lib/koyo/repl/postgres_server.rb +12 -12
- data/lib/koyo/repl/railtie.rb +5 -0
- data/lib/koyo/repl/version.rb +1 -1
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8b45ea024487cd58842efb84ffb49a8a838a087c3302fc1411d02ec1afc646c2
|
4
|
+
data.tar.gz: 81900cffddb22af277e55be4c558316b9e0a61e3c9d9618f8d47ae1019f479ab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 52657842594b2e36b7ac7f658b2c3a56b3e4c6a4d7b22896dd1fade2daa34c7d7a4a9884c374930b055180b46078b72b2c6bdddf2a6b8a518ea67528e8b58b56
|
7
|
+
data.tar.gz: 7252cd8c30c701ee033cf7244ed668e9b23d9c9b0f48d958835eafe59a0419c0df60a05e09e580ebb798bec704e44708bd12905cf658669494ed58fa6a3082f6
|
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
|
7
|
-
lib/koyo/repl/version.rb
|
8
|
-
lib/koyo/repl/data_row.rb
|
9
|
-
lib/koyo/repl/database.rb
|
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
|
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
|
data/.yardoc/objects/root.dat
CHANGED
Binary file
|
data/Dockerfile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
FROM ruby:3.2.2-slim
|
2
|
+
|
3
|
+
RUN apt-get update -qq && apt-get install -yq --no-install-recommends \
|
4
|
+
git \
|
5
|
+
build-essential \
|
6
|
+
gnupg2 \
|
7
|
+
less \
|
8
|
+
libpq-dev \
|
9
|
+
postgresql-client \
|
10
|
+
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
|
11
|
+
|
12
|
+
ENV LANG=C.UTF-8 \
|
13
|
+
BUNDLE_JOBS=4 \
|
14
|
+
BUNDLE_RETRY=3
|
15
|
+
|
16
|
+
RUN gem update --system && gem install bundler && gem install rails
|
17
|
+
|
18
|
+
WORKDIR /usr/src/app
|
19
|
+
|
20
|
+
COPY Gemfile .
|
21
|
+
COPY Gemfile.lock .
|
22
|
+
|
23
|
+
COPY . .
|
24
|
+
|
25
|
+
RUN bundle install
|
26
|
+
|
27
|
+
COPY . .
|
28
|
+
|
29
|
+
CMD ["irb"]
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
koyo-postgres-replication (0.1.
|
4
|
+
koyo-postgres-replication (0.1.5.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)
|
@@ -123,6 +125,8 @@ GEM
|
|
123
125
|
net-smtp (0.3.3)
|
124
126
|
net-protocol
|
125
127
|
nio4r (2.5.9)
|
128
|
+
nokogiri (1.15.4-aarch64-linux)
|
129
|
+
racc (~> 1.4)
|
126
130
|
nokogiri (1.15.4-arm64-darwin)
|
127
131
|
racc (~> 1.4)
|
128
132
|
parallel (1.23.0)
|
@@ -212,9 +216,11 @@ GEM
|
|
212
216
|
zeitwerk (2.6.11)
|
213
217
|
|
214
218
|
PLATFORMS
|
219
|
+
aarch64-linux
|
215
220
|
arm64-darwin-22
|
216
221
|
|
217
222
|
DEPENDENCIES
|
223
|
+
composite_primary_keys (~> 14.0)
|
218
224
|
debug
|
219
225
|
factory_bot_rails
|
220
226
|
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
|
@@ -188,6 +192,16 @@ TODO: update
|
|
188
192
|
|
189
193
|
# Working with gem
|
190
194
|
|
195
|
+
## Run specs
|
196
|
+
|
197
|
+
```
|
198
|
+
rspec spec
|
199
|
+
```
|
200
|
+
|
201
|
+
### Docker
|
202
|
+
|
203
|
+
See [Docker wiki page](https://github.com/wiseleyb/koyo-postgres-replication/wiki/Docker)
|
204
|
+
|
191
205
|
## Gem Build
|
192
206
|
|
193
207
|
```
|
data/changelog.md
CHANGED
@@ -1,5 +1,18 @@
|
|
1
1
|
# Koyo Postgres Replication Changelog
|
2
2
|
|
3
|
+
## 0.1.5.pre
|
4
|
+
|
5
|
+
- Yard doc gemspec change to get it to show up in rubygems
|
6
|
+
- Add Docker files
|
7
|
+
|
8
|
+
## 0.1.4.pre
|
9
|
+
|
10
|
+
- Add link to
|
11
|
+
[doc](https://rubydoc.info/github/wiseleyb/koyo-postgres-replication/main) in
|
12
|
+
README
|
13
|
+
- Fix issues around composite keys (multiple primary keys) [Issues
|
14
|
+
4](https://github.com/wiseleyb/koyo-postgres-replication/issues/4)
|
15
|
+
|
3
16
|
## 0.1.3.pre
|
4
17
|
|
5
18
|
- republishing yanked gem
|
data/docker-compose.yml
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
version: '3.9'
|
2
|
+
services:
|
3
|
+
db:
|
4
|
+
build: ./docker/postgres
|
5
|
+
image: postgres:13
|
6
|
+
ports:
|
7
|
+
- "5432:5432"
|
8
|
+
environment:
|
9
|
+
- POSTGRES_DB=rei_replication_test
|
10
|
+
- POSTGRES_PASSWORD=changeme
|
11
|
+
# - POSTGRES_USER=postgres
|
12
|
+
volumes:
|
13
|
+
- db_data:/var/lib/postgresql/data
|
14
|
+
command:
|
15
|
+
- "postgres"
|
16
|
+
- "-c"
|
17
|
+
- "wal_level=logical"
|
18
|
+
web:
|
19
|
+
build: .
|
20
|
+
image: rails-on-docker:1.3.0
|
21
|
+
stdin_open: true
|
22
|
+
tty: true
|
23
|
+
environment:
|
24
|
+
- DATABASE_URL=postgres://postgres:changeme@db
|
25
|
+
- BOOTSNAP_CACHE_DIR=/usr/local/bundle/_bootsnap
|
26
|
+
- HISTFILE=/usr/src/app/.dockerdev/.bash_history
|
27
|
+
- MALLOC_ARENA_MAX=2
|
28
|
+
volumes:
|
29
|
+
- .:/usr/src/app/:cached
|
30
|
+
depends_on:
|
31
|
+
- db
|
32
|
+
volumes:
|
33
|
+
bundle:
|
34
|
+
db_data:
|
data/entrypoint.sh
ADDED
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.metadata = {
|
21
21
|
'bug_tracker_uri' => "#{url}/issues",
|
22
22
|
'changelog_uri' => "#{url}/blob/main/changelog.md",
|
23
|
-
'
|
23
|
+
'documentation_uri' => 'https://www.rubydoc.info/github/wiseleyb/koyo-postgres-replication/main',
|
24
24
|
'homepage_uri' => spec.homepage,
|
25
25
|
'source_code_uri' => burl
|
26
26
|
}
|
data/lib/koyo/repl/data_row.rb
CHANGED
@@ -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
|
-
|
38
|
-
|
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
|
-
|
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
|
-
|
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
|
data/lib/koyo/repl/railtie.rb
CHANGED
data/lib/koyo/repl/version.rb
CHANGED
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.
|
4
|
+
version: 0.1.5.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-
|
11
|
+
date: 2023-08-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pg
|
@@ -116,12 +116,16 @@ files:
|
|
116
116
|
- ".yardoc/objects/root.dat"
|
117
117
|
- ".yardoc/proxy_types"
|
118
118
|
- ".yardopts"
|
119
|
+
- Dockerfile
|
119
120
|
- Gemfile
|
120
121
|
- Gemfile.lock
|
121
122
|
- MIT-LICENSE
|
122
123
|
- README.md
|
123
124
|
- Rakefile
|
124
125
|
- changelog.md
|
126
|
+
- docker-compose.yml
|
127
|
+
- docker/postgres/Dockerfile
|
128
|
+
- entrypoint.sh
|
125
129
|
- koyo-postgres-replication.gemspec
|
126
130
|
- lib/koyo.rb
|
127
131
|
- lib/koyo/repl/configuration.rb
|
@@ -146,7 +150,7 @@ licenses:
|
|
146
150
|
metadata:
|
147
151
|
bug_tracker_uri: https://github.com/wiseleyb/koyo-postgres-replication/issues
|
148
152
|
changelog_uri: https://github.com/wiseleyb/koyo-postgres-replication/blob/main/changelog.md
|
149
|
-
|
153
|
+
documentation_uri: https://www.rubydoc.info/github/wiseleyb/koyo-postgres-replication/main
|
150
154
|
homepage_uri: https://github.com/wiseleyb
|
151
155
|
source_code_uri: https://github.com/wiseleyb
|
152
156
|
post_install_message:
|