-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
POC code to show savepoints from subsequent appends in transaction
Related: #1108
- Loading branch information
1 parent
6be5f60
commit 8dbabc0
Showing
1 changed file
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
require "bundler/inline" | ||
|
||
gemfile do | ||
source "https://rubygems.org" | ||
gem "ruby_event_store", path: ".." | ||
gem "ruby_event_store-active_record", path: "." | ||
gem "pg" | ||
gem "childprocess" | ||
gem "benchmark-ips" | ||
end | ||
|
||
require "ruby_event_store" | ||
require "ruby_event_store/active_record" | ||
|
||
require_relative "../support/helpers/migrator" | ||
require_relative "../support/helpers/schema_helper" | ||
|
||
include SchemaHelper | ||
establish_database_connection | ||
drop_database | ||
load_database_schema | ||
|
||
event_store = | ||
RubyEventStore::Client.new( | ||
repository: | ||
RubyEventStore::ActiveRecord::EventRepository.new( | ||
serializer: RubyEventStore::NULL | ||
) | ||
) | ||
|
||
mk_event = | ||
lambda { RubyEventStore::Event.new(metadata: { event_type: "whatever" }) } | ||
|
||
logged_keywords = %w[COMMIT BEGIN SAVEPOINT RELEASE].freeze | ||
|
||
log_transaction = | ||
lambda do |name, started, finished, unique_id, payload| | ||
if logged_keywords.any? { |keyword| payload[:sql].start_with? keyword } | ||
puts payload[:sql] | ||
end | ||
end | ||
|
||
ActiveSupport::Notifications.subscribed(log_transaction, /sql/) do | ||
ActiveRecord::Base.transaction do | ||
100.times { event_store.append(mk_event.call) } | ||
end | ||
end |