active_record_proxy_adapters 0.2.1 → 0.2.2

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: f5fc4961ba1a8bce59f560d529b55eb965cd27971d92772f95f57b7a21bce30c
4
- data.tar.gz: 9c5c16ed9546f3be6df5e191e20483bb2177473b6c934ac589035a75771189e9
3
+ metadata.gz: efb046fb2816644ce048912c4c2666ae00f90fd728800f867cbe79bab99a59f3
4
+ data.tar.gz: 3d193415b9063dcfb5633c8e1493c20742f8cfbf06bc0baa7efccb291c727b49
5
5
  SHA512:
6
- metadata.gz: 8a97f02e6e212666c43490ebebe13957a9226103fb59ab2142de1905a10cc6357372314736f79fb86e141b5efdff0bfc1078a89e4205a52e53c80daf6df6b073
7
- data.tar.gz: b8d947651861fbbe6227c5ef6cc670c72a73bd58126c228d1cc6fe253327531e6b1ef299b51ea69402bd986380134be5d39308fdaaa9fc075f127b22ee37ee8d
6
+ metadata.gz: 8faf6efe63b55a9f00bbd4664f862abd3f0dd729f22b4e59306515a5dcd0fefbd42077cfaafc39f33f75d23eedd11a861e9284ba38c15868c69f72956d3acbbb
7
+ data.tar.gz: 91717a29aca4d6c41c71436527adb72cac844a4d19a2707eb5111d4f5f8b42b3c017990bdcc77972b48a7fa32082b02f74328a4c86b4f87cebc776b1d1641a17
data/CHANGELOG.md CHANGED
@@ -1,30 +1,37 @@
1
1
  ## [Unreleased]
2
2
 
3
+ - Handle PendingMigrationConnection introduced by Rails 7.2 and backported to Rails 7.1
4
+ - Stick to same connection throughout request span
5
+
3
6
  ## [0.2.1] - 2025-01-02
4
7
 
5
- - Fix replica connection pool getter when specific connection name is not found (847e150dd21c5bc619745ee1d9d8fcaa9b8f2eea)
8
+ - Fix replica connection pool getter when specific connection name is not found https://github.com/Nasdaq/active_record_proxy_adapters/commit/847e150dd21c5bc619745ee1d9d8fcaa9b8f2eea
6
9
 
7
10
  ## [0.2.0] - 2024-12-24
8
11
 
9
- - Add custom log subscriber to tag queries based on the adapter being used (68b8c1f4191388eb957bf12e0f84289da667e940)
12
+ - Add custom log subscriber to tag queries based on the adapter being used https://github.com/Nasdaq/active_record_proxy_adapters/commit/68b8c1f4191388eb957bf12e0f84289da667e940
13
+
14
+ ## [0.1.4] - 2025-01-02
15
+
16
+ - Fix replica connection pool getter when specific connection name is not found https://github.com/Nasdaq/active_record_proxy_adapters/commit/88b32a282b54d420e652f638656dbcf063ac8796
10
17
 
11
18
  ## [0.1.3] - 2024-12-24
12
19
 
13
- - Fix replica connection pool getter when database configurations have multiple replicas (ea5a33997da45ac073f166b3fbd2d12426053cd6)
14
- - Retrieve replica pool without checking out a connection (6470ef58e851082ae1f7a860ecdb5b451ef903c8)
20
+ - Fix replica connection pool getter when database configurations have multiple replicas https://github.com/Nasdaq/active_record_proxy_adapters/commit/ea5a33997da45ac073f166b3fbd2d12426053cd6
21
+ - Retrieve replica pool without checking out a connection https://github.com/Nasdaq/active_record_proxy_adapters/commit/6470ef58e851082ae1f7a860ecdb5b451ef903c8
15
22
 
16
23
  ## [0.1.2] - 2024-12-16
17
24
 
18
- - Fix CTE regex matcher (4b1d10bfd952fb1f5b102de8cc1a5bd05d25f5e9)
25
+ - Fix CTE regex matcher https://github.com/Nasdaq/active_record_proxy_adapters/commit/4b1d10bfd952fb1f5b102de8cc1a5bd05d25f5e9
19
26
 
20
27
  ## [0.1.1] - 2024-11-27
21
28
 
22
- - Enable RubyGems MFA (2a71b1f4354fb966cc0aa68231ca5837814e07ee)
29
+ - Enable RubyGems MFA https://github.com/Nasdaq/active_record_proxy_adapters/commit/2a71b1f4354fb966cc0aa68231ca5837814e07ee
23
30
 
24
31
  ## [0.1.0] - 2024-11-19
25
32
 
26
- - Add PostgreSQLProxyAdapter (2b3bb9f7359139519b32af3018ceb07fed8c6b33)
33
+ - Add PostgreSQLProxyAdapter https://github.com/Nasdaq/active_record_proxy_adapters/commit/2b3bb9f7359139519b32af3018ceb07fed8c6b33
27
34
 
28
35
  ## [0.1.0.rc2] - 2024-10-28
29
36
 
30
- - Add PostgreSQLProxyAdapter (2b3bb9f7359139519b32af3018ceb07fed8c6b33)
37
+ - Add PostgreSQLProxyAdapter https://github.com/Nasdaq/active_record_proxy_adapters/commit/2b3bb9f7359139519b32af3018ceb07fed8c6b33
data/Dockerfile CHANGED
@@ -8,7 +8,7 @@ RUN apk --update add \
8
8
  build-base \
9
9
  git \
10
10
  postgresql-dev \
11
- postgresql-client
11
+ postgresql17-client
12
12
  RUN gem install bundler -v 2.5.13
13
13
 
14
14
  COPY . /app
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # ActiveRecordProxyAdapters
2
2
 
3
+ [![Run Test Suite](https://github.com/Nasdaq/active_record_proxy_adapters/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/Nasdaq/active_record_proxy_adapters/actions/workflows/test.yml)
4
+
3
5
  A set of ActiveRecord adapters that leverage Rails native multiple database setup to allow automatic connection switching from _one_ primary pool to _one_ replica pool at the database statement level.
4
6
 
5
7
  ## Why do I need this?
@@ -1,6 +1,7 @@
1
1
  SET statement_timeout = 0;
2
2
  SET lock_timeout = 0;
3
3
  SET idle_in_transaction_session_timeout = 0;
4
+ SET transaction_timeout = 0;
4
5
  SET client_encoding = 'UTF8';
5
6
  SET standard_conforming_strings = on;
6
7
  SELECT pg_catalog.set_config('search_path', '', false);
@@ -9,16 +10,18 @@ SET xmloption = content;
9
10
  SET client_min_messages = warning;
10
11
  SET row_security = off;
11
12
 
12
- --
13
- -- Name: public; Type: SCHEMA; Schema: -; Owner: -
14
- --
13
+ SET default_tablespace = '';
15
14
 
16
- -- *not* creating schema, since initdb creates it
15
+ SET default_table_access_method = heap;
17
16
 
17
+ --
18
+ -- Name: schema_migrations; Type: TABLE; Schema: public; Owner: -
19
+ --
18
20
 
19
- SET default_tablespace = '';
21
+ CREATE TABLE public.schema_migrations (
22
+ version character varying(255) NOT NULL
23
+ );
20
24
 
21
- SET default_table_access_method = heap;
22
25
 
23
26
  --
24
27
  -- Name: users; Type: TABLE; Schema: public; Owner: -
@@ -68,6 +71,13 @@ ALTER TABLE ONLY public.users
68
71
  ADD CONSTRAINT users_pkey PRIMARY KEY (id);
69
72
 
70
73
 
74
+ --
75
+ -- Name: unique_schema_migrations; Type: INDEX; Schema: public; Owner: -
76
+ --
77
+
78
+ CREATE UNIQUE INDEX unique_schema_migrations ON public.schema_migrations USING btree (version);
79
+
80
+
71
81
  --
72
82
  -- PostgreSQL database dump complete
73
83
  --
@@ -62,7 +62,7 @@ module ActiveRecordProxyAdapters
62
62
 
63
63
  attr_reader :primary_connection, :last_write_at, :active_record_context
64
64
 
65
- delegate :connection_handler, :connected_to_stack, to: :connection_class
65
+ delegate :connection_handler, to: :connection_class
66
66
  delegate :reading_role, :writing_role, to: :active_record_context
67
67
 
68
68
  def replica_pool_unavailable?
@@ -120,11 +120,25 @@ module ActiveRecordProxyAdapters
120
120
  [reading_role, writing_role].include?(role) ? role : nil
121
121
  end
122
122
 
123
+ def connected_to_stack
124
+ return connection_class.connected_to_stack if connection_class.respond_to?(:connected_to_stack)
125
+
126
+ # handle Rails 7.2+ pending migrations Connection
127
+ return [{ role: writing_role }] if pending_migration_connection?
128
+
129
+ []
130
+ end
131
+
132
+ def pending_migration_connection?
133
+ active_record_context.active_record_v7_1_or_greater? &&
134
+ connection_class.name == "ActiveRecord::PendingMigrationConnection"
135
+ end
136
+
123
137
  def connection_for(role, sql_string)
124
138
  connection = primary_connection if role == writing_role || replica_pool_unavailable?
125
139
  connection ||= checkout_replica_connection
126
140
 
127
- result = yield(connection)
141
+ result = connected_to(role:) { yield connection }
128
142
 
129
143
  update_primary_latest_write_timestamp if !replica_connection?(connection) && write_statement?(sql_string)
130
144
 
@@ -133,6 +147,12 @@ module ActiveRecordProxyAdapters
133
147
  replica_connection?(connection) && replica_pool.checkin(connection)
134
148
  end
135
149
 
150
+ def connected_to(role:, &block)
151
+ return block.call unless connection_class.respond_to?(:connected_to)
152
+
153
+ connection_class.connected_to(role:, &block)
154
+ end
155
+
136
156
  def replica_connection?(connection)
137
157
  connection && connection != primary_connection
138
158
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveRecordProxyAdapters
4
- VERSION = "0.2.1"
4
+ VERSION = "0.2.2"
5
5
  end
@@ -1,4 +1,4 @@
1
- FROM docker.io/postgres:14-alpine
1
+ FROM docker.io/postgres:17-alpine
2
2
 
3
3
  ARG REPLICA_USER=replicator
4
4
  ARG REPLICA_PASSWORD=replicator
@@ -1,4 +1,4 @@
1
- FROM docker.io/postgres:14-alpine
1
+ FROM docker.io/postgres:17-alpine
2
2
 
3
3
  ENV PRIMARY_DATABASE_HOST=localhost
4
4
  ENV PRIMARY_DATABASE_PORT=5432
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_record_proxy_adapters
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Cruz
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-01-02 00:00:00.000000000 Z
11
+ date: 2025-01-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord