koyo-postgres-replication 0.1.4.pre → 0.1.6.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 +1 -1
- data/.yardoc/objects/root.dat +0 -0
- data/Dockerfile +24 -0
- data/Gemfile.lock +4 -1
- data/README.md +66 -2
- data/changelog.md +10 -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/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: 205fff146002126edb7d725c1897ed7e3dc6bedc78539f0d21e707e22c5aeee0
|
4
|
+
data.tar.gz: 5aa57b08c21c7e86fdd6b44f9b2a4a679b2cf6c3e7628ab99f932757b46974ab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 13a8079535f071892ce0916853c6ddb2f197d355dbe780889c80d67313254632365e6a2a29a171f3dcbba6811bf6f77f9be59a26fe9822abbf56cace481cd41b
|
7
|
+
data.tar.gz: 20db2d8d865adc610b433673b44c93528cc490b43f7ac430aaf4a8924f10a14e552e7ea8e986790226bab27ce3e4835f900daebddf6252f27133fd5b9f1faba3
|
data/.yardoc/checksums
CHANGED
@@ -4,7 +4,7 @@ lib/koyo/repl/mod.rb 92b54b56643b06fdc74adc65dc04460f631d4036
|
|
4
4
|
lib/koyo/repl/data.rb cb847585c0f439b9f645b5ebd7fa3b96e08b94ff
|
5
5
|
lib/koyo/repl/install.rb 9b19b7bb74d084882a1f726693bac2d693015daa
|
6
6
|
lib/koyo/repl/railtie.rb 9c560c38f4663edda57aa39c9bb4bd9411daabbd
|
7
|
-
lib/koyo/repl/version.rb
|
7
|
+
lib/koyo/repl/version.rb a05897446d0fc22220b2393f10f0ab1f4dbba1d8
|
8
8
|
lib/koyo/repl/data_row.rb 46bd0b440721f3b0ddcded3fef1817ca5d77cb35
|
9
9
|
lib/koyo/repl/database.rb 719f2723b83a927e0524f6dea79393caaeba0514
|
10
10
|
lib/koyo/repl/diagnostics.rb 93226c47642c5e20f615425aff8a0c0ba988b07b
|
data/.yardoc/objects/root.dat
CHANGED
Binary file
|
data/Dockerfile
ADDED
@@ -0,0 +1,24 @@
|
|
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 . .
|
21
|
+
|
22
|
+
RUN bundle install
|
23
|
+
|
24
|
+
CMD ["irb"]
|
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.6.pre)
|
5
5
|
pg (~> 1.1)
|
6
6
|
rack (~> 2.0, >= 2.0.0)
|
7
7
|
rails (~> 7.0)
|
@@ -125,6 +125,8 @@ GEM
|
|
125
125
|
net-smtp (0.3.3)
|
126
126
|
net-protocol
|
127
127
|
nio4r (2.5.9)
|
128
|
+
nokogiri (1.15.4-aarch64-linux)
|
129
|
+
racc (~> 1.4)
|
128
130
|
nokogiri (1.15.4-arm64-darwin)
|
129
131
|
racc (~> 1.4)
|
130
132
|
parallel (1.23.0)
|
@@ -214,6 +216,7 @@ GEM
|
|
214
216
|
zeitwerk (2.6.11)
|
215
217
|
|
216
218
|
PLATFORMS
|
219
|
+
aarch64-linux
|
217
220
|
arm64-darwin-22
|
218
221
|
|
219
222
|
DEPENDENCIES
|
data/README.md
CHANGED
@@ -4,9 +4,63 @@
|
|
4
4
|
|
5
5
|
効用 koyo - Japanese for utility
|
6
6
|
|
7
|
-
##
|
7
|
+
## What is this?
|
8
8
|
|
9
|
-
This gem tries to simplify dealing with a `replication slot` in Postgres.
|
9
|
+
This gem tries to simplify dealing with a `replication slot` in Postgres. It
|
10
|
+
gives you a simple way to capture events in your Rails app when your Postgres
|
11
|
+
DB has a create, update, delete event. You can manage this from one class, or
|
12
|
+
manage this on a table-by-table basis within ActiveRecord Models.
|
13
|
+
|
14
|
+
Example of catch all:
|
15
|
+
|
16
|
+
```
|
17
|
+
class KoyoReplHandlerService < Koyo::Repl::EventHandlerService
|
18
|
+
class << self
|
19
|
+
# This is called whenever a create/update/delete action happens
|
20
|
+
# @param (Koyo::Repl::DataRow) row is docuemented in the wiki at
|
21
|
+
# https://github.com/wiseleyb/koyo-postgres-replication/wiki/Koyo::Repl::DataRow-data-spec
|
22
|
+
def koyo_handle_all_replication(row)
|
23
|
+
case row.kind
|
24
|
+
when 'insert'
|
25
|
+
case row.table
|
26
|
+
when 'users'
|
27
|
+
# Do something with data... like update some api
|
28
|
+
# It's important to do this async (active-job/sidekiq) so you
|
29
|
+
# don't back up the replication slot
|
30
|
+
UpdateSomeApi.performn_async(row.id)
|
31
|
+
# This job would do something like:
|
32
|
+
# User.find(row.id); Call some API with data
|
33
|
+
when 'delete'
|
34
|
+
when 'update'
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
```
|
39
|
+
|
40
|
+
Example of model callback:
|
41
|
+
|
42
|
+
```
|
43
|
+
class User < ApplicationRecord
|
44
|
+
include Koyo::Repl::Mod
|
45
|
+
koyo_repl_handler :handle_replication
|
46
|
+
|
47
|
+
# This is called when a row is created/updated/deleted for the users table
|
48
|
+
# @param (Koyo::Repl::DataRow) row is docuemented in the wiki at
|
49
|
+
# https://github.com/wiseleyb/koyo-postgres-replication/wiki/Koyo::Repl::DataRow-data-spec
|
50
|
+
def self.handle_replication(row)
|
51
|
+
case row.kind
|
52
|
+
when 'insert'
|
53
|
+
# Do something with data... like update some api
|
54
|
+
# It's important to do this async (active-job/sidekiq) so you
|
55
|
+
# don't back up the replication slot
|
56
|
+
UpdateSomeApi.performn_async(row.id)
|
57
|
+
# This job would do something like:
|
58
|
+
# User.find(row.id); Call some API with data
|
59
|
+
when 'delete'
|
60
|
+
when 'update'
|
61
|
+
end
|
62
|
+
end
|
63
|
+
```
|
10
64
|
|
11
65
|
### What is a replication slot?
|
12
66
|
|
@@ -192,6 +246,16 @@ TODO: update
|
|
192
246
|
|
193
247
|
# Working with gem
|
194
248
|
|
249
|
+
## Run specs
|
250
|
+
|
251
|
+
```
|
252
|
+
rspec spec
|
253
|
+
```
|
254
|
+
|
255
|
+
### Docker
|
256
|
+
|
257
|
+
See [Docker wiki page](https://github.com/wiseleyb/koyo-postgres-replication/wiki/Docker)
|
258
|
+
|
195
259
|
## Gem Build
|
196
260
|
|
197
261
|
```
|
data/changelog.md
CHANGED
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/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.6.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-22 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:
|