wal 0.0.3 → 0.0.5

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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/exe/wal +18 -14
  3. data/lib/wal/version.rb +1 -1
  4. data/rbi/wal.rbi +20 -21
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3df0dd993bf343f90d54d4b60f52504ca2a84d4fd839c5c952e6f866b40a46cd
4
- data.tar.gz: 8e8b568f3a26ed687e9010bd9c69ea4a656e6af59be20449a9142b61c61fe4ad
3
+ metadata.gz: 15525cced6fec830b09643dfa43d867090a7393a41575cf463445d4b89a664f8
4
+ data.tar.gz: ea86cbc0117bb0c180021cb618975ceb11df8827ca651f2626dfd2b09e9cda34
5
5
  SHA512:
6
- metadata.gz: '09591c7506a7b29d9261574f9a512f120862b58d08ae71d31501147076bbae7f9ab65c9c0ded4fe3c15ddfaa9ec1881ebebf934069c08847d8b486d4fcdfc6f7'
7
- data.tar.gz: c09c1417b8021fde2890f9dd38d32cec9e64e9fec6d1341613b2a8c4522edd60c0ae34e78fdee3c45e8257c6be66d480fb8ad5f3d52fcec5fb0955d79c054a63
6
+ metadata.gz: 70d0acc4046bc00f58e29f2e943cba4dd86e0aa4e7303f6cbe9c57a80fc579023194f58c11e4ee42f6f9622baf69f797babf38eb942e814697b820b380ea81d3
7
+ data.tar.gz: 07b6d3496f3cc1e1c65b0880e91c84bdbd14ca1cfcbc667735f16fcce275fa8a2d148d08390736a6428d1b9b3d50a121764ffa1f4360c8b2ba348b33b6e684e9
data/exe/wal CHANGED
@@ -5,16 +5,19 @@ require "docopt"
5
5
  begin
6
6
  cli = Docopt.docopt(<<~DOCOPT)
7
7
  Usage:
8
- wal watch --watcher <watcher-class> (--slot <replication-slot> | --tmp-slot) [--publication=<publication>...] [--with-timings]
8
+ wal watch --watcher <watcher-class>
9
+ (--slot <replication-slot> | --tmp-slot)
10
+ [--publication=<publication>...]
11
+ [--replicator <replicator-class>]
9
12
  wal start <config-file>
10
13
 
11
14
  Options:
12
- -h --help Show this screen.
13
- --watcher=<watcher-class> The watcher class to be used to listen for WAL changes.
14
- --slot=<replication-slot> The replication slot that will be used.
15
- --tmp-slot Use a temporary replication slot.
16
- [--publication=<publication>...] Force using the informed Postgres publications.
17
- [--with-timings] Add timing logs to the output.
15
+ -h --help Show this screen.
16
+ --watcher=<watcher-class> The watcher class to be used to listen for WAL changes.
17
+ --slot=<replication-slot> The replication slot that will be used.
18
+ --tmp-slot Use a temporary replication slot.
19
+ [--publication=<publication>...] Force using the informed Postgres publications.
20
+ [--replicator=<replicatior_class>] Change the replication driver class
18
21
  DOCOPT
19
22
  rescue Docopt::Exit => err
20
23
  puts err.message
@@ -23,31 +26,32 @@ end
23
26
 
24
27
  require "./config/environment"
25
28
 
29
+ db_config = ActiveRecord::Base.configurations.configs_for(name: "primary").configuration_hash
30
+
26
31
  if cli["watch"]
27
32
  watcher = cli["--watcher"].constantize.new
28
- watcher = Wal::MonitoringWatcher.new(watcher) if cli["--with-timings"]
29
-
30
33
  use_temporary_slot = cli["--tmp-slot"] || false
31
34
  replication_slot = cli["--slot"]
32
35
  replication_slot = replication_slot.presence || "wal_watcher_#{SecureRandom.alphanumeric(4)}" if use_temporary_slot
36
+ replicator = cli["--replicator"]&.constantize || Wal::Replicator
33
37
 
34
- Wal::Replicator
35
- .new(replication_slot:, use_temporary_slot:)
38
+ replicator
39
+ .new(replication_slot:, use_temporary_slot:, db_config:)
36
40
  .replicate_forever(watcher, publications: cli["--publication"])
37
41
 
38
42
  elsif cli["start"]
39
43
  workers = YAML.load_file(cli["<config-file>"])["slots"].map do |slot, config|
40
44
  watcher = config["watcher"].constantize.new
41
- watcher = Wal::MonitoringWatcher.new(watcher) if config["log_execution_time"]
42
45
  temporary = config["temporary"] || false
43
46
  publications = config["publications"] || []
47
+ replicator = config["replicator"]&.constantize || Wal::Replicator
44
48
 
45
49
  Thread.new(slot, watcher, temporary, publications) do |replication_slot, watcher, use_temporary_slot, publications|
46
50
  replication_slot = "#{replication_slot}_#{SecureRandom.alphanumeric(4)}" if use_temporary_slot
47
51
  puts "Watcher started for #{replication_slot} slot (#{publications.join(", ")})"
48
52
 
49
- Wal::Replicator
50
- .new(replication_slot:, use_temporary_slot:)
53
+ replicator
54
+ .new(replication_slot:, use_temporary_slot:, db_config:)
51
55
  .replicate_forever(watcher, publications:)
52
56
 
53
57
  puts "Watcher finished for #{replication_slot}"
data/lib/wal/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Wal
4
- VERSION = "0.0.3"
4
+ VERSION = "0.0.5"
5
5
  end
data/rbi/wal.rbi CHANGED
@@ -103,7 +103,7 @@ module Wal
103
103
  include Wal::Watcher
104
104
  extend T::Sig
105
105
 
106
- sig { override.params(event: Event).void }
106
+ sig { override.params(event: Wal::Event).void }
107
107
  def on_event(event); end
108
108
  end
109
109
 
@@ -113,21 +113,21 @@ module Wal
113
113
  include Wal::Watcher
114
114
  extend T::Sig
115
115
  extend T::Helpers
116
- RecordEvent = T.type_alias { T.any(InsertEvent, UpdateEvent, DeleteEvent) }
116
+ RecordEvent = T.type_alias { T.any(Wal::InsertEvent, Wal::UpdateEvent, Wal::DeleteEvent) }
117
117
 
118
118
  sig { params(subclass: T.untyped).returns(T.untyped) }
119
119
  def self.inherited(subclass); end
120
120
 
121
- sig { params(table: T.any(String, T.class_of(::ActiveRecord::Base)), block: T.proc.bind(T.attached_class).params(event: InsertEvent).void).void }
121
+ sig { params(table: T.any(String, T.class_of(::ActiveRecord::Base)), block: T.proc.bind(T.attached_class).params(event: Wal::InsertEvent).void).void }
122
122
  def self.on_insert(table, &block); end
123
123
 
124
- sig { params(table: T.any(String, T.class_of(::ActiveRecord::Base)), changed: T.nilable(T::Array[T.any(String, Symbol)]), block: T.proc.bind(T.attached_class).params(event: UpdateEvent).void).void }
124
+ sig { params(table: T.any(String, T.class_of(::ActiveRecord::Base)), changed: T.nilable(T::Array[T.any(String, Symbol)]), block: T.proc.bind(T.attached_class).params(event: Wal::UpdateEvent).void).void }
125
125
  def self.on_update(table, changed: nil, &block); end
126
126
 
127
- sig { params(table: T.any(String, T.class_of(::ActiveRecord::Base)), changed: T.nilable(T::Array[T.any(String, Symbol)]), block: T.proc.bind(T.attached_class).params(event: T.any(InsertEvent, UpdateEvent)).void).void }
127
+ sig { params(table: T.any(String, T.class_of(::ActiveRecord::Base)), changed: T.nilable(T::Array[T.any(String, Symbol)]), block: T.proc.bind(T.attached_class).params(event: T.any(Wal::InsertEvent, Wal::UpdateEvent)).void).void }
128
128
  def self.on_save(table, changed: nil, &block); end
129
129
 
130
- sig { params(table: T.any(String, T.class_of(::ActiveRecord::Base)), block: T.proc.bind(T.attached_class).params(event: DeleteEvent).void).void }
130
+ sig { params(table: T.any(String, T.class_of(::ActiveRecord::Base)), block: T.proc.bind(T.attached_class).params(event: Wal::DeleteEvent).void).void }
131
131
  def self.on_destroy(table, &block); end
132
132
 
133
133
  sig { params(event: RecordEvent).void }
@@ -136,10 +136,10 @@ module Wal
136
136
  sig { params(table: String).returns(T::Boolean) }
137
137
  def should_watch_table?(table); end
138
138
 
139
- sig { params(event: BeginTransactionEvent).returns(Symbol) }
139
+ sig { params(event: Wal::BeginTransactionEvent).returns(Symbol) }
140
140
  def aggregation_strategy(event); end
141
141
 
142
- sig { override.params(event: Event).void }
142
+ sig { override.params(event: Wal::Event).void }
143
143
  def on_event(event); end
144
144
  end
145
145
 
@@ -150,10 +150,10 @@ module Wal
150
150
  sig { params(replication_slot: String, use_temporary_slot: T::Boolean, db_config: T::Hash[Symbol, T.untyped]).void }
151
151
  def initialize(replication_slot:, use_temporary_slot: false, db_config: ActiveRecord::Base.configurations.configs_for(name: "primary").configuration_hash); end
152
152
 
153
- sig { params(watcher: Watcher, publications: T::Array[String]).void }
153
+ sig { params(watcher: Wal::Watcher, publications: T::Array[String]).void }
154
154
  def replicate_forever(watcher, publications:); end
155
155
 
156
- sig { params(watcher: Watcher, publications: T::Array[String]).returns(T::Enumerator::Lazy[Event]) }
156
+ sig { params(watcher: Wal::Watcher, publications: T::Array[String]).returns(T::Enumerator::Lazy[Wal::Event]) }
157
157
  def replicate(watcher, publications:); end
158
158
  end
159
159
 
@@ -164,24 +164,23 @@ module Wal
164
164
  extend T::Sig
165
165
  extend T::Helpers
166
166
 
167
- sig { abstract.params(events: T::Enumerator[Event]).void }
167
+ sig { abstract.params(events: T::Enumerator[Wal::Event]).void }
168
168
  def on_transaction_events(events); end
169
169
 
170
- sig { params(event: BeginTransactionEvent).returns(Integer) }
170
+ sig { params(event: Wal::BeginTransactionEvent).returns(Integer) }
171
171
  def queue_size(event); end
172
172
 
173
- sig { override.params(event: Event).void }
173
+ sig { override.params(event: Wal::Event).void }
174
174
  def on_event(event); end
175
175
  end
176
176
 
177
177
  module Watcher
178
178
  abstract!
179
179
 
180
- include Wal
181
180
  extend T::Sig
182
181
  extend T::Helpers
183
182
 
184
- sig { abstract.params(event: Event).void }
183
+ sig { abstract.params(event: Wal::Event).void }
185
184
  def on_event(event); end
186
185
 
187
186
  sig { params(table: String).returns(T::Boolean) }
@@ -193,22 +192,22 @@ module Wal
193
192
  module SeparatedEvents
194
193
  extend T::Sig
195
194
 
196
- sig { params(event: Event).void }
195
+ sig { params(event: Wal::Event).void }
197
196
  def on_event(event); end
198
197
 
199
- sig { params(event: BeginTransactionEvent).void }
198
+ sig { params(event: Wal::BeginTransactionEvent).void }
200
199
  def on_begin(event); end
201
200
 
202
- sig { params(event: InsertEvent).void }
201
+ sig { params(event: Wal::InsertEvent).void }
203
202
  def on_insert(event); end
204
203
 
205
- sig { params(event: UpdateEvent).void }
204
+ sig { params(event: Wal::UpdateEvent).void }
206
205
  def on_update(event); end
207
206
 
208
- sig { params(event: DeleteEvent).void }
207
+ sig { params(event: Wal::DeleteEvent).void }
209
208
  def on_delete(event); end
210
209
 
211
- sig { params(event: CommitTransactionEvent).void }
210
+ sig { params(event: Wal::CommitTransactionEvent).void }
212
211
  def on_commit(event); end
213
212
  end
214
213
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rodrigo Navarro
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-08-02 00:00:00.000000000 Z
10
+ date: 2025-08-10 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: pg