janus-ar 0.9.0 → 0.11.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: 9fdf4d3725380dbdf4fc2bcf1d60d3135d4d45a37976eac826d5733ddd7fc8fa
4
- data.tar.gz: e3e24f00234a1eab55e2493d8a497a5c7c3916830d629b0f54ce20fc435bbffe
3
+ metadata.gz: 4f68517d31773a920a61e251c4f52a38a79027f0a0d6501c425403a9fa69a866
4
+ data.tar.gz: d4c21cf0ebc3db473bced580364c5e185fc9d97cf28781cd7b97571ef4148fe4
5
5
  SHA512:
6
- metadata.gz: eed5d877a0aeece9d905d0b1092b345f5788fbc15533cc59eee878d69c5e0fe76f4af968ce0d85a5dce9d2cd1f49fe6e9a035fb2add54a2be39c8abe1cb5c326
7
- data.tar.gz: 222ee284a1e96bc86451abb16df09b7a1572987bdf47c44092925ff81aaffcc1bb73a7a50e8bf3fa280bd7d2e6d1b433da80885d9302ea67321c312605e054fd
6
+ metadata.gz: eff2590b57eca7703f4cda808982f46c57a1c728b2b194af5a8b9b18a7d49ad7c0569f7ab394d7f5382fa368802b07f0599d0afa3a45e2476ad97920093c656a
7
+ data.tar.gz: cb655011ec0518dd701a668542574c71d700c8eedcf5c361207b55180888a629a2062b25c37d48ea50c21e5478245a4835a87b51dde64ebbe740dc87b1443e94
data/.bundle/config ADDED
@@ -0,0 +1,5 @@
1
+ ---
2
+ BUNDLE_JOBS: "4"
3
+ BUNDLE_BUILD__UNICODE: "--with-cflags=-Wno-incompatible-function-pointer-types"
4
+ BUNDLE_BUILD__MYSQL2: "--with-ldflags=-L/opt/homebrew/opt/zstd/lib"
5
+ BUNDLE_FROZEN: "false"
@@ -5,16 +5,21 @@ on:
5
5
  tags:
6
6
  - v*
7
7
  jobs:
8
- build:
8
+ push:
9
9
  runs-on: ubuntu-latest
10
10
 
11
+ permissions:
12
+ contents: write
13
+ id-token: write
14
+
11
15
  steps:
12
- - uses: actions/checkout@v3
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
- - name: Release GEM
15
- if: contains(github.ref, 'refs/tags/v')
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
@@ -1,3 +1,2 @@
1
1
  janus-ar-*.gem
2
- .bundle/
3
2
  .rubocop-*
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- janus-ar (0.9.0)
4
+ janus-ar (0.11.0)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
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 ::Janus::Logging::Logger.logger and Janus.
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
@@ -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
@@ -4,7 +4,7 @@ module Janus
4
4
  unless defined?(::Janus::VERSION)
5
5
  module VERSION
6
6
  MAJOR = 0
7
- MINOR = 9
7
+ MINOR = 11
8
8
  PATCH = 0
9
9
  PRE = nil
10
10
 
data/lib/janus.rb CHANGED
@@ -5,6 +5,7 @@ require 'active_support'
5
5
  module Janus
6
6
  autoload :Context, 'janus/context'
7
7
  autoload :VERSION, 'janus/version'
8
+ autoload :DbConsoleConfig, 'janus/db_console_config'
8
9
 
9
10
  module Logging
10
11
  autoload :Subscriber, 'janus/logging/subscriber'
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.9.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 00:00:00.000000000 Z
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.3
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