janus-ar 0.12.0 → 0.14.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a0e77e0c182f105a55bad08e2dd345fae0c4a568fb22c3f85e38f3ce30eb0af0
4
- data.tar.gz: 4c821cafeb65b0c0ed820f43a631e719b3b06dc3dc6d299a5361bfa3cd9f067e
3
+ metadata.gz: 3b4012fc9260dbab0c2d86b585d800968f45dd463e39d63bc512320ce3c78665
4
+ data.tar.gz: 4790e30c5f89242b39174d3ae4de12cb4c848461c494133dbdd4e3f5caee4221
5
5
  SHA512:
6
- metadata.gz: a50fcaaadbf761c1f7bdde29da7df857521340815d0b672217bd02372b23800513beed01382763c765fc4fd4df73e22c7b568e9a7b77cf6156f67d118dea4596
7
- data.tar.gz: a24258c387cbc623f708723e928824db25cffc80c68eaec985ecd649694fb53f5161def1d1fe7215a87c280d885e17cb280871c5ba125b7b78200d27dcb5927c
6
+ metadata.gz: 3d2f60f04c8e234453e61a6a549099e905389b9e845707611cfb4d3f81b93490fbfd8dd9727fa5c90700d3183ec88de4bb4b503e9782baa9b9736879f811916b
7
+ data.tar.gz: b70f8246e567c80c8dba2423127f573a7988483d9e5078c7e9b7efae78d0f6ef6efeb2cbefa58c1b145291f8930b171d255dbfad43adcc85bf03ac0f8dae9d85
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/
@@ -64,7 +64,7 @@ GEM
64
64
  diff-lcs (>= 1.2.0, < 2.0)
65
65
  rspec-support (~> 3.13.0)
66
66
  rspec-support (3.13.1)
67
- rubocop (1.63.0)
67
+ rubocop (1.63.1)
68
68
  json (~> 2.3)
69
69
  language_server-protocol (>= 3.17.0)
70
70
  parallel (~> 1.10)
data/README.md CHANGED
@@ -15,6 +15,8 @@ Janus ActiveRecord is generic primary/replica proxy for ActiveRecord 7.1+ and My
15
15
 
16
16
  Janus is heavily inspired by [Makara](https://github.com/instacart/makara) from TaskRabbit and then Instacart. Unfortunately this project is unmaintained and broke for us with Rails 7.1. This is an attempt to start afresh on the project. It is definitely not as fully featured as Makara at this stage.
17
17
 
18
+ Learn more about its origins: [https://tech.olioex.com/ruby/2024/04/16/introducing-janus.html](https://tech.olioex.com/ruby/2024/04/16/introducing-janus.html).
19
+
18
20
  ## Installation
19
21
 
20
22
  Use the current version of the gem from [rubygems](https://rubygems.org/gems/janus-ar) in your `Gemfile`.
@@ -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 ALTER).freeze
35
+ WRITE_PREFIXES = %w(INSERT UPDATE DELETE LOCK CREATE GRANT DROP ALTER TRUNCATE FLUSH).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 = 12
7
+ MINOR = 14
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 ALTER) }
19
+ it { expect(described_class::WRITE_PREFIXES).to eq %w(INSERT UPDATE DELETE LOCK CREATE GRANT DROP ALTER TRUNCATE FLUSH) }
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.12.0
4
+ version: 0.14.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-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord