active_record_proxy_adapters 0.8.0 → 0.8.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: 8e87a47a033b2402f2fdd0dbae2aec360ff04afbe4639f83615030da82d80cfc
4
- data.tar.gz: 7caec5f8d663d2b67482f28f30b669e36a00fedb8d9eea6b06404ad3df9ce594
3
+ metadata.gz: a5c79bbbfc75972477b105dbee115b4107a12b3a326164c8ef3562c16910609a
4
+ data.tar.gz: d7276cdc0c42fb138fdf662c867ff3e3e2abcb2a2b58904d8080b630f91e6ac6
5
5
  SHA512:
6
- metadata.gz: 65850028f544840668b1aa172a6442665cf9142c1a52934773f433c823fc56365b0251b6188636ccd252f9b33f74c9a40c9578d44953b57e33af842393e92e54
7
- data.tar.gz: eb1c1b67ba524477b2b792d8a23f003f057cd764c4ee2930e9c5613efee9262ea7ba03c18084004b406b26e9c9e770a905733a2164ce6a84d107b172589860b0
6
+ metadata.gz: e0cb991cc6c4f4f49fcdb330e2d4254a13fd0e8b3a10f2ce9cf38f9dac36305c9c0ad148d2660839e354d2fd9b251ce0d92df5c05fd45414b0d1b298cd03df6c
7
+ data.tar.gz: d98aa2d8ddf561875041c9807604e1b13fbda7600bee9b2528cb7a34beb700d0540f9750f69a7d4fa10a0f3074bce71d1ad2f51b28701d018784c68a81edc78d
@@ -7,6 +7,7 @@ module ActiveRecordProxyAdapters
7
7
  class Railtie < Rails::Railtie
8
8
  require "active_record_proxy_adapters/connection_handling"
9
9
  require "active_record_proxy_adapters/middleware"
10
+ require "active_record_proxy_adapters/rake"
10
11
 
11
12
  config.to_prepare do
12
13
  Rails.autoloaders.each do |autoloader|
@@ -22,5 +23,10 @@ module ActiveRecordProxyAdapters
22
23
  initializer "active_record_proxy_adapters.configure_rails_initialization" do |app|
23
24
  app.middleware.use ActiveRecordProxyAdapters::Middleware
24
25
  end
26
+
27
+ rake_tasks do
28
+ ActiveRecordProxyAdapters::Rake.load_tasks
29
+ ActiveRecordProxyAdapters::Rake.enhance_db_tasks
30
+ end
25
31
  end
26
32
  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.8.0"
4
+ VERSION = "0.8.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.8.0
4
+ version: 0.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Cruz
@@ -149,8 +149,10 @@ files:
149
149
  - lib/active_record_proxy_adapters/postgresql_proxy.rb
150
150
  - lib/active_record_proxy_adapters/primary_replica_proxy.rb
151
151
  - lib/active_record_proxy_adapters/railtie.rb
152
+ - lib/active_record_proxy_adapters/rake.rb
152
153
  - lib/active_record_proxy_adapters/sqlite3_proxy.rb
153
154
  - lib/active_record_proxy_adapters/synchronizable_configuration.rb
155
+ - lib/active_record_proxy_adapters/tasks/arpa.rake
154
156
  - lib/active_record_proxy_adapters/transactionable_proxy_a_r_70.rb
155
157
  - lib/active_record_proxy_adapters/trilogy_proxy.rb
156
158
  - lib/active_record_proxy_adapters/version.rb