pgbus 0.16.7 → 0.17.0

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.
@@ -14,6 +14,7 @@ module Pgbus
14
14
  class VersionNotFoundError < Pgbus::Error; end
15
15
 
16
16
  SCHEMA_DIR = File.expand_path("pgmq_schema", __dir__).freeze
17
+ FIXUPS_DIR = File.join(SCHEMA_DIR, "fixups").freeze
17
18
 
18
19
  class << self
19
20
  # Returns the latest vendored PGMQ version string.
@@ -23,9 +24,37 @@ module Pgbus
23
24
 
24
25
  # Returns sorted list of all vendored PGMQ versions.
25
26
  def available_versions
26
- Dir.glob(File.join(SCHEMA_DIR, "pgmq_v*.sql"))
27
- .map { |f| File.basename(f).match(/pgmq_v(.+)\.sql/)[1] }
28
- .sort_by { |v| Gem::Version.new(v) }
27
+ versions_in(SCHEMA_DIR)
28
+ end
29
+
30
+ # Versions that ship a table fixup, in version order.
31
+ #
32
+ # An upgrade drops every pgmq function and composite type and re-runs the
33
+ # target version's schema, which recreates both — but never touches an
34
+ # existing table. An upstream hop that ALTERs one (1.13.0 moves
35
+ # partitioned queues' msg_id from GENERATED ALWAYS to BY DEFAULT) needs
36
+ # its own step, and that is what these files are.
37
+ def fixup_versions
38
+ versions_in(FIXUPS_DIR)
39
+ end
40
+
41
+ # Concatenated fixups for every version in (after, upto], in version
42
+ # order. Returns "" when the hop crosses none.
43
+ #
44
+ # @param after [String, nil] the installed version; nil (no recorded
45
+ # version) applies every fixup up to the target, which is safe because
46
+ # each one is idempotent.
47
+ # @param upto [String] the version being upgraded to
48
+ def fixups_sql(after:, upto: latest_version)
49
+ ceiling = Gem::Version.new(upto)
50
+ floor = after && Gem::Version.new(after)
51
+
52
+ applicable = fixup_versions.select do |version|
53
+ candidate = Gem::Version.new(version)
54
+ candidate <= ceiling && (floor.nil? || candidate > floor)
55
+ end
56
+
57
+ applicable.map { |version| File.read(File.join(FIXUPS_DIR, "pgmq_v#{version}.sql")) }.join("\n")
29
58
  end
30
59
 
31
60
  # Returns the filesystem path to the vendored SQL file for a given version.
@@ -177,6 +206,15 @@ module Pgbus
177
206
 
178
207
  private
179
208
 
209
+ # Vendored versions discovered in a directory, in version order. Schema
210
+ # files and fixups share this so the two can never drift into different
211
+ # discovery rules.
212
+ def versions_in(dir)
213
+ Dir.glob(File.join(dir, "pgmq_v*.sql"))
214
+ .map { |f| File.basename(f).match(/pgmq_v(.+)\.sql/)[1] }
215
+ .sort_by { |v| Gem::Version.new(v) }
216
+ end
217
+
180
218
  # Strips extension-specific blocks (pg_extension_config_dump, pg_depend checks)
181
219
  # that only work when pgmq is installed as an extension.
182
220
  def strip_extension_only_blocks(sql)
data/lib/pgbus/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Pgbus
4
- VERSION = "0.16.7"
4
+ VERSION = "0.17.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pgbus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.16.7
4
+ version: 0.17.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mikael Henriksson
@@ -343,9 +343,11 @@ files:
343
343
  - lib/pgbus/outbox.rb
344
344
  - lib/pgbus/outbox/poller.rb
345
345
  - lib/pgbus/pgmq_schema.rb
346
+ - lib/pgbus/pgmq_schema/fixups/pgmq_v1.13.0.sql
346
347
  - lib/pgbus/pgmq_schema/pgmq_v1.11.0.sql
347
348
  - lib/pgbus/pgmq_schema/pgmq_v1.11.1.sql
348
349
  - lib/pgbus/pgmq_schema/pgmq_v1.12.0.sql
350
+ - lib/pgbus/pgmq_schema/pgmq_v1.13.0.sql
349
351
  - lib/pgbus/process/consumer.rb
350
352
  - lib/pgbus/process/consumer_priority.rb
351
353
  - lib/pgbus/process/dispatcher.rb