janus-ar 0.11.0 → 0.13.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4f68517d31773a920a61e251c4f52a38a79027f0a0d6501c425403a9fa69a866
4
- data.tar.gz: d4c21cf0ebc3db473bced580364c5e185fc9d97cf28781cd7b97571ef4148fe4
3
+ metadata.gz: 385d7c8b2d818661697a772e2c32d382bea82e11a01548812d6e0bd50b729eb5
4
+ data.tar.gz: 3314da59cac901b3d453c763d426ffeacafa98586f7530b8dd52421b185ed968
5
5
  SHA512:
6
- metadata.gz: eff2590b57eca7703f4cda808982f46c57a1c728b2b194af5a8b9b18a7d49ad7c0569f7ab394d7f5382fa368802b07f0599d0afa3a45e2476ad97920093c656a
7
- data.tar.gz: cb655011ec0518dd701a668542574c71d700c8eedcf5c361207b55180888a629a2062b25c37d48ea50c21e5478245a4835a87b51dde64ebbe740dc87b1443e94
6
+ metadata.gz: a108987d5c2d0fc9daa7de2b0f934a89f03bc877f6b8fc93c49af724e2aa55727b2a9bd912e5727cb91b16676cdf76bc089e8ffcbef9ca4bfd2132acd90623b1
7
+ data.tar.gz: a4b3fbf3e1b3b9b932454952048441954048ea0571947aa5ede324eb166bf7890bee96e4d0e2d1419cb0b551dc1a19ee47acd04f79e7718d589773e697cdff42
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- janus-ar (0.11.0)
4
+ janus-ar (0.13.0)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
@@ -32,7 +32,7 @@ module ActiveRecord
32
32
  SQL_REPLICA_MATCHERS = [/\A\s*(select|with.+\)\s*select)\s/i].freeze
33
33
  SQL_ALL_MATCHERS = [/\A\s*set\s/i].freeze
34
34
  SQL_SKIP_ALL_MATCHERS = [/\A\s*set\s+local\s/i].freeze
35
- WRITE_PREFIXES = %w(INSERT UPDATE DELETE LOCK CREATE GRANT DROP).freeze
35
+ WRITE_PREFIXES = %w(INSERT UPDATE DELETE LOCK CREATE GRANT DROP ALTER).freeze
36
36
 
37
37
  attr_reader :config
38
38
 
@@ -133,7 +133,7 @@ module ActiveRecord
133
133
  end
134
134
 
135
135
  def write_query?(sql)
136
- WRITE_PREFIXES.include?(sql.split(' ').first)
136
+ WRITE_PREFIXES.include?(sql.upcase.split(' ').first)
137
137
  end
138
138
 
139
139
  def update_config
data/lib/janus/version.rb CHANGED
@@ -4,7 +4,7 @@ module Janus
4
4
  unless defined?(::Janus::VERSION)
5
5
  module VERSION
6
6
  MAJOR = 0
7
- MINOR = 11
7
+ MINOR = 13
8
8
  PATCH = 0
9
9
  PRE = nil
10
10
 
@@ -16,7 +16,7 @@ RSpec.describe ActiveRecord::ConnectionAdapters::JanusMysql2Adapter do
16
16
  }
17
17
  it { expect(described_class::SQL_REPLICA_MATCHERS).to eq([/\A\s*(select|with.+\)\s*select)\s/i]) }
18
18
  it { expect(described_class::SQL_ALL_MATCHERS).to eq([/\A\s*set\s/i]) }
19
- it { expect(described_class::WRITE_PREFIXES).to eq %w(INSERT UPDATE DELETE LOCK CREATE GRANT DROP) }
19
+ it { expect(described_class::WRITE_PREFIXES).to eq %w(INSERT UPDATE DELETE LOCK CREATE GRANT DROP ALTER) }
20
20
 
21
21
  let(:database) { 'test' }
22
22
  let(:primary_config) do
@@ -121,5 +121,25 @@ RSpec.describe ActiveRecord::ConnectionAdapters::JanusMysql2Adapter do
121
121
  expect($query_logger.queries.first).to include '[primary]'
122
122
  end
123
123
  end
124
+
125
+ describe 'INSERT' do
126
+ let(:insert_query) { 'INSERT INTO test_table SET `id` = 5;' }
127
+
128
+ before(:each) do
129
+ create_test_table
130
+ $query_logger.flush_all
131
+ Janus::Context.release_all
132
+ end
133
+
134
+ it 'sends INSERT query to primary' do
135
+ ActiveRecord::Base.connection.execute(insert_query)
136
+ expect($query_logger.queries.first).to include '[primary]'
137
+ end
138
+
139
+ it 'ignores case when directing queries' do
140
+ ActiveRecord::Base.connection.execute(insert_query.downcase)
141
+ expect($query_logger.queries.first).to include '[primary]'
142
+ end
143
+ end
124
144
  end
125
145
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: janus-ar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lloyd Watkin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-04-12 00:00:00.000000000 Z
11
+ date: 2024-04-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord