active_record_proxy_adapters 0.3.3 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rspec +4 -0
- data/.rubocop.yml +18 -0
- data/Appraisals +25 -0
- data/CHANGELOG.md +49 -0
- data/CODE_OF_CONDUCT.md +132 -0
- data/Dockerfile +21 -0
- data/db/mysql_structure.sql +41 -0
- data/db/postgresql_structure.sql +86 -0
- data/docker/postgres_replica/cmd.sh +9 -0
- data/docker-compose.yml +98 -0
- data/gemfiles/rails_7.0.gemfile +25 -0
- data/gemfiles/rails_7.0.gemfile.lock +122 -0
- data/gemfiles/rails_7.1.gemfile +21 -0
- data/gemfiles/rails_7.1.gemfile.lock +131 -0
- data/gemfiles/rails_7.2.gemfile +21 -0
- data/gemfiles/rails_7.2.gemfile.lock +129 -0
- data/gemfiles/rails_8.0.gemfile +21 -0
- data/gemfiles/rails_8.0.gemfile.lock +131 -0
- data/lib/active_record/connection_adapters/mysql2_proxy_adapter.rb +2 -0
- data/lib/active_record/connection_adapters/postgresql_proxy_adapter.rb +3 -0
- data/lib/active_record/connection_adapters/trilogy_proxy_adapter.rb +41 -0
- data/lib/active_record/tasks/trilogy_proxy_database_tasks.rb +19 -0
- data/lib/active_record_proxy_adapters/connection_handling/mysql2.rb +29 -23
- data/lib/active_record_proxy_adapters/connection_handling/postgresql.rb +27 -21
- data/lib/active_record_proxy_adapters/connection_handling/trilogy.rb +44 -0
- data/lib/active_record_proxy_adapters/connection_handling.rb +1 -7
- data/lib/active_record_proxy_adapters/primary_replica_proxy.rb +1 -18
- data/lib/active_record_proxy_adapters/railtie.rb +1 -4
- data/lib/active_record_proxy_adapters/trilogy_proxy.rb +9 -0
- data/lib/active_record_proxy_adapters/version.rb +1 -1
- data/postgres_primary.dockerfile +34 -0
- data/postgres_replica.dockerfile +15 -0
- data/sig/active_record_proxy_adapters.rbs +4 -0
- metadata +28 -5
@@ -50,22 +50,6 @@ module ActiveRecordProxyAdapters
|
|
50
50
|
delegate :connection_handler, to: :connection_class
|
51
51
|
delegate :reading_role, :writing_role, to: :active_record_context
|
52
52
|
|
53
|
-
# We need to call .verify! to ensure `configure_connection` is called on the instance before attempting to use it.
|
54
|
-
# This is necessary because the connection may have been lazily initialized and is an unintended side effect from a
|
55
|
-
# change in Rails to defer connection verification: https://github.com/rails/rails/pull/44576
|
56
|
-
# verify! cannot be called before the object is initialized and because of how the proxy hooks into the connection
|
57
|
-
# instance, it has to be done lazily (hence the memoization). Ideally, we shouldn't have to worry about this at all
|
58
|
-
# But there is tight coupling between methods in ActiveRecord::ConnectionAdapters::AbstractAdapter and
|
59
|
-
# its descendants which will require significant refactoring to be decoupled.
|
60
|
-
# See https://github.com/rails/rails/issues/51780
|
61
|
-
def verified_primary_connection
|
62
|
-
@verified_primary_connection ||= begin
|
63
|
-
connected_to(role: writing_role) { primary_connection.verify! }
|
64
|
-
|
65
|
-
primary_connection
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
53
|
def replica_pool_unavailable?
|
70
54
|
!replica_pool
|
71
55
|
end
|
@@ -136,8 +120,7 @@ module ActiveRecordProxyAdapters
|
|
136
120
|
end
|
137
121
|
|
138
122
|
def connection_for(role, sql_string)
|
139
|
-
connection =
|
140
|
-
|
123
|
+
connection = primary_connection if role == writing_role || replica_pool_unavailable?
|
141
124
|
connection ||= checkout_replica_connection
|
142
125
|
|
143
126
|
result = connected_to(role:) { yield connection }
|
@@ -5,10 +5,7 @@ require "active_support"
|
|
5
5
|
module ActiveRecordProxyAdapters
|
6
6
|
# Hooks into rails boot process to extend ActiveRecord with the proxy adapter.
|
7
7
|
class Railtie < Rails::Railtie
|
8
|
-
|
9
|
-
require "active_record_proxy_adapters/connection_handling"
|
10
|
-
ActiveRecord::Base.extend(ActiveRecordProxyAdapters::ConnectionHandling)
|
11
|
-
end
|
8
|
+
require "active_record_proxy_adapters/connection_handling"
|
12
9
|
|
13
10
|
config.to_prepare do
|
14
11
|
Rails.autoloaders.each do |autoloader|
|
@@ -0,0 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_record_proxy_adapters/mysql2_proxy"
|
4
|
+
|
5
|
+
module ActiveRecordProxyAdapters
|
6
|
+
# Proxy to the Mysql2Proxy, allowing the use of the ActiveRecordProxyAdapters::PrimaryReplicaProxy.
|
7
|
+
class TrilogyProxy < Mysql2Proxy
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
FROM docker.io/postgres:17-alpine
|
2
|
+
|
3
|
+
ARG REPLICA_USER=replicator
|
4
|
+
ARG REPLICA_PASSWORD=replicator
|
5
|
+
ARG REPLICATION_SLOT_NAME=replication_slot
|
6
|
+
ARG INIT_SQL=00_init.sql
|
7
|
+
ARG POSTGRES_LOGGING_COLLECTOR=
|
8
|
+
ARG POSTGRES_LOG_DESTINATION=
|
9
|
+
ARG POSTGRES_LOG_STATEMENT=
|
10
|
+
ENV CONF_SAMPLE="/usr/local/share/postgresql/postgresql.conf.sample"
|
11
|
+
|
12
|
+
WORKDIR /docker-entrypoint-initdb.d
|
13
|
+
|
14
|
+
USER root
|
15
|
+
|
16
|
+
RUN touch $INIT_SQL
|
17
|
+
RUN chown -R postgres:postgres $INIT_SQL
|
18
|
+
RUN echo "CREATE USER ${REPLICA_USER} WITH REPLICATION ENCRYPTED PASSWORD '${REPLICA_PASSWORD}';" > $INIT_SQL
|
19
|
+
RUN echo "SELECT pg_create_physical_replication_slot('${REPLICATION_SLOT_NAME}');" >> $INIT_SQL
|
20
|
+
|
21
|
+
# Enable logging collector if given
|
22
|
+
RUN if [[ ! -z "${POSTGRES_LOGGING_COLLECTOR}" ]]; then sed -i "s/#\(logging_collector = \)off\(.*\)/\1${POSTGRES_LOGGING_COLLECTOR}\2/" ${CONF_SAMPLE}; fi
|
23
|
+
|
24
|
+
# Override default log destination if given
|
25
|
+
RUN if [[ ! -z "${POSTGRES_LOG_DESTINATION}" ]]; then sed -i "s/#\(log_destination = \)'stderr'\(.*\)/\1'${POSTGRES_LOG_DESTINATION}'\2/" ${CONF_SAMPLE}; fi
|
26
|
+
|
27
|
+
# Override log statement if given
|
28
|
+
RUN if [[ ! -z "${POSTGRES_LOG_STATEMENT}" ]]; then sed -i "s/#\(log_statement = \)'none'\(.*\)/\1'${POSTGRES_LOG_STATEMENT}'\2/" ${CONF_SAMPLE}; fi
|
29
|
+
|
30
|
+
WORKDIR /
|
31
|
+
|
32
|
+
USER postgres
|
33
|
+
|
34
|
+
CMD ["postgres", "-c", "wal_level=replica", "-c", "hot_standby=on", "-c", "max_wal_senders=10", "-c", "max_replication_slots=10", "-c", "hot_standby_feedback=on" ]
|
@@ -0,0 +1,15 @@
|
|
1
|
+
FROM docker.io/postgres:17-alpine
|
2
|
+
|
3
|
+
ENV PRIMARY_DATABASE_HOST=localhost
|
4
|
+
ENV PRIMARY_DATABASE_PORT=5432
|
5
|
+
ENV PRIMARY_REPLICATION_SLOT=replication_slot
|
6
|
+
|
7
|
+
|
8
|
+
COPY docker/postgres_replica/cmd.sh cmd.sh
|
9
|
+
|
10
|
+
USER root
|
11
|
+
RUN chown -R postgres:postgres cmd.sh
|
12
|
+
USER postgres
|
13
|
+
RUN chmod u+x cmd.sh
|
14
|
+
|
15
|
+
CMD [ "./cmd.sh" ]
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_record_proxy_adapters
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Cruz
|
8
8
|
bindir: exe
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-
|
10
|
+
date: 2025-02-25 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: activerecord
|
@@ -57,22 +57,41 @@ email:
|
|
57
57
|
- matt.cruz@nasdaq.com
|
58
58
|
executables: []
|
59
59
|
extensions: []
|
60
|
-
extra_rdoc_files:
|
61
|
-
- README.md
|
62
|
-
- LICENSE.txt
|
60
|
+
extra_rdoc_files: []
|
63
61
|
files:
|
62
|
+
- ".rspec"
|
63
|
+
- ".rubocop.yml"
|
64
|
+
- Appraisals
|
65
|
+
- CHANGELOG.md
|
66
|
+
- CODE_OF_CONDUCT.md
|
67
|
+
- Dockerfile
|
64
68
|
- LICENSE.txt
|
65
69
|
- README.md
|
70
|
+
- db/mysql_structure.sql
|
71
|
+
- db/postgresql_structure.sql
|
72
|
+
- docker-compose.yml
|
73
|
+
- docker/postgres_replica/cmd.sh
|
74
|
+
- gemfiles/rails_7.0.gemfile
|
75
|
+
- gemfiles/rails_7.0.gemfile.lock
|
76
|
+
- gemfiles/rails_7.1.gemfile
|
77
|
+
- gemfiles/rails_7.1.gemfile.lock
|
78
|
+
- gemfiles/rails_7.2.gemfile
|
79
|
+
- gemfiles/rails_7.2.gemfile.lock
|
80
|
+
- gemfiles/rails_8.0.gemfile
|
81
|
+
- gemfiles/rails_8.0.gemfile.lock
|
66
82
|
- lib/active_record/connection_adapters/mysql2_proxy_adapter.rb
|
67
83
|
- lib/active_record/connection_adapters/postgresql_proxy_adapter.rb
|
84
|
+
- lib/active_record/connection_adapters/trilogy_proxy_adapter.rb
|
68
85
|
- lib/active_record/tasks/mysql2_proxy_database_tasks.rb
|
69
86
|
- lib/active_record/tasks/postgresql_proxy_database_tasks.rb
|
87
|
+
- lib/active_record/tasks/trilogy_proxy_database_tasks.rb
|
70
88
|
- lib/active_record_proxy_adapters.rb
|
71
89
|
- lib/active_record_proxy_adapters/active_record_context.rb
|
72
90
|
- lib/active_record_proxy_adapters/configuration.rb
|
73
91
|
- lib/active_record_proxy_adapters/connection_handling.rb
|
74
92
|
- lib/active_record_proxy_adapters/connection_handling/mysql2.rb
|
75
93
|
- lib/active_record_proxy_adapters/connection_handling/postgresql.rb
|
94
|
+
- lib/active_record_proxy_adapters/connection_handling/trilogy.rb
|
76
95
|
- lib/active_record_proxy_adapters/database_tasks.rb
|
77
96
|
- lib/active_record_proxy_adapters/hijackable.rb
|
78
97
|
- lib/active_record_proxy_adapters/log_subscriber.rb
|
@@ -80,7 +99,11 @@ files:
|
|
80
99
|
- lib/active_record_proxy_adapters/postgresql_proxy.rb
|
81
100
|
- lib/active_record_proxy_adapters/primary_replica_proxy.rb
|
82
101
|
- lib/active_record_proxy_adapters/railtie.rb
|
102
|
+
- lib/active_record_proxy_adapters/trilogy_proxy.rb
|
83
103
|
- lib/active_record_proxy_adapters/version.rb
|
104
|
+
- postgres_primary.dockerfile
|
105
|
+
- postgres_replica.dockerfile
|
106
|
+
- sig/active_record_proxy_adapters.rbs
|
84
107
|
homepage: https://github.com/Nasdaq/active_record_proxy_adapters
|
85
108
|
licenses:
|
86
109
|
- MIT
|