goldlapel-rails 0.0.1.pre.rc1
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 +7 -0
- data/README.md +86 -0
- data/lib/goldlapel/rails.rb +62 -0
- metadata +75 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: f44db54519a70c3f3273f3db9799f26bb7d68e162c1ea28a82a9364e127beb2a
|
|
4
|
+
data.tar.gz: cd18f606f98ebe6b0d068aec9f93588242158f3fb1b0c3d39bf03609d2a912b7
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: e8dc604866635f228b2719ced388a4b0ebd16982ebece15e0af269f1b20ef5ccde7c1269beb9937b5c8b5fada4c2188a2ace7d1cbe0a137d2895eeb5380865e0
|
|
7
|
+
data.tar.gz: 877c583ed1469cdfa8801b66101a541ce829552b0ebb708b1342a9ce7fb9c4b16e078aa31793740a8da6a6d88731440aace91787d50f77b2bea8b11892188f67
|
data/README.md
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# goldlapel-rails
|
|
2
|
+
|
|
3
|
+
Rails integration for [Gold Lapel](https://goldlapel.com) — the self-optimizing Postgres proxy.
|
|
4
|
+
|
|
5
|
+
Auto-patches ActiveRecord's PostgreSQL adapter to start the Gold Lapel proxy on first connection and route all queries through it. Zero config — just add the gem.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
# Gemfile
|
|
11
|
+
gem "goldlapel-rails"
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
That's it. Your existing `config/database.yml` works unchanged.
|
|
15
|
+
|
|
16
|
+
## How It Works
|
|
17
|
+
|
|
18
|
+
When ActiveRecord opens its first PostgreSQL connection, `goldlapel-rails`:
|
|
19
|
+
|
|
20
|
+
1. Reads your connection params (host, port, user, password, database)
|
|
21
|
+
2. Starts the Gold Lapel proxy pointing at your database
|
|
22
|
+
3. Rewrites the connection to go through the proxy (`127.0.0.1:7932`)
|
|
23
|
+
|
|
24
|
+
On reconnect, the proxy is already running — the adapter reuses the rewritten params.
|
|
25
|
+
|
|
26
|
+
## Optional Configuration
|
|
27
|
+
|
|
28
|
+
You can pass Gold Lapel options in `config/database.yml`:
|
|
29
|
+
|
|
30
|
+
```yaml
|
|
31
|
+
production:
|
|
32
|
+
adapter: postgresql
|
|
33
|
+
host: db.example.com
|
|
34
|
+
database: mydb
|
|
35
|
+
username: user
|
|
36
|
+
password: pass
|
|
37
|
+
goldlapel:
|
|
38
|
+
port: 9000 # proxy listen port (default: 7932)
|
|
39
|
+
config: # proxy configuration
|
|
40
|
+
mode: butler
|
|
41
|
+
pool_size: 30
|
|
42
|
+
disable_n1: true
|
|
43
|
+
extra_args:
|
|
44
|
+
- "--threshold-duration-ms"
|
|
45
|
+
- "200"
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
The `config` hash maps directly to Gold Lapel's configuration options. Use snake_case keys:
|
|
49
|
+
|
|
50
|
+
```ruby
|
|
51
|
+
# config/environments/production.rb (programmatic alternative)
|
|
52
|
+
config.database_configuration["production"]["goldlapel"] = {
|
|
53
|
+
config: { mode: "butler", pool_size: 30, disable_n1: true }
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Multiple Databases
|
|
58
|
+
|
|
59
|
+
Each database needs a different proxy port:
|
|
60
|
+
|
|
61
|
+
```yaml
|
|
62
|
+
production:
|
|
63
|
+
primary:
|
|
64
|
+
adapter: postgresql
|
|
65
|
+
host: primary-db.example.com
|
|
66
|
+
database: myapp
|
|
67
|
+
goldlapel:
|
|
68
|
+
port: 7932
|
|
69
|
+
|
|
70
|
+
analytics:
|
|
71
|
+
adapter: postgresql
|
|
72
|
+
host: analytics-db.example.com
|
|
73
|
+
database: analytics
|
|
74
|
+
goldlapel:
|
|
75
|
+
port: 7933
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Requirements
|
|
79
|
+
|
|
80
|
+
- Ruby >= 3.2
|
|
81
|
+
- Rails >= 7.0
|
|
82
|
+
- The [`goldlapel`](https://rubygems.org/gems/goldlapel) gem (added automatically as a dependency)
|
|
83
|
+
|
|
84
|
+
## License
|
|
85
|
+
|
|
86
|
+
Proprietary. See [goldlapel.com](https://goldlapel.com) for licensing.
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
require "uri"
|
|
2
|
+
require "goldlapel"
|
|
3
|
+
|
|
4
|
+
module GoldLapel
|
|
5
|
+
module Rails
|
|
6
|
+
def self.build_upstream_url(params)
|
|
7
|
+
host = (params[:host].nil? || params[:host].empty?) ? "localhost" : params[:host]
|
|
8
|
+
port = (params[:port].nil? || params[:port].to_s.empty?) ? "5432" : params[:port].to_s
|
|
9
|
+
|
|
10
|
+
if host.start_with?("/")
|
|
11
|
+
raise ArgumentError, "Gold Lapel cannot proxy Unix socket connections (host: #{host})"
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
userinfo = nil
|
|
15
|
+
if params[:user] && !params[:user].empty?
|
|
16
|
+
userinfo = URI.encode_uri_component(params[:user])
|
|
17
|
+
if params[:password] && !params[:password].empty?
|
|
18
|
+
userinfo += ":#{URI.encode_uri_component(params[:password])}"
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
dbname = params[:dbname] ? URI.encode_uri_component(params[:dbname]) : ""
|
|
23
|
+
|
|
24
|
+
authority = userinfo ? "#{userinfo}@#{host}:#{port}" : "#{host}:#{port}"
|
|
25
|
+
"postgresql://#{authority}/#{dbname}"
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
module PostgreSQLExtension
|
|
29
|
+
private
|
|
30
|
+
|
|
31
|
+
def connect
|
|
32
|
+
unless @goldlapel_started
|
|
33
|
+
gl_config = @config.is_a?(Hash) ? @config[:goldlapel] || {} : {}
|
|
34
|
+
port = gl_config[:port]
|
|
35
|
+
config = gl_config[:config]
|
|
36
|
+
extra_args = gl_config[:extra_args] || []
|
|
37
|
+
|
|
38
|
+
upstream = GoldLapel::Rails.build_upstream_url(@connection_parameters)
|
|
39
|
+
GoldLapel.start(upstream, config: config, port: port, extra_args: extra_args)
|
|
40
|
+
|
|
41
|
+
proxy_port = port || GoldLapel::DEFAULT_PORT
|
|
42
|
+
@connection_parameters[:host] = "127.0.0.1"
|
|
43
|
+
@connection_parameters[:port] = proxy_port
|
|
44
|
+
@goldlapel_started = true
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
super
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
class Railtie < ::Rails::Railtie
|
|
52
|
+
initializer "goldlapel.configure" do
|
|
53
|
+
ActiveSupport.on_load(:active_record) do
|
|
54
|
+
require "active_record/connection_adapters/postgresql_adapter"
|
|
55
|
+
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.prepend(
|
|
56
|
+
GoldLapel::Rails::PostgreSQLExtension
|
|
57
|
+
)
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: goldlapel-rails
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1.pre.rc1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Stephen Gibson
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2026-03-15 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: goldlapel
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '0'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ">="
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '0'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: activerecord
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ">="
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '7.0'
|
|
34
|
+
type: :runtime
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ">="
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '7.0'
|
|
41
|
+
description: Auto-patches ActiveRecord's PostgreSQL adapter to route queries through
|
|
42
|
+
the Gold Lapel proxy. Zero config — just add the gem.
|
|
43
|
+
email:
|
|
44
|
+
executables: []
|
|
45
|
+
extensions: []
|
|
46
|
+
extra_rdoc_files: []
|
|
47
|
+
files:
|
|
48
|
+
- README.md
|
|
49
|
+
- lib/goldlapel/rails.rb
|
|
50
|
+
homepage: https://goldlapel.com
|
|
51
|
+
licenses:
|
|
52
|
+
- Proprietary
|
|
53
|
+
metadata:
|
|
54
|
+
homepage_uri: https://goldlapel.com
|
|
55
|
+
source_code_uri: https://github.com/goldlapel/goldlapel-rails
|
|
56
|
+
post_install_message:
|
|
57
|
+
rdoc_options: []
|
|
58
|
+
require_paths:
|
|
59
|
+
- lib
|
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
61
|
+
requirements:
|
|
62
|
+
- - ">="
|
|
63
|
+
- !ruby/object:Gem::Version
|
|
64
|
+
version: 3.2.0
|
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
66
|
+
requirements:
|
|
67
|
+
- - ">="
|
|
68
|
+
- !ruby/object:Gem::Version
|
|
69
|
+
version: '0'
|
|
70
|
+
requirements: []
|
|
71
|
+
rubygems_version: 3.5.22
|
|
72
|
+
signing_key:
|
|
73
|
+
specification_version: 4
|
|
74
|
+
summary: Gold Lapel integration for Rails
|
|
75
|
+
test_files: []
|