sequel-pgt_outbox 0.2.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.
- checksums.yaml +7 -0
- data/.overcommit.yml +345 -0
- data/.rubocop.yml +19 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +132 -0
- data/LICENSE.txt +21 -0
- data/Rakefile +31 -0
- data/Readme.adoc +82 -0
- data/ci/build_image.sh +257 -0
- data/ci/publish-gem.sh +77 -0
- data/lib/sequel/extensions/pgt_outbox.rb +17 -0
- data/lib/sequel/pgt_outbox/database_methods.rb +12 -0
- data/lib/sequel/pgt_outbox/function.rb +66 -0
- data/lib/sequel/pgt_outbox/table.rb +161 -0
- data/lib/sequel/pgt_outbox/trigger.rb +51 -0
- data/lib/sequel/pgt_outbox/version.rb +9 -0
- data/lib/sequel/pgt_outbox.rb +56 -0
- data/sig/sequel/pgt_outbox.rbs +6 -0
- metadata +78 -0
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'sequel'
|
4
|
+
require 'sequel_postgresql_triggers'
|
5
|
+
Sequel.extension :pg_triggers
|
6
|
+
require_relative 'pgt_outbox/version'
|
7
|
+
|
8
|
+
module Rubyists
|
9
|
+
# The main namespace for the PgtOutbox library
|
10
|
+
module PgtOutbox
|
11
|
+
DEFINITION = proc do
|
12
|
+
def pgt_outbox_setup(table, opts = {})
|
13
|
+
outbox = Rubyists::PgtOutbox.outbox_table(table, self, opts:)
|
14
|
+
pgt_created_at outbox.name, outbox.created_column
|
15
|
+
pgt_updated_at outbox.name, outbox.updated_column
|
16
|
+
outbox.function.name
|
17
|
+
end
|
18
|
+
|
19
|
+
def pgt_outbox_events(table, function, events: %i[insert update delete], when: nil, opts: {})
|
20
|
+
Rubyists::PgtOutbox::Trigger.create!(self, table, function, events:, opts: opts.merge(when:))
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.outbox_table(table, db, opts: {})
|
25
|
+
require_relative 'pgt_outbox/table'
|
26
|
+
require_relative 'pgt_outbox/trigger'
|
27
|
+
Table.create!(table, db, opts:)
|
28
|
+
end
|
29
|
+
|
30
|
+
# Helper instance methods
|
31
|
+
|
32
|
+
# Guards against recursive triggers
|
33
|
+
# NOTE: Taken from sequel_postgresql_triggers
|
34
|
+
# @param [Integer] depth_limit The maximum trigger depth to allow before returning NEW
|
35
|
+
def depth_guard_clause(depth_limit = nil)
|
36
|
+
return unless depth_limit
|
37
|
+
|
38
|
+
depth_limit = 1 if depth_limit == true
|
39
|
+
depth_limit = depth_limit.to_i
|
40
|
+
raise ArgumentError, ':trigger_depth_limit option must be at least 1' unless depth_limit >= 1
|
41
|
+
|
42
|
+
<<-SQL
|
43
|
+
IF pg_trigger_depth() > #{depth_limit} THEN
|
44
|
+
RETURN NEW;
|
45
|
+
END IF;
|
46
|
+
SQL
|
47
|
+
end
|
48
|
+
|
49
|
+
# Mangle the schema name so it can be used in an unquoted_identifier
|
50
|
+
# NOTE: Taken from sequel_postgresql_triggers
|
51
|
+
# @param [String] table The table name to mangle
|
52
|
+
def mangled_table_name(db, table)
|
53
|
+
db.send(:quote_schema_table, table).gsub('"', '').gsub(/[^A-Za-z0-9]/, '_').gsub(/_+/, '_')
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
metadata
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sequel-pgt_outbox
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- bougyman
|
8
|
+
bindir: exe
|
9
|
+
cert_chain: []
|
10
|
+
date: 2025-02-15 00:00:00.000000000 Z
|
11
|
+
dependencies:
|
12
|
+
- !ruby/object:Gem::Dependency
|
13
|
+
name: sequel_postgresql_triggers
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - "~>"
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: '1.6'
|
19
|
+
type: :runtime
|
20
|
+
prerelease: false
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
requirements:
|
23
|
+
- - "~>"
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: '1.6'
|
26
|
+
description: This implements a configurable outbox and triggers to populate it with
|
27
|
+
events. See https://microservices.io/patterns/data/transactional-outbox.html for
|
28
|
+
details. To be this clear, this only handles the insert of events into the outbox
|
29
|
+
email:
|
30
|
+
- bougyman@users.noreply.github.com
|
31
|
+
executables: []
|
32
|
+
extensions: []
|
33
|
+
extra_rdoc_files: []
|
34
|
+
files:
|
35
|
+
- ".overcommit.yml"
|
36
|
+
- ".rubocop.yml"
|
37
|
+
- CHANGELOG.md
|
38
|
+
- CODE_OF_CONDUCT.md
|
39
|
+
- LICENSE.txt
|
40
|
+
- Rakefile
|
41
|
+
- Readme.adoc
|
42
|
+
- ci/build_image.sh
|
43
|
+
- ci/publish-gem.sh
|
44
|
+
- lib/sequel/extensions/pgt_outbox.rb
|
45
|
+
- lib/sequel/pgt_outbox.rb
|
46
|
+
- lib/sequel/pgt_outbox/database_methods.rb
|
47
|
+
- lib/sequel/pgt_outbox/function.rb
|
48
|
+
- lib/sequel/pgt_outbox/table.rb
|
49
|
+
- lib/sequel/pgt_outbox/trigger.rb
|
50
|
+
- lib/sequel/pgt_outbox/version.rb
|
51
|
+
- sig/sequel/pgt_outbox.rbs
|
52
|
+
homepage: https://github.com/rubyists/sequel-pgt_outbox
|
53
|
+
licenses:
|
54
|
+
- MIT
|
55
|
+
metadata:
|
56
|
+
allowed_push_host: https://rubygems.org
|
57
|
+
homepage_uri: https://github.com/rubyists/sequel-pgt_outbox
|
58
|
+
source_code_uri: https://github.com/rubyists/sequel-pgt_outbox
|
59
|
+
changelog_uri: https://github.com/rubyists/sequel-pgt_outbox/blob/main/CHANGELOG.md
|
60
|
+
rubygems_mfa_required: 'true'
|
61
|
+
rdoc_options: []
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 3.3.0
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
requirements: []
|
75
|
+
rubygems_version: 3.6.3
|
76
|
+
specification_version: 4
|
77
|
+
summary: Triggers to implement a transaction outbox pattern.
|
78
|
+
test_files: []
|