cmd/postgresql-upgrade-database: fix brew not being found

This commit is contained in:
Bo Anderson 2023-07-03 02:52:12 +01:00
parent f40b0f9f6e
commit fa0ccdb3ba
No known key found for this signature in database
GPG Key ID: 3DB94E204E137D65

View File

@ -52,7 +52,7 @@ module Homebrew
old_bin ||= begin old_bin ||= begin
Formula[old_pg_name] Formula[old_pg_name]
ohai "brew install #{old_pg_name}" ohai "brew install #{old_pg_name}"
system "brew", "install", old_pg_name system HOMEBREW_BREW_FILE, "install", old_pg_name
Pathname.glob(old_pg_glob).first Pathname.glob(old_pg_glob).first
rescue FormulaUnavailableError rescue FormulaUnavailableError
nil nil
@ -69,11 +69,11 @@ module Homebrew
# Following instructions from: # Following instructions from:
# https://www.postgresql.org/docs/10/static/pgupgrade.html # https://www.postgresql.org/docs/10/static/pgupgrade.html
ohai "Upgrading #{name} data from #{pg_version_data} to #{pg_version_installed}..." ohai "Upgrading #{name} data from #{pg_version_data} to #{pg_version_installed}..."
services_json_output = Utils.popen_read("brew", "services", "info", "--all", "--json") services_json_output = Utils.popen_read(HOMEBREW_BREW_FILE, "services", "info", "--all", "--json")
services_json = JSON.parse(services_json_output) services_json = JSON.parse(services_json_output)
loaded_service_names = services_json.select { |sj| sj[:loaded] }.map { |sj| sj[:name] } loaded_service_names = services_json.select { |sj| sj[:loaded] }.map { |sj| sj[:name] }
if loaded_service_names.include?(name) if loaded_service_names.include?(name)
system "brew", "services", "stop", name system HOMEBREW_BREW_FILE, "services", "stop", name
service_stopped = true service_stopped = true
elsif quiet_system "#{bin}/pg_ctl", "-D", datadir, "status" elsif quiet_system "#{bin}/pg_ctl", "-D", datadir, "status"
system "#{bin}/pg_ctl", "-D", datadir, "stop" system "#{bin}/pg_ctl", "-D", datadir, "stop"
@ -81,7 +81,7 @@ module Homebrew
end end
# Shut down old server if it is up via brew services # Shut down old server if it is up via brew services
system "brew", "services", "stop", old_pg_name if loaded_service_names.include?(old_pg_name) system HOMEBREW_BREW_FILE, "services", "stop", old_pg_name if loaded_service_names.include?(old_pg_name)
# get 'lc_collate' from old DB" # get 'lc_collate' from old DB"
unless quiet_system "#{old_bin}/pg_ctl", "-w", "-D", datadir, "status" unless quiet_system "#{old_bin}/pg_ctl", "-w", "-D", datadir, "status"
@ -143,7 +143,7 @@ module Homebrew
if server_stopped if server_stopped
safe_system "#{bin}/pg_ctl", "-D", datadir, "start" safe_system "#{bin}/pg_ctl", "-D", datadir, "start"
elsif service_stopped elsif service_stopped
safe_system "brew", "services", "start", name safe_system HOMEBREW_BREW_FILE, "services", "start", name
end end
else else
onoe "Upgrading #{name} data from #{pg_version_data} to #{pg_version_installed} failed!" onoe "Upgrading #{name} data from #{pg_version_data} to #{pg_version_installed} failed!"
@ -158,7 +158,7 @@ module Homebrew
if server_stopped if server_stopped
system "#{bin}/pg_ctl", "-D", datadir, "start" system "#{bin}/pg_ctl", "-D", datadir, "start"
elsif service_stopped elsif service_stopped
system "brew", "services", "start", name system HOMEBREW_BREW_FILE, "services", "start", name
end end
end end
end end