janus-ar 0.9.0 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.bundle/config +5 -0
- data/.github/workflows/publish.yml +14 -9
- data/.gitignore +0 -1
- data/Gemfile.lock +1 -1
- data/README.md +5 -3
- data/lib/active_record/connection_adapters/janus_mysql2_adapter.rb +17 -1
- data/lib/janus/db_console_config.rb +17 -0
- data/lib/janus/version.rb +1 -1
- data/lib/janus.rb +1 -0
- data/spec/lib/active_record/connection_adapters/janus_mysql_adapter_spec.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a0e77e0c182f105a55bad08e2dd345fae0c4a568fb22c3f85e38f3ce30eb0af0
|
4
|
+
data.tar.gz: 4c821cafeb65b0c0ed820f43a631e719b3b06dc3dc6d299a5361bfa3cd9f067e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a50fcaaadbf761c1f7bdde29da7df857521340815d0b672217bd02372b23800513beed01382763c765fc4fd4df73e22c7b568e9a7b77cf6156f67d118dea4596
|
7
|
+
data.tar.gz: a24258c387cbc623f708723e928824db25cffc80c68eaec985ecd649694fb53f5161def1d1fe7215a87c280d885e17cb280871c5ba125b7b78200d27dcb5927c
|
data/.bundle/config
ADDED
@@ -5,16 +5,21 @@ on:
|
|
5
5
|
tags:
|
6
6
|
- v*
|
7
7
|
jobs:
|
8
|
-
|
8
|
+
push:
|
9
9
|
runs-on: ubuntu-latest
|
10
10
|
|
11
|
+
permissions:
|
12
|
+
contents: write
|
13
|
+
id-token: write
|
14
|
+
|
11
15
|
steps:
|
12
|
-
|
16
|
+
# Set up
|
17
|
+
- uses: actions/checkout@v4
|
18
|
+
- name: Set up Ruby
|
19
|
+
uses: ruby/setup-ruby@v1
|
20
|
+
with:
|
21
|
+
bundler-cache: true
|
22
|
+
ruby-version: ruby
|
13
23
|
|
14
|
-
|
15
|
-
|
16
|
-
uses: cadwallion/publish-rubygems-action@master
|
17
|
-
env:
|
18
|
-
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
|
19
|
-
RUBYGEMS_API_KEY: ${{secrets.RUBYGEMS_API_KEY}}
|
20
|
-
RELEASE_COMMAND: ./bin/release.sh
|
24
|
+
# Release
|
25
|
+
- uses: rubygems/release-gem@v1
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -6,11 +6,11 @@
|
|
6
6
|
style="float: left; margin: 0 auto; height: 500px;" />
|
7
7
|
</p>
|
8
8
|
|
9
|
+
> In ancient Roman religion and myth, Janus (/ˈdʒeɪnəs/ JAY-nəs; Latin: Ianvs [ˈi̯aːnʊs]) is the god of beginnings, gates, transitions, time, duality, doorways,[2] passages, frames, and endings. [(wikipedia)](https://en.wikipedia.org/wiki/Janus)
|
10
|
+
|
9
11
|
[![CI](https://github.com/OLIOEX/janus-ar/actions/workflows/ci.yml/badge.svg)](https://github.com/OLIOEX/janus-ar/actions/workflows/ci.yml)
|
10
12
|
[![Gem Version](https://badge.fury.io/rb/janus-ar.svg)](https://badge.fury.io/rb/janus-ar)
|
11
13
|
|
12
|
-
> In ancient Roman religion and myth, Janus (/ˈdʒeɪnəs/ JAY-nəs; Latin: Ianvs [ˈi̯aːnʊs]) is the god of beginnings, gates, transitions, time, duality, doorways,[2] passages, frames, and endings. [(wikipedia)](https://en.wikipedia.org/wiki/Janus)
|
13
|
-
|
14
14
|
Janus ActiveRecord is generic primary/replica proxy for ActiveRecord 7.1+ and MySQL. It handles the switching of connections between primary and replica database servers. It comes with an ActiveRecord database adapter implementation.
|
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.
|
@@ -68,12 +68,14 @@ Janus::Context.stick_to_primary
|
|
68
68
|
|
69
69
|
### Logging
|
70
70
|
|
71
|
-
You can set a logger instance to
|
71
|
+
You can set a logger instance to `::Janus::Logging::Logger.logger`:
|
72
72
|
|
73
73
|
```ruby
|
74
74
|
Janus::Logging::Logger.logger = ::Logger.new(STDOUT)
|
75
75
|
```
|
76
76
|
|
77
|
+
If using `ActiveRecord` logging, Janus will append the name of the connection used to any logs e.g. `[primary]` or `[replica]`.
|
78
|
+
|
77
79
|
### What queries goes where?
|
78
80
|
|
79
81
|
In general: Any `SELECT` statements will execute against your replica(s), anything else will go to the primary.
|
@@ -12,6 +12,14 @@ module ActiveRecord
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
+
module ActiveRecord
|
16
|
+
class Base
|
17
|
+
def self.janus_mysql2_adapter_class
|
18
|
+
ActiveRecord::ConnectionAdapters::JanusMysql2Adapter
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
15
23
|
module ActiveRecord
|
16
24
|
module ConnectionAdapters
|
17
25
|
class JanusMysql2Adapter < ActiveRecord::ConnectionAdapters::Mysql2Adapter
|
@@ -24,10 +32,18 @@ module ActiveRecord
|
|
24
32
|
SQL_REPLICA_MATCHERS = [/\A\s*(select|with.+\)\s*select)\s/i].freeze
|
25
33
|
SQL_ALL_MATCHERS = [/\A\s*set\s/i].freeze
|
26
34
|
SQL_SKIP_ALL_MATCHERS = [/\A\s*set\s+local\s/i].freeze
|
27
|
-
WRITE_PREFIXES = %w(INSERT UPDATE DELETE LOCK CREATE GRANT DROP).freeze
|
35
|
+
WRITE_PREFIXES = %w(INSERT UPDATE DELETE LOCK CREATE GRANT DROP ALTER).freeze
|
28
36
|
|
29
37
|
attr_reader :config
|
30
38
|
|
39
|
+
class << self
|
40
|
+
def dbconsole(config, options = {})
|
41
|
+
connection_config = Janus::DbConsoleConfig.new(config)
|
42
|
+
|
43
|
+
super(connection_config, options)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
31
47
|
def initialize(*args)
|
32
48
|
args[0][:janus]['replica']['database'] = args[0][:database]
|
33
49
|
args[0][:janus]['primary']['database'] = args[0][:database]
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Janus
|
4
|
+
class DbConsoleConfig
|
5
|
+
def initialize(config)
|
6
|
+
@_config = config.configuration_hash
|
7
|
+
end
|
8
|
+
|
9
|
+
def configuration_hash
|
10
|
+
@_config[:janus]['replica'].symbolize_keys
|
11
|
+
end
|
12
|
+
|
13
|
+
def database
|
14
|
+
@_config[:database]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/janus/version.rb
CHANGED
data/lib/janus.rb
CHANGED
@@ -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
|
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.
|
4
|
+
version: 0.12.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-
|
11
|
+
date: 2024-04-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -172,6 +172,7 @@ executables:
|
|
172
172
|
extensions: []
|
173
173
|
extra_rdoc_files: []
|
174
174
|
files:
|
175
|
+
- ".bundle/config"
|
175
176
|
- ".github/dependabot.yml"
|
176
177
|
- ".github/workflows/ci.yml"
|
177
178
|
- ".github/workflows/publish.yml"
|
@@ -190,6 +191,7 @@ files:
|
|
190
191
|
- lib/active_record/connection_adapters/janus_mysql2_adapter.rb
|
191
192
|
- lib/janus.rb
|
192
193
|
- lib/janus/context.rb
|
194
|
+
- lib/janus/db_console_config.rb
|
193
195
|
- lib/janus/logging/logger.rb
|
194
196
|
- lib/janus/logging/subscriber.rb
|
195
197
|
- lib/janus/version.rb
|
@@ -217,7 +219,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
217
219
|
- !ruby/object:Gem::Version
|
218
220
|
version: '0'
|
219
221
|
requirements: []
|
220
|
-
rubygems_version: 3.5.
|
222
|
+
rubygems_version: 3.5.7
|
221
223
|
signing_key:
|
222
224
|
specification_version: 4
|
223
225
|
summary: Read/Write proxy for ActiveRecord using primary/replica databases
|