active_record_proxy_adapters 0.1.4 → 0.1.6
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/README.md +2 -0
- data/lib/active_record_proxy_adapters/primary_replica_proxy.rb +22 -2
- data/lib/active_record_proxy_adapters/version.rb +1 -1
- metadata +6 -19
- data/.rspec +0 -4
- data/.rubocop.yml +0 -16
- data/CHANGELOG.md +0 -20
- data/CODE_OF_CONDUCT.md +0 -132
- data/Dockerfile +0 -18
- data/Rakefile +0 -81
- data/db/postgresql_structure.sql +0 -76
- data/docker/postgres_replica/cmd.sh +0 -9
- data/docker-compose.yml +0 -77
- data/postgres_primary.dockerfile +0 -34
- data/postgres_replica.dockerfile +0 -15
- data/sig/active_record_proxy_adapters.rbs +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0650c0793e1af3d7f06f1da1708cc590942468daca491353b57a74575926a5e2
|
4
|
+
data.tar.gz: 44cd716171d8a8d2d430ac8ae3780f54634ecdf1ae1014ca09720f9fef95bf5b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 68b00c13361168d78b70752002443988132725b013330d1e1161277f73c1a808f0153e76e6fb397bc7dd23c9bc8ba108a6c99ec3bdfc60d45f59a2c47902f693
|
7
|
+
data.tar.gz: a2bb48e98f0a57bb4f4546ca5bf821be670205a50a0b2ec439a79c98e3db1e43c28b63fe90c7d5849ba0ae048b4b20300658ce7fee62dd874e345c9ac50a0e86
|
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# ActiveRecordProxyAdapters
|
2
2
|
|
3
|
+
[](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
|
## Installation
|
@@ -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,
|
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
|
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
|
metadata
CHANGED
@@ -1,14 +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.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Cruz
|
8
|
-
autorequire:
|
9
8
|
bindir: exe
|
10
9
|
cert_chain: []
|
11
|
-
date: 2025-
|
10
|
+
date: 2025-02-25 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: activerecord
|
@@ -58,19 +57,12 @@ email:
|
|
58
57
|
- matt.cruz@nasdaq.com
|
59
58
|
executables: []
|
60
59
|
extensions: []
|
61
|
-
extra_rdoc_files:
|
60
|
+
extra_rdoc_files:
|
61
|
+
- README.md
|
62
|
+
- LICENSE.txt
|
62
63
|
files:
|
63
|
-
- ".rspec"
|
64
|
-
- ".rubocop.yml"
|
65
|
-
- CHANGELOG.md
|
66
|
-
- CODE_OF_CONDUCT.md
|
67
|
-
- Dockerfile
|
68
64
|
- LICENSE.txt
|
69
65
|
- README.md
|
70
|
-
- Rakefile
|
71
|
-
- db/postgresql_structure.sql
|
72
|
-
- docker-compose.yml
|
73
|
-
- docker/postgres_replica/cmd.sh
|
74
66
|
- lib/active_record/connection_adapters/postgresql_proxy_adapter.rb
|
75
67
|
- lib/active_record/tasks/postgresql_proxy_database_tasks.rb
|
76
68
|
- lib/active_record_proxy_adapters.rb
|
@@ -82,9 +74,6 @@ files:
|
|
82
74
|
- lib/active_record_proxy_adapters/primary_replica_proxy.rb
|
83
75
|
- lib/active_record_proxy_adapters/railtie.rb
|
84
76
|
- lib/active_record_proxy_adapters/version.rb
|
85
|
-
- postgres_primary.dockerfile
|
86
|
-
- postgres_replica.dockerfile
|
87
|
-
- sig/active_record_proxy_adapters.rbs
|
88
77
|
homepage: https://github.com/Nasdaq/active_record_proxy_adapters
|
89
78
|
licenses:
|
90
79
|
- MIT
|
@@ -94,7 +83,6 @@ metadata:
|
|
94
83
|
source_code_uri: https://github.com/Nasdaq/active_record_proxy_adapters
|
95
84
|
changelog_uri: https://github.com/Nasdaq/active_record_proxy_adapters/blob/main/CHANGELOG.md
|
96
85
|
rubygems_mfa_required: 'true'
|
97
|
-
post_install_message:
|
98
86
|
rdoc_options: []
|
99
87
|
require_paths:
|
100
88
|
- lib
|
@@ -109,8 +97,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
109
97
|
- !ruby/object:Gem::Version
|
110
98
|
version: '0'
|
111
99
|
requirements: []
|
112
|
-
rubygems_version: 3.
|
113
|
-
signing_key:
|
100
|
+
rubygems_version: 3.6.2
|
114
101
|
specification_version: 4
|
115
102
|
summary: Read replica proxy adapters for ActiveRecord!
|
116
103
|
test_files: []
|
data/.rspec
DELETED
data/.rubocop.yml
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
require:
|
2
|
-
- rubocop-rspec
|
3
|
-
|
4
|
-
AllCops:
|
5
|
-
TargetRubyVersion: 3.1
|
6
|
-
NewCops: enable
|
7
|
-
|
8
|
-
Style/StringLiterals:
|
9
|
-
EnforcedStyle: double_quotes
|
10
|
-
|
11
|
-
Style/StringLiteralsInInterpolation:
|
12
|
-
EnforcedStyle: double_quotes
|
13
|
-
|
14
|
-
RSpec/NestedGroups:
|
15
|
-
Enabled: true
|
16
|
-
Max: 5
|
data/CHANGELOG.md
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
## [Unreleased]
|
2
|
-
|
3
|
-
- Fix replica connection pool getter when database configurations have multiple replicas
|
4
|
-
- Retrieve replica pool without checking out a connection
|
5
|
-
|
6
|
-
## [0.1.2] - 2024-12-16
|
7
|
-
|
8
|
-
- Fix CTE regex matcher (4b1d10b)
|
9
|
-
|
10
|
-
## [0.1.1] - 2024-11-27
|
11
|
-
|
12
|
-
- Enable RubyGems MFA (2a71b1f)
|
13
|
-
|
14
|
-
## [0.1.0] - 2024-11-19
|
15
|
-
|
16
|
-
- Add PostgreSQLProxyAdapter (2b3bb9f)
|
17
|
-
|
18
|
-
## [0.1.0.rc2] - 2024-10-28
|
19
|
-
|
20
|
-
- Add PostgreSQLProxyAdapter (2b3bb9f)
|
data/CODE_OF_CONDUCT.md
DELETED
@@ -1,132 +0,0 @@
|
|
1
|
-
# Contributor Covenant Code of Conduct
|
2
|
-
|
3
|
-
## Our Pledge
|
4
|
-
|
5
|
-
We as members, contributors, and leaders pledge to make participation in our
|
6
|
-
community a harassment-free experience for everyone, regardless of age, body
|
7
|
-
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
8
|
-
identity and expression, level of experience, education, socio-economic status,
|
9
|
-
nationality, personal appearance, race, caste, color, religion, or sexual
|
10
|
-
identity and orientation.
|
11
|
-
|
12
|
-
We pledge to act and interact in ways that contribute to an open, welcoming,
|
13
|
-
diverse, inclusive, and healthy community.
|
14
|
-
|
15
|
-
## Our Standards
|
16
|
-
|
17
|
-
Examples of behavior that contributes to a positive environment for our
|
18
|
-
community include:
|
19
|
-
|
20
|
-
* Demonstrating empathy and kindness toward other people
|
21
|
-
* Being respectful of differing opinions, viewpoints, and experiences
|
22
|
-
* Giving and gracefully accepting constructive feedback
|
23
|
-
* Accepting responsibility and apologizing to those affected by our mistakes,
|
24
|
-
and learning from the experience
|
25
|
-
* Focusing on what is best not just for us as individuals, but for the overall
|
26
|
-
community
|
27
|
-
|
28
|
-
Examples of unacceptable behavior include:
|
29
|
-
|
30
|
-
* The use of sexualized language or imagery, and sexual attention or advances of
|
31
|
-
any kind
|
32
|
-
* Trolling, insulting or derogatory comments, and personal or political attacks
|
33
|
-
* Public or private harassment
|
34
|
-
* Publishing others' private information, such as a physical or email address,
|
35
|
-
without their explicit permission
|
36
|
-
* Other conduct which could reasonably be considered inappropriate in a
|
37
|
-
professional setting
|
38
|
-
|
39
|
-
## Enforcement Responsibilities
|
40
|
-
|
41
|
-
Community leaders are responsible for clarifying and enforcing our standards of
|
42
|
-
acceptable behavior and will take appropriate and fair corrective action in
|
43
|
-
response to any behavior that they deem inappropriate, threatening, offensive,
|
44
|
-
or harmful.
|
45
|
-
|
46
|
-
Community leaders have the right and responsibility to remove, edit, or reject
|
47
|
-
comments, commits, code, wiki edits, issues, and other contributions that are
|
48
|
-
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
49
|
-
decisions when appropriate.
|
50
|
-
|
51
|
-
## Scope
|
52
|
-
|
53
|
-
This Code of Conduct applies within all community spaces, and also applies when
|
54
|
-
an individual is officially representing the community in public spaces.
|
55
|
-
Examples of representing our community include using an official email address,
|
56
|
-
posting via an official social media account, or acting as an appointed
|
57
|
-
representative at an online or offline event.
|
58
|
-
|
59
|
-
## Enforcement
|
60
|
-
|
61
|
-
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
62
|
-
reported to the community leaders responsible for enforcement at
|
63
|
-
[INSERT CONTACT METHOD].
|
64
|
-
All complaints will be reviewed and investigated promptly and fairly.
|
65
|
-
|
66
|
-
All community leaders are obligated to respect the privacy and security of the
|
67
|
-
reporter of any incident.
|
68
|
-
|
69
|
-
## Enforcement Guidelines
|
70
|
-
|
71
|
-
Community leaders will follow these Community Impact Guidelines in determining
|
72
|
-
the consequences for any action they deem in violation of this Code of Conduct:
|
73
|
-
|
74
|
-
### 1. Correction
|
75
|
-
|
76
|
-
**Community Impact**: Use of inappropriate language or other behavior deemed
|
77
|
-
unprofessional or unwelcome in the community.
|
78
|
-
|
79
|
-
**Consequence**: A private, written warning from community leaders, providing
|
80
|
-
clarity around the nature of the violation and an explanation of why the
|
81
|
-
behavior was inappropriate. A public apology may be requested.
|
82
|
-
|
83
|
-
### 2. Warning
|
84
|
-
|
85
|
-
**Community Impact**: A violation through a single incident or series of
|
86
|
-
actions.
|
87
|
-
|
88
|
-
**Consequence**: A warning with consequences for continued behavior. No
|
89
|
-
interaction with the people involved, including unsolicited interaction with
|
90
|
-
those enforcing the Code of Conduct, for a specified period of time. This
|
91
|
-
includes avoiding interactions in community spaces as well as external channels
|
92
|
-
like social media. Violating these terms may lead to a temporary or permanent
|
93
|
-
ban.
|
94
|
-
|
95
|
-
### 3. Temporary Ban
|
96
|
-
|
97
|
-
**Community Impact**: A serious violation of community standards, including
|
98
|
-
sustained inappropriate behavior.
|
99
|
-
|
100
|
-
**Consequence**: A temporary ban from any sort of interaction or public
|
101
|
-
communication with the community for a specified period of time. No public or
|
102
|
-
private interaction with the people involved, including unsolicited interaction
|
103
|
-
with those enforcing the Code of Conduct, is allowed during this period.
|
104
|
-
Violating these terms may lead to a permanent ban.
|
105
|
-
|
106
|
-
### 4. Permanent Ban
|
107
|
-
|
108
|
-
**Community Impact**: Demonstrating a pattern of violation of community
|
109
|
-
standards, including sustained inappropriate behavior, harassment of an
|
110
|
-
individual, or aggression toward or disparagement of classes of individuals.
|
111
|
-
|
112
|
-
**Consequence**: A permanent ban from any sort of public interaction within the
|
113
|
-
community.
|
114
|
-
|
115
|
-
## Attribution
|
116
|
-
|
117
|
-
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
118
|
-
version 2.1, available at
|
119
|
-
[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
|
120
|
-
|
121
|
-
Community Impact Guidelines were inspired by
|
122
|
-
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
|
123
|
-
|
124
|
-
For answers to common questions about this code of conduct, see the FAQ at
|
125
|
-
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
|
126
|
-
[https://www.contributor-covenant.org/translations][translations].
|
127
|
-
|
128
|
-
[homepage]: https://www.contributor-covenant.org
|
129
|
-
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
|
130
|
-
[Mozilla CoC]: https://github.com/mozilla/diversity
|
131
|
-
[FAQ]: https://www.contributor-covenant.org/faq
|
132
|
-
[translations]: https://www.contributor-covenant.org/translations
|
data/Dockerfile
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
ARG RUBY_VERSION=3.2.3
|
2
|
-
ARG DOCKER_REGISTRY=docker.io
|
3
|
-
FROM $DOCKER_REGISTRY/ruby:$RUBY_VERSION-alpine
|
4
|
-
ARG RAILS_VERSION="~> 6.1.0"
|
5
|
-
ENV RAILS_VERSION=$RAILS_VERSION
|
6
|
-
|
7
|
-
RUN apk --update add \
|
8
|
-
build-base \
|
9
|
-
git \
|
10
|
-
postgresql-dev \
|
11
|
-
postgresql-client
|
12
|
-
RUN gem install bundler -v 2.5.13
|
13
|
-
|
14
|
-
COPY . /app
|
15
|
-
WORKDIR /app
|
16
|
-
|
17
|
-
RUN bundle install
|
18
|
-
|
data/Rakefile
DELETED
@@ -1,81 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "bundler/gem_tasks"
|
4
|
-
require "rspec/core/rake_task"
|
5
|
-
|
6
|
-
RSpec::Core::RakeTask.new(:spec)
|
7
|
-
|
8
|
-
require "rubocop/rake_task"
|
9
|
-
|
10
|
-
RuboCop::RakeTask.new
|
11
|
-
|
12
|
-
task default: %i[spec rubocop]
|
13
|
-
|
14
|
-
desc "Prepares the database environment for use"
|
15
|
-
task :environment do
|
16
|
-
$LOAD_PATH << File.expand_path("lib", __dir__)
|
17
|
-
require "active_record_proxy_adapters"
|
18
|
-
require "active_record_proxy_adapters/connection_handling"
|
19
|
-
ActiveRecord::Base.extend ActiveRecordProxyAdapters::ConnectionHandling
|
20
|
-
require_relative "spec/test_helper"
|
21
|
-
|
22
|
-
TestHelper.setup_active_record_config
|
23
|
-
|
24
|
-
$stdout.puts "Environment loaded: #{TestHelper.env_name}"
|
25
|
-
end
|
26
|
-
|
27
|
-
namespace :db do # rubocop:disable Metrics/BlockLength
|
28
|
-
desc "Drops all databases"
|
29
|
-
task drop: %i[drop:postgresql]
|
30
|
-
|
31
|
-
namespace :drop do
|
32
|
-
desc "Drops the postgresql database"
|
33
|
-
task postgresql: :environment do
|
34
|
-
TestHelper.drop_database
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
desc "Creates all databases"
|
39
|
-
task create: %i[create:postgresql]
|
40
|
-
|
41
|
-
namespace :create do
|
42
|
-
desc "Creates the postgresql database"
|
43
|
-
task postgresql: :environment do
|
44
|
-
TestHelper.create_database
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
namespace :schema do
|
49
|
-
desc "Loads all schemas onto their respective databases"
|
50
|
-
task load: %i[load:postgresql]
|
51
|
-
|
52
|
-
namespace :load do
|
53
|
-
desc "Loads the schema into the postgresql database from schema_path. Default is db/postgresql_structure.sql"
|
54
|
-
task :postgresql, [:schema_path] => :environment do |_task, args|
|
55
|
-
args.with_defaults(schema_path: "db/postgresql_structure.sql")
|
56
|
-
TestHelper.load_schema(args.schema_path)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
desc "Creates a all databases and loads their schemas"
|
62
|
-
task setup: %i[create schema:load]
|
63
|
-
|
64
|
-
namespace :setup do
|
65
|
-
desc "Creates the postgresql database and loads the schema"
|
66
|
-
task postgresql: %i[create:postgresql schema:load:postgresql]
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
namespace :coverage do
|
71
|
-
desc "Collates all result sets generated by the different test runners"
|
72
|
-
task :report do
|
73
|
-
require "simplecov"
|
74
|
-
|
75
|
-
SimpleCov.collate Dir["coverage/**/.resultset.json"] do
|
76
|
-
add_group "PostgreSQL" do |src_file|
|
77
|
-
[/postgresql/, /postgre_sql/].any? { |pattern| pattern.match?(src_file.filename) }
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
data/db/postgresql_structure.sql
DELETED
@@ -1,76 +0,0 @@
|
|
1
|
-
SET statement_timeout = 0;
|
2
|
-
SET lock_timeout = 0;
|
3
|
-
SET idle_in_transaction_session_timeout = 0;
|
4
|
-
SET client_encoding = 'UTF8';
|
5
|
-
SET standard_conforming_strings = on;
|
6
|
-
SELECT pg_catalog.set_config('search_path', '', false);
|
7
|
-
SET check_function_bodies = false;
|
8
|
-
SET xmloption = content;
|
9
|
-
SET client_min_messages = warning;
|
10
|
-
SET row_security = off;
|
11
|
-
|
12
|
-
--
|
13
|
-
-- Name: public; Type: SCHEMA; Schema: -; Owner: -
|
14
|
-
--
|
15
|
-
|
16
|
-
-- *not* creating schema, since initdb creates it
|
17
|
-
|
18
|
-
|
19
|
-
SET default_tablespace = '';
|
20
|
-
|
21
|
-
SET default_table_access_method = heap;
|
22
|
-
|
23
|
-
--
|
24
|
-
-- Name: users; Type: TABLE; Schema: public; Owner: -
|
25
|
-
--
|
26
|
-
|
27
|
-
CREATE TABLE public.users (
|
28
|
-
id integer NOT NULL,
|
29
|
-
name text NOT NULL,
|
30
|
-
email text NOT NULL,
|
31
|
-
created_at timestamp without time zone DEFAULT now() NOT NULL,
|
32
|
-
updated_at timestamp without time zone DEFAULT now() NOT NULL
|
33
|
-
);
|
34
|
-
|
35
|
-
|
36
|
-
--
|
37
|
-
-- Name: users_id_seq; Type: SEQUENCE; Schema: public; Owner: -
|
38
|
-
--
|
39
|
-
|
40
|
-
CREATE SEQUENCE public.users_id_seq
|
41
|
-
AS integer
|
42
|
-
START WITH 1
|
43
|
-
INCREMENT BY 1
|
44
|
-
NO MINVALUE
|
45
|
-
NO MAXVALUE
|
46
|
-
CACHE 1;
|
47
|
-
|
48
|
-
|
49
|
-
--
|
50
|
-
-- Name: users_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
|
51
|
-
--
|
52
|
-
|
53
|
-
ALTER SEQUENCE public.users_id_seq OWNED BY public.users.id;
|
54
|
-
|
55
|
-
|
56
|
-
--
|
57
|
-
-- Name: users id; Type: DEFAULT; Schema: public; Owner: -
|
58
|
-
--
|
59
|
-
|
60
|
-
ALTER TABLE ONLY public.users ALTER COLUMN id SET DEFAULT nextval('public.users_id_seq'::regclass);
|
61
|
-
|
62
|
-
|
63
|
-
--
|
64
|
-
-- Name: users users_pkey; Type: CONSTRAINT; Schema: public; Owner: -
|
65
|
-
--
|
66
|
-
|
67
|
-
ALTER TABLE ONLY public.users
|
68
|
-
ADD CONSTRAINT users_pkey PRIMARY KEY (id);
|
69
|
-
|
70
|
-
|
71
|
-
--
|
72
|
-
-- PostgreSQL database dump complete
|
73
|
-
--
|
74
|
-
|
75
|
-
SET search_path TO "$user", public;
|
76
|
-
|
@@ -1,9 +0,0 @@
|
|
1
|
-
until pg_basebackup --pgdata=/var/lib/postgresql/data -R --slot=$PRIMARY_REPLICATION_SLOT --host=$PRIMARY_DATABASE_HOST --port=$PRIMARY_DATABASE_PORT
|
2
|
-
do
|
3
|
-
echo 'Waiting for primary to connect...'
|
4
|
-
sleep 1s
|
5
|
-
done
|
6
|
-
|
7
|
-
echo 'Backup done, starting replica...'
|
8
|
-
chmod 0700 /var/lib/postgresql/data
|
9
|
-
postgres
|
data/docker-compose.yml
DELETED
@@ -1,77 +0,0 @@
|
|
1
|
-
name: active_record_proxy_adapters
|
2
|
-
|
3
|
-
x-postgres-common: &postgres-common
|
4
|
-
restart: always
|
5
|
-
user: postgres
|
6
|
-
healthcheck:
|
7
|
-
test: 'pg_isready -U postgres_primary_test --dbname=postgres'
|
8
|
-
interval: 10s
|
9
|
-
timeout: 5s
|
10
|
-
retries: 5
|
11
|
-
networks:
|
12
|
-
- postgres
|
13
|
-
|
14
|
-
services:
|
15
|
-
app:
|
16
|
-
build:
|
17
|
-
args:
|
18
|
-
- RUBY_VERSION=${RUBY_VERSION:-3.3.6}
|
19
|
-
- RAILS_VERSION=${RAILS_VERSION:-8.0.0}
|
20
|
-
container_name: app
|
21
|
-
image: active_record_proxy_adapters-app:${ENV_TAG:-latest}
|
22
|
-
tty: true
|
23
|
-
stdin_open: true
|
24
|
-
environment:
|
25
|
-
PGHOST: postgres_primary
|
26
|
-
PG_PRIMARY_USER: postgres_primary_test
|
27
|
-
PG_PRIMARY_PASSWORD: postgres_primary_test
|
28
|
-
PG_PRIMARY_HOST: postgres_primary
|
29
|
-
PG_PRIMARY_PORT: 5432
|
30
|
-
PG_REPLICA_USER: postgres_primary_test
|
31
|
-
PG_REPLICA_PASSWORD: postgres_primary_test
|
32
|
-
PG_REPLICA_HOST: postgres_replica
|
33
|
-
PG_REPLICA_PORT: 5432
|
34
|
-
depends_on:
|
35
|
-
- postgres_primary
|
36
|
-
- postgres_replica
|
37
|
-
networks:
|
38
|
-
- app
|
39
|
-
- postgres
|
40
|
-
volumes:
|
41
|
-
- .:/app
|
42
|
-
postgres_primary:
|
43
|
-
<<: *postgres-common
|
44
|
-
build:
|
45
|
-
context: .
|
46
|
-
dockerfile: postgres_primary.dockerfile
|
47
|
-
args:
|
48
|
-
- POSTGRES_LOGGING_COLLECTOR=${POSTGRES_LOGGING_COLLECTOR:-}
|
49
|
-
- POSTGRES_LOG_DESTINATION=${POSTGRES_LOG_DESTINATION:-}
|
50
|
-
- POSTGRES_LOG_STATEMENT=${POSTGRES_LOG_STATEMENT:-}
|
51
|
-
- REPLICA_USER=replicator
|
52
|
-
- REPLICA_PASSWORD=replicator
|
53
|
-
environment:
|
54
|
-
POSTGRES_DB: postgres
|
55
|
-
POSTGRES_USER: postgres_primary_test
|
56
|
-
POSTGRES_PASSWORD: postgres_primary_test
|
57
|
-
POSTGRES_HOST_AUTH_METHOD: "scram-sha-256\nhost replication all 0.0.0.0/0 md5"
|
58
|
-
POSTGRES_INITDB_ARGS: "--auth-host=scram-sha-256"
|
59
|
-
|
60
|
-
postgres_replica:
|
61
|
-
<<: *postgres-common
|
62
|
-
build:
|
63
|
-
context: .
|
64
|
-
dockerfile: postgres_replica.dockerfile
|
65
|
-
container_name: postgres_replica
|
66
|
-
environment:
|
67
|
-
PGUSER: replicator
|
68
|
-
PGPASSWORD: replicator
|
69
|
-
PRIMARY_DATABASE_HOST: postgres_primary
|
70
|
-
depends_on:
|
71
|
-
- postgres_primary
|
72
|
-
networks:
|
73
|
-
app:
|
74
|
-
postgres:
|
75
|
-
|
76
|
-
volumes:
|
77
|
-
postgres_primary:
|
data/postgres_primary.dockerfile
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
FROM docker.io/postgres:14-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" ]
|
data/postgres_replica.dockerfile
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
FROM docker.io/postgres:14-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" ]
|