discharger 0.2.21 → 0.2.22
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
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a330978c9c3a143da222b8f82e62d6caa5ce8a7b530ec3f168027abc364176ec
|
|
4
|
+
data.tar.gz: '08ed901337c5dbc19172928703f46d028249e1dc8811db7862eec005518c7020'
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b5f2f78a6c014e9367bb32b7b15a4650905669502374fd4bed92397a3c06e4dcab0df2acce30200f51c31dce032269c1dd2e8895ba815031533af938251bd813
|
|
7
|
+
data.tar.gz: 903aa8c51fca10ee7b86e13c49b69e747967c0315c8c88d8b749ac2f0ac02134a6286303f99dd6a49d6396ad5dfd5474ddc49a29ac603e7bb0b45803e137c419
|
data/CHANGELOG.md
CHANGED
|
@@ -5,10 +5,10 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
|
6
6
|
and this project adheres to [Semantic Versioning](http://semver.org/).
|
|
7
7
|
|
|
8
|
+
## [0.2.22] - 2026-01-07
|
|
9
|
+
|
|
8
10
|
## [0.2.21] - 2025-12-17
|
|
9
11
|
|
|
10
12
|
### Fixed
|
|
11
13
|
|
|
12
14
|
- Corrected mis-matched method names for #database and #redis
|
|
13
|
-
|
|
14
|
-
## [0.2.20] - 2025-12-11
|
data/lib/discharger/railtie.rb
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
module Discharger
|
|
2
2
|
class Railtie < ::Rails::Railtie
|
|
3
|
+
# Prepend bin/pg-tools to PATH so Docker-aware pg_dump/psql wrappers are used
|
|
4
|
+
# This runs before any rake tasks execute, ensuring Rails uses the wrappers
|
|
5
|
+
initializer "discharger.pg_tools_path", before: :load_config_initializers do
|
|
6
|
+
pg_tools_path = Rails.root.join("bin", "pg-tools").to_s
|
|
7
|
+
if File.directory?(pg_tools_path) && !ENV["PATH"].to_s.include?(pg_tools_path)
|
|
8
|
+
ENV["PATH"] = "#{pg_tools_path}:#{ENV["PATH"]}"
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
3
12
|
config.after_initialize do |app|
|
|
4
13
|
if Rails.env.development? && Discharger.slack_token.nil?
|
|
5
14
|
warn "Your application Discharger.slack_token must be set."
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "base_command"
|
|
4
|
+
|
|
5
|
+
module Discharger
|
|
6
|
+
module SetupRunner
|
|
7
|
+
module Commands
|
|
8
|
+
class PgToolsCommand < BaseCommand
|
|
9
|
+
TOOLS = %w[pg_dump psql].freeze
|
|
10
|
+
|
|
11
|
+
def description
|
|
12
|
+
"Setting up PostgreSQL tools wrappers"
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def can_execute?
|
|
16
|
+
config.respond_to?(:db_config) && config.db_config&.name.present?
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def execute
|
|
20
|
+
create_pg_tools_directory
|
|
21
|
+
TOOLS.each { |tool| create_wrapper(tool) }
|
|
22
|
+
create_envrc_if_needed
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
private
|
|
26
|
+
|
|
27
|
+
def container_name
|
|
28
|
+
config.db_config.name
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def create_pg_tools_directory
|
|
32
|
+
FileUtils.mkdir_p(File.join(app_root, "bin", "pg-tools"))
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def create_wrapper(tool)
|
|
36
|
+
wrapper_path = File.join(app_root, "bin", "pg-tools", tool)
|
|
37
|
+
File.write(wrapper_path, wrapper_content(tool))
|
|
38
|
+
FileUtils.chmod(0o755, wrapper_path)
|
|
39
|
+
log "Created bin/pg-tools/#{tool}"
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def wrapper_content(tool)
|
|
43
|
+
if tool == "pg_dump"
|
|
44
|
+
pg_dump_wrapper_content
|
|
45
|
+
else
|
|
46
|
+
generic_wrapper_content(tool)
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def pg_dump_wrapper_content
|
|
51
|
+
<<~BASH
|
|
52
|
+
#!/usr/bin/env bash
|
|
53
|
+
set -e
|
|
54
|
+
|
|
55
|
+
CONTAINER="#{container_name}"
|
|
56
|
+
|
|
57
|
+
# Docker first: use container's pg_dump if running
|
|
58
|
+
if docker ps --format '{{.Names}}' 2>/dev/null | grep -q "^${CONTAINER}$"; then
|
|
59
|
+
echo "Using pg_dump from Docker container: $CONTAINER" >&2
|
|
60
|
+
|
|
61
|
+
# Parse arguments to handle --file option specially
|
|
62
|
+
# When running in Docker, we need to output to stdout and redirect locally
|
|
63
|
+
OUTPUT_FILE=""
|
|
64
|
+
HAS_USER=""
|
|
65
|
+
ARGS=()
|
|
66
|
+
while [[ $# -gt 0 ]]; do
|
|
67
|
+
case $1 in
|
|
68
|
+
--file)
|
|
69
|
+
OUTPUT_FILE="$2"
|
|
70
|
+
shift 2
|
|
71
|
+
;;
|
|
72
|
+
--file=*)
|
|
73
|
+
OUTPUT_FILE="${1#*=}"
|
|
74
|
+
shift
|
|
75
|
+
;;
|
|
76
|
+
-f)
|
|
77
|
+
OUTPUT_FILE="$2"
|
|
78
|
+
shift 2
|
|
79
|
+
;;
|
|
80
|
+
-U|--username|--username=*)
|
|
81
|
+
HAS_USER="1"
|
|
82
|
+
ARGS+=("$1")
|
|
83
|
+
shift
|
|
84
|
+
;;
|
|
85
|
+
*)
|
|
86
|
+
ARGS+=("$1")
|
|
87
|
+
shift
|
|
88
|
+
;;
|
|
89
|
+
esac
|
|
90
|
+
done
|
|
91
|
+
|
|
92
|
+
# Default to postgres user if not specified (container runs as root)
|
|
93
|
+
if [[ -z "$HAS_USER" ]]; then
|
|
94
|
+
ARGS=("-U" "postgres" "${ARGS[@]}")
|
|
95
|
+
fi
|
|
96
|
+
|
|
97
|
+
if [[ -n "$OUTPUT_FILE" ]]; then
|
|
98
|
+
# Run pg_dump in container, output to stdout, redirect to local file
|
|
99
|
+
docker exec -i "$CONTAINER" pg_dump "${ARGS[@]}" > "$OUTPUT_FILE"
|
|
100
|
+
else
|
|
101
|
+
# No file output, just exec normally
|
|
102
|
+
exec docker exec -i "$CONTAINER" pg_dump "${ARGS[@]}"
|
|
103
|
+
fi
|
|
104
|
+
exit 0
|
|
105
|
+
fi
|
|
106
|
+
|
|
107
|
+
# Fallback to system pg_dump
|
|
108
|
+
exec pg_dump "$@"
|
|
109
|
+
BASH
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def generic_wrapper_content(tool)
|
|
113
|
+
<<~BASH
|
|
114
|
+
#!/usr/bin/env bash
|
|
115
|
+
set -e
|
|
116
|
+
|
|
117
|
+
CONTAINER="#{container_name}"
|
|
118
|
+
|
|
119
|
+
# Docker first: use container's #{tool} if running
|
|
120
|
+
if docker ps --format '{{.Names}}' 2>/dev/null | grep -q "^${CONTAINER}$"; then
|
|
121
|
+
echo "Using #{tool} from Docker container: $CONTAINER" >&2
|
|
122
|
+
exec docker exec -i "$CONTAINER" #{tool} "$@"
|
|
123
|
+
fi
|
|
124
|
+
|
|
125
|
+
# Fallback to system #{tool}
|
|
126
|
+
exec #{tool} "$@"
|
|
127
|
+
BASH
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def create_envrc_if_needed
|
|
131
|
+
envrc_path = File.join(app_root, ".envrc")
|
|
132
|
+
if File.exist?(envrc_path)
|
|
133
|
+
# Don't overwrite existing .envrc, but suggest adding PATH if not present
|
|
134
|
+
unless File.read(envrc_path).include?("bin/pg-tools")
|
|
135
|
+
log "Note: Add 'PATH_add bin/pg-tools' to existing .envrc for shell access"
|
|
136
|
+
end
|
|
137
|
+
else
|
|
138
|
+
File.write(envrc_path, "PATH_add bin/pg-tools\n")
|
|
139
|
+
log "Created .envrc (run 'direnv allow' to enable for shell access)"
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
end
|
data/lib/discharger/version.rb
CHANGED
|
@@ -19,7 +19,7 @@ redis:
|
|
|
19
19
|
version: "latest"
|
|
20
20
|
|
|
21
21
|
# Built-in commands to run (empty array runs all available commands)
|
|
22
|
-
# Available commands: brew, asdf, git, bundler, yarn, config, docker, env, database
|
|
22
|
+
# Available commands: brew, asdf, git, bundler, yarn, config, docker, pg_tools, env, database
|
|
23
23
|
steps:
|
|
24
24
|
- brew
|
|
25
25
|
- asdf
|
|
@@ -28,6 +28,7 @@ steps:
|
|
|
28
28
|
- yarn
|
|
29
29
|
- config
|
|
30
30
|
- docker
|
|
31
|
+
- pg_tools
|
|
31
32
|
- env
|
|
32
33
|
- database
|
|
33
34
|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: discharger
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.22
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jim Gay
|
|
@@ -120,6 +120,7 @@ files:
|
|
|
120
120
|
- lib/discharger/setup_runner/commands/docker_command.rb
|
|
121
121
|
- lib/discharger/setup_runner/commands/env_command.rb
|
|
122
122
|
- lib/discharger/setup_runner/commands/git_command.rb
|
|
123
|
+
- lib/discharger/setup_runner/commands/pg_tools_command.rb
|
|
123
124
|
- lib/discharger/setup_runner/commands/yarn_command.rb
|
|
124
125
|
- lib/discharger/setup_runner/condition_evaluator.rb
|
|
125
126
|
- lib/discharger/setup_runner/configuration.rb
|