Module: PostgresHelper
- Defined in:
- lib/postgres_helper.rb
Class Method Summary collapse
- .available? ⇒ Boolean
- .psql_command ⇒ Object
-
.reset_cache! ⇒ Object
Reset cached command detection (for tests).
- .using_docker? ⇒ Boolean
- .validate_env_vars! ⇒ Object
Class Method Details
.available? ⇒ Boolean
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/postgres_helper.rb', line 9 def available? return false if psql_command.nil? # If using Docker, check required env vars are present if using_docker? has_required_env_vars? else true end end |
.psql_command ⇒ Object
5 6 7 |
# File 'lib/postgres_helper.rb', line 5 def psql_command @psql_command ||= detect_psql_command end |
.reset_cache! ⇒ Object
Reset cached command detection (for tests)
26 27 28 |
# File 'lib/postgres_helper.rb', line 26 def reset_cache! @psql_command = nil end |
.using_docker? ⇒ Boolean
20 21 22 23 |
# File 'lib/postgres_helper.rb', line 20 def using_docker? cmd = psql_command cmd && cmd.start_with?("docker exec") end |
.validate_env_vars! ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/postgres_helper.rb', line 30 def validate_env_vars! return unless using_docker? required_vars = ["PGUSER", "PGDATABASE"] missing_vars = required_vars.reject { |var| ENV[var] } if missing_vars.any? TestSilencer.abort_unless_testing "Error: PostgreSQL is running in Docker but required environment variables are missing: #{missing_vars.join(", ")}. Please set these variables before running psql commands." end end |