Port Homebrew::Cmd::PostgresqlUpgradeDatabase

This commit is contained in:
Douglas Eichelberger 2024-04-01 09:48:23 -07:00
parent c1b1c11a8c
commit 31aa89aa7c
2 changed files with 157 additions and 151 deletions

View File

@ -1,15 +1,13 @@
# typed: true
# typed: strict
# frozen_string_literal: true
require "cli/parser"
require "abstract_command"
require "formula"
module Homebrew
module_function
sig { returns(CLI::Parser) }
def postgresql_upgrade_database_args
Homebrew::CLI::Parser.new do
module Cmd
class PostgresqlUpgradeDatabase < AbstractCommand
cmd_args do
description <<~EOS
Upgrades the database for the `postgresql` formula.
EOS
@ -18,12 +16,9 @@ module Homebrew
hide_from_man_page!
end
end
sig { void }
def postgresql_upgrade_database
postgresql_upgrade_database_args.parse
sig { override.void }
def run
odisabled "brew postgresql_upgrade_database",
"using new, versioned e.g. `var/postgres@14` datadir and `pg_upgrade`"
@ -105,7 +100,8 @@ module Homebrew
]
locale_settings.each do |setting|
sql = "SELECT setting FROM pg_settings WHERE name LIKE '#{setting}';"
value = Utils.popen_read("#{old_bin}/psql", "postgres", "-qtAX", "-U", ENV.fetch("USER"), "-c", sql).strip
value = Utils.popen_read("#{old_bin}/psql", "postgres", "-qtAX", "-U", ENV.fetch("USER"), "-c",
sql).strip
next if value.empty?
@ -168,4 +164,6 @@ module Homebrew
end
end
end
end
end
end

View File

@ -0,0 +1,8 @@
# frozen_string_literal: true
require "cmd/postgresql-upgrade-database"
require "cmd/shared_examples/args_parse"
RSpec.describe Homebrew::Cmd::PostgresqlUpgradeDatabase do
it_behaves_like "parseable arguments"
end