active_record_proxy_adapters 0.9.0 → 0.9.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f404b61f94eec82c838124e111eba202e7fdbea61c07596739219749e7c76ac2
4
- data.tar.gz: 930327b485fb9b7637a1b810c0cb52def9d0164777103f918862a9dd4a0a89e7
3
+ metadata.gz: f8eb66dc7f981575d9694d06749bd555f097e0304e479cef138271e4625c292d
4
+ data.tar.gz: 94671f1e33f3b48041e77fbb8f63c4f8044ffc719cfff0c434a68a96c6d11ac7
5
5
  SHA512:
6
- metadata.gz: 4d0c6210521feb5db9ce40fc476607fb862d818e16feb23d795e95f20f20b8db0b1311049a5895f6e9795ba2740cdef140ecb6ec67f5f1c7c7aec759e0a4c2ca
7
- data.tar.gz: 1134342f6be3093cb5a3ddaba514ef702adb611e5646a3abd3c68073fcb7060459a39a5845983733b4c5f0bc24d5928f57e8333b7741bbb8b3fa812d9472f066
6
+ metadata.gz: db126cae318181a3598d821a58801c33a9658fee002b93263e6c73dcee9d3c67362d76543aa0d9787ce6aa8cf28e054f646212aa3cc9c88d1afe63e19dc5257f
7
+ data.tar.gz: 7f21d5c7c4dd96ae1c0636523b039fddecd4cf0dc41e4af5cd6ce4907502da07792196be15734708a061d348010ff635e18fea8e6457e8b51cb308d526d898a4
@@ -18,21 +18,13 @@ module ActiveRecordProxyAdapters
18
18
  end
19
19
 
20
20
  def hijackable_methods
21
- hijackable = %i[execute exec_query]
22
-
23
- hijackable << :internal_exec_query if active_record_v7_1_or_greater?
24
-
25
- hijackable
21
+ %i[execute exec_query internal_exec_query]
26
22
  end
27
23
 
28
24
  def active_record_v7?
29
25
  active_record_version >= Gem::Version.new("7.1") && active_record_version < Gem::Version.new("8.0")
30
26
  end
31
27
 
32
- def active_record_v7_1_or_greater?
33
- active_record_version >= Gem::Version.new("7.1")
34
- end
35
-
36
28
  def active_record_v7_2_or_greater?
37
29
  active_record_version >= Gem::Version.new("7.2")
38
30
  end
@@ -160,8 +160,7 @@ module ActiveRecordProxyAdapters
160
160
  end
161
161
 
162
162
  def pending_migration_connection?
163
- active_record_context.active_record_v7_1_or_greater? &&
164
- connection_class.name == "ActiveRecord::PendingMigrationConnection"
163
+ connection_class.name == "ActiveRecord::PendingMigrationConnection"
165
164
  end
166
165
 
167
166
  def connection_for(role, sql_string)
@@ -11,9 +11,15 @@ module ActiveRecordProxyAdapters
11
11
  # Hooks into rails boot process to extend ActiveRecord with the proxy adapter.
12
12
  class Railtie < Rails::Railtie
13
13
  require "active_record_proxy_adapters/middleware"
14
+ require "active_record_proxy_adapters/rake"
14
15
 
15
16
  initializer "active_record_proxy_adapters.configure_rails_initialization" do |app|
16
17
  app.middleware.use ActiveRecordProxyAdapters::Middleware
17
18
  end
19
+
20
+ rake_tasks do
21
+ ActiveRecordProxyAdapters::Rake.load_tasks
22
+ ActiveRecordProxyAdapters::Rake.enhance_db_tasks
23
+ end
18
24
  end
19
25
  end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rake"
4
+
5
+ module ActiveRecordProxyAdapters
6
+ # Enhances all rails db rake tasks to stick to writer connection
7
+ module Rake
8
+ module_function
9
+
10
+ def load_tasks
11
+ Dir[rake_tasks_path].each { |rake_path| load(rake_path) }
12
+ end
13
+
14
+ def rake_tasks_path
15
+ File.join(__dir__, "tasks/**/*.rake")
16
+ end
17
+
18
+ def enhance_db_tasks
19
+ ::Rake::Task
20
+ .tasks
21
+ .select(&enhanceable_db_task?)
22
+ .each { |task| task.enhance([push_to_stack_rake_task.name], &pop_from_stack_and_reenable) }
23
+ end
24
+
25
+ def push_to_stack_rake_task
26
+ ::Rake::Task["arpa:push_to_stack"]
27
+ end
28
+
29
+ def pop_from_stack_rake_task
30
+ ::Rake::Task["arpa:pop_from_stack"]
31
+ end
32
+
33
+ def pop_from_stack_and_reenable
34
+ proc do
35
+ pop_from_stack_rake_task.invoke
36
+ [push_to_stack_rake_task, pop_from_stack_rake_task].each(&:reenable)
37
+ end
38
+ end
39
+
40
+ def enhanceable_db_task?
41
+ proc do |task|
42
+ task_name = task.name
43
+ task_name.start_with?("db:") && task_name != "db:load_config"
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ namespace :arpa do
4
+ desc "Pushes to connected_to stack before rake task is executed"
5
+ task :push_to_stack do
6
+ writing_role = ActiveRecordProxyAdapters::ActiveRecordContext.writing_role
7
+
8
+ ActiveRecord::Base.connected_to_stack << {
9
+ role: writing_role,
10
+ shard: nil,
11
+ prevent_writes: false,
12
+ klasses: [ActiveRecord::Base]
13
+ }
14
+
15
+ Thread.current.thread_variable_set(:arpa_rake_pushed_to_stack, true)
16
+ end
17
+
18
+ desc "Pops from connected_to stack after rake task is invoked"
19
+ task :pop_from_stack do
20
+ if Thread.current.thread_variable_get(:arpa_rake_pushed_to_stack)
21
+ ActiveRecord::Base.connected_to_stack.pop
22
+ Thread.current.thread_variable_set(:arpa_rake_pushed_to_stack, nil)
23
+ end
24
+ end
25
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveRecordProxyAdapters
4
- VERSION = "0.9.0"
4
+ VERSION = "0.9.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_record_proxy_adapters
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Cruz
@@ -154,8 +154,10 @@ files:
154
154
  - lib/active_record_proxy_adapters/railties/postgresql.rb
155
155
  - lib/active_record_proxy_adapters/railties/sqlite3.rb
156
156
  - lib/active_record_proxy_adapters/railties/trilogy.rb
157
+ - lib/active_record_proxy_adapters/rake.rb
157
158
  - lib/active_record_proxy_adapters/sqlite3_proxy.rb
158
159
  - lib/active_record_proxy_adapters/synchronizable_configuration.rb
160
+ - lib/active_record_proxy_adapters/tasks/arpa.rake
159
161
  - lib/active_record_proxy_adapters/trilogy_proxy.rb
160
162
  - lib/active_record_proxy_adapters/version.rb
161
163
  homepage: https://github.com/Nasdaq/active_record_proxy_adapters