iron_trail 0.3.0.pre.alpha1 → 0.3.0.pre.alpha3

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: 5f71f8c85d8b8b0bb81528cba7696a279cd012a85035f4882f61607a4f032778
4
- data.tar.gz: b9aaf678019f278724a510cfd6df566288976939dda0f5f37aa67b01538a9ab4
3
+ metadata.gz: 25117e0591f067570aa8feed5b58cde1c01c09a0fdb386b48fe80e9349684ac4
4
+ data.tar.gz: e73f15bcc8bb2c2e26e6a1f9de39ecf6517e1f60489d9a795df863c0e082c207
5
5
  SHA512:
6
- metadata.gz: 56f449260f7c0f83cde52d4311e370828bf2a4d0250f6490003de296066e2717f56afebc969dfe97d74fba2ecefd1a43d72236bdc32450ce7384f1e3b8fc9a56
7
- data.tar.gz: 1b3ce44bad0e293d3c6eb38e21d1d076713ff53240bce114bcb5504f74457db94dc4978cfacb8d182ec590ae08aa5d67008d2e06a923bf8ae17aacaa05053fec
6
+ metadata.gz: 87ae15bd0c12904c32d7bc10d4d89eb8a50e719a0ca3eb518bebf42eef5383c860eb165251bb8406a3ae63497541e3cdbf676066f1e3fa354af7bb07d28b15a0
7
+ data.tar.gz: 975ba22ccae12a3d90f9b7fbb35cc837b1c2d93c7fbbb1abe271724f62480450b72c8999fcfcc640079c7646e26539967cee504674ec8caba370ec66e65caa09
@@ -66,7 +66,9 @@ module IronTrail
66
66
  # This works by inspecting whether there are any keys in the rec_delta column
67
67
  # other than the columns specified in the `columns` parameter.
68
68
  def with_delta_other_than(*columns)
69
- quoted_columns = columns.map { |col_name| connection.quote(col_name) }
69
+ quoted_columns = with_connection do |conn|
70
+ columns.map { |col_name| conn.quote(col_name) }
71
+ end
70
72
  exclude_array = "ARRAY[#{quoted_columns.join(', ')}]::text[]"
71
73
 
72
74
  sql = "rec_delta IS NULL OR (rec_delta - #{exclude_array}) <> '{}'::jsonb"
@@ -79,17 +81,19 @@ module IronTrail
79
81
  ary_index = Integer(ary_index)
80
82
  scope = all
81
83
 
82
- args.each do |col_name, value|
83
- col_delta = "rec_delta->#{connection.quote(col_name)}"
84
- node = if value == nil
85
- ::Arel::Nodes::SqlLiteral.new("#{col_delta}->#{ary_index} = 'null'::jsonb")
86
- else
87
- ::Arel::Nodes::SqlLiteral.new("#{col_delta}->>#{ary_index}").eq(
88
- ::Arel::Nodes::BindParam.new(value.to_s)
89
- )
84
+ with_connection do |conn|
85
+ args.each do |col_name, value|
86
+ col_delta = "rec_delta->#{conn.quote(col_name)}"
87
+ node = if value == nil
88
+ ::Arel::Nodes::SqlLiteral.new("#{col_delta}->#{ary_index} = 'null'::jsonb")
89
+ else
90
+ ::Arel::Nodes::SqlLiteral.new("#{col_delta}->>#{ary_index}").eq(
91
+ ::Arel::Nodes::BindParam.new(value.to_s)
92
+ )
93
+ end
94
+
95
+ scope.where!(node)
90
96
  end
91
-
92
- scope.where!(node)
93
97
  end
94
98
 
95
99
  scope
@@ -27,7 +27,7 @@ module IronTrail
27
27
  attr_accessor :enabled
28
28
 
29
29
  def enable!
30
- with_connection { |conn| DbFunctions.new(conn).install_functions }
30
+ ActiveRecord::Base.with_connection { |conn| DbFunctions.new(conn).install_functions }
31
31
  @enabled = true
32
32
  end
33
33
 
@@ -44,7 +44,7 @@ module IronTrail
44
44
  $$ LANGUAGE plpgsql;
45
45
  SQL
46
46
 
47
- with_connection { |conn| conn.execute(sql) }
47
+ ActiveRecord::Base.with_connection { |conn| conn.execute(sql) }
48
48
  @enabled = false
49
49
  end
50
50
 
@@ -65,20 +65,6 @@ module IronTrail
65
65
  ::IronTrail::Testing.enable!
66
66
  end
67
67
  end
68
-
69
- private
70
-
71
- # Checks out a connection for the duration of the block, mirroring
72
- # ActiveRecord::Base.with_connection (Rails 7.2+). On Rails 7.1, where
73
- # that method does not exist yet, it falls back to yielding the
74
- # (soft-deprecated on Rails 8.1+) ActiveRecord::Base.connection.
75
- def with_connection(&block)
76
- if ActiveRecord::Base.respond_to?(:with_connection)
77
- ActiveRecord::Base.with_connection(&block)
78
- else
79
- yield ActiveRecord::Base.connection
80
- end
81
- end
82
68
  end
83
69
  end
84
70
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_literal_string: true
2
2
 
3
3
  module IronTrail
4
- VERSION = '0.3.0-alpha1'
4
+ VERSION = '0.3.0-alpha3'
5
5
  end
@@ -2,8 +2,8 @@
2
2
 
3
3
  module IronTrail::RakeHelper
4
4
  class << self
5
- def db_functions
6
- IronTrail::DbFunctions.new(ActiveRecord::Base.connection)
5
+ def db_functions(connection)
6
+ IronTrail::DbFunctions.new(connection)
7
7
  end
8
8
 
9
9
  def abort_when_unsafe!
@@ -22,28 +22,33 @@ namespace :iron_trail do
22
22
  namespace :tracking do
23
23
  desc 'Enables tracking for all missing tables.'
24
24
  task enable: :environment do
25
- tables = IronTrail::RakeHelper.db_functions.collect_tables_tracking_status[:missing]
26
- unless tables.length > 0
27
- puts "All tables are being tracked already (no missing tables found)."
28
- puts "If you think this is wrong, check your ignored_tables list."
29
- return
30
- end
31
-
32
- puts "Will start tracking #{tables.length} tables."
33
- tables.each do |table_name|
34
- IronTrail::RakeHelper.db_functions.enable_tracking_for_table(table_name)
25
+ ActiveRecord::Base.with_connection do |conn|
26
+ db_functions = IronTrail::RakeHelper.db_functions(conn)
27
+ tables = db_functions.collect_tables_tracking_status[:missing]
28
+
29
+ if tables.empty?
30
+ puts "All tables are being tracked already (no missing tables found)."
31
+ puts "If you think this is wrong, check your ignored_tables list."
32
+ else
33
+ puts "Will start tracking #{tables.length} tables."
34
+ tables.each do |table_name|
35
+ db_functions.enable_tracking_for_table(table_name)
36
+ end
37
+ end
35
38
  end
36
39
  end
37
40
 
38
41
  desc 'Disabled tracking for any ignored table that might still have the trigger enabled.'
39
42
  task disable_on_ignored: :environment do
40
- affected_tables = IronTrail::RakeHelper.db_functions.disable_for_all_ignored_tables
43
+ ActiveRecord::Base.with_connection do |conn|
44
+ affected_tables = IronTrail::RakeHelper.db_functions(conn).disable_for_all_ignored_tables
41
45
 
42
- unless affected_tables.empty?
43
- puts "Removed tracking from #{affected_tables.length} tables:"
46
+ unless affected_tables.empty?
47
+ puts "Removed tracking from #{affected_tables.length} tables:"
44
48
 
45
- affected_tables.each do |table_name|
46
- puts "\t#{table_name}"
49
+ affected_tables.each do |table_name|
50
+ puts "\t#{table_name}"
51
+ end
47
52
  end
48
53
  end
49
54
  end
@@ -52,24 +57,30 @@ namespace :iron_trail do
52
57
  task disable: :environment do
53
58
  IronTrail::RakeHelper.abort_when_unsafe!
54
59
 
55
- tables = IronTrail::RakeHelper.db_functions.collect_tables_tracking_status[:tracked]
56
- puts "Will stop tracking #{tables.length} tables."
57
- tables.each do |table_name|
58
- IronTrail::RakeHelper.db_functions.disable_tracking_for_table(table_name)
59
- end
60
+ ActiveRecord::Base.with_connection do |conn|
61
+ db_functions = IronTrail::RakeHelper.db_functions(conn)
60
62
 
61
- tables = IronTrail::RakeHelper.db_functions.collect_tables_tracking_status[:tracked]
62
- if tables.length > 0
63
- puts "WARNING: Something went wrong. There are still #{tables.length}" + \
64
- " tables being tracked."
65
- else
66
- puts "Done!"
63
+ tables = db_functions.collect_tables_tracking_status[:tracked]
64
+ puts "Will stop tracking #{tables.length} tables."
65
+ tables.each do |table_name|
66
+ db_functions.disable_tracking_for_table(table_name)
67
+ end
68
+
69
+ tables = db_functions.collect_tables_tracking_status[:tracked]
70
+ if tables.length > 0
71
+ puts "WARNING: Something went wrong. There are still #{tables.length}" + \
72
+ " tables being tracked."
73
+ else
74
+ puts "Done!"
75
+ end
67
76
  end
68
77
  end
69
78
 
70
79
  desc 'Shows which tables are tracking, missing and ignored.'
71
80
  task status: :environment do
72
- status = IronTrail::RakeHelper.db_functions.collect_tables_tracking_status
81
+ status = ActiveRecord::Base.with_connection do |conn|
82
+ IronTrail::RakeHelper.db_functions(conn).collect_tables_tracking_status
83
+ end
73
84
  ignored = (IronTrail.config.ignored_tables || [])
74
85
 
75
86
  # We likely want to keep this structure of text untouched as someone
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iron_trail
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0.pre.alpha1
4
+ version: 0.3.0.pre.alpha3
5
5
  platform: ruby
6
6
  authors:
7
7
  - André Diego Piske
@@ -15,14 +15,14 @@ dependencies:
15
15
  requirements:
16
16
  - - ">="
17
17
  - !ruby/object:Gem::Version
18
- version: '7.1'
18
+ version: '8.0'
19
19
  type: :runtime
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
23
  - - ">="
24
24
  - !ruby/object:Gem::Version
25
- version: '7.1'
25
+ version: '8.0'
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: appraisal
28
28
  requirement: !ruby/object:Gem::Requirement
@@ -77,14 +77,14 @@ dependencies:
77
77
  requirements:
78
78
  - - "~>"
79
79
  - !ruby/object:Gem::Version
80
- version: '1.2'
80
+ version: '1.6'
81
81
  type: :development
82
82
  prerelease: false
83
83
  version_requirements: !ruby/object:Gem::Requirement
84
84
  requirements:
85
85
  - - "~>"
86
86
  - !ruby/object:Gem::Version
87
- version: '1.2'
87
+ version: '1.6'
88
88
  - !ruby/object:Gem::Dependency
89
89
  name: json
90
90
  requirement: !ruby/object:Gem::Requirement
@@ -105,14 +105,14 @@ dependencies:
105
105
  requirements:
106
106
  - - "~>"
107
107
  - !ruby/object:Gem::Version
108
- version: '7.2'
108
+ version: '8.0'
109
109
  type: :development
110
110
  prerelease: false
111
111
  version_requirements: !ruby/object:Gem::Requirement
112
112
  requirements:
113
113
  - - "~>"
114
114
  - !ruby/object:Gem::Version
115
- version: '7.2'
115
+ version: '8.0'
116
116
  email: andrepiske@gmail.com
117
117
  executables: []
118
118
  extensions: []
@@ -159,7 +159,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
159
159
  requirements:
160
160
  - - ">="
161
161
  - !ruby/object:Gem::Version
162
- version: 3.1.0
162
+ version: 3.3.0
163
163
  required_rubygems_version: !ruby/object:Gem::Requirement
164
164
  requirements:
165
165
  - - ">="