janus-ar 0.7.0 → 0.11.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/bin/release.sh +3 -0
- data/lib/active_record/connection_adapters/janus_mysql2_adapter.rb +16 -0
- data/lib/janus/db_console_config.rb +17 -0
- data/lib/janus/version.rb +1 -1
- data/lib/janus.rb +1 -0
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4f68517d31773a920a61e251c4f52a38a79027f0a0d6501c425403a9fa69a866
|
4
|
+
data.tar.gz: d4c21cf0ebc3db473bced580364c5e185fc9d97cf28781cd7b97571ef4148fe4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eff2590b57eca7703f4cda808982f46c57a1c728b2b194af5a8b9b18a7d49ad7c0569f7ab394d7f5382fa368802b07f0599d0afa3a45e2476ad97920093c656a
|
7
|
+
data.tar.gz: cb655011ec0518dd701a668542574c71d700c8eedcf5c361207b55180888a629a2062b25c37d48ea50c21e5478245a4835a87b51dde64ebbe740dc87b1443e94
|
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: gem build && gem push janus-ar-*.gem
|
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.
|
data/bin/release.sh
ADDED
@@ -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
|
@@ -28,6 +36,14 @@ module ActiveRecord
|
|
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
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.11.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
|
@@ -167,10 +167,12 @@ dependencies:
|
|
167
167
|
description: Read/Write proxy for ActiveRecord using primary/replica databases
|
168
168
|
email:
|
169
169
|
- lloyd@olioex.com
|
170
|
-
executables:
|
170
|
+
executables:
|
171
|
+
- release.sh
|
171
172
|
extensions: []
|
172
173
|
extra_rdoc_files: []
|
173
174
|
files:
|
175
|
+
- ".bundle/config"
|
174
176
|
- ".github/dependabot.yml"
|
175
177
|
- ".github/workflows/ci.yml"
|
176
178
|
- ".github/workflows/publish.yml"
|
@@ -184,10 +186,12 @@ files:
|
|
184
186
|
- README.md
|
185
187
|
- assets/.gitkeep
|
186
188
|
- assets/janus-logo.png
|
189
|
+
- bin/release.sh
|
187
190
|
- janus-ar.gemspec
|
188
191
|
- lib/active_record/connection_adapters/janus_mysql2_adapter.rb
|
189
192
|
- lib/janus.rb
|
190
193
|
- lib/janus/context.rb
|
194
|
+
- lib/janus/db_console_config.rb
|
191
195
|
- lib/janus/logging/logger.rb
|
192
196
|
- lib/janus/logging/subscriber.rb
|
193
197
|
- lib/janus/version.rb
|